https://github.com/proway2/kvserver
Simple yet fully functional in-memory key-value storage server based on HTTP protocol with elements being purged when expired. All operations run in constant time.
https://github.com/proway2/kvserver
database elements-purged expiration golang gplv3 http-protocol in-memory key key-value key-value-database key-value-store server storage-server ttl ttl-cache value
Last synced: 12 days ago
JSON representation
Simple yet fully functional in-memory key-value storage server based on HTTP protocol with elements being purged when expired. All operations run in constant time.
- Host: GitHub
- URL: https://github.com/proway2/kvserver
- Owner: proway2
- License: gpl-3.0
- Created: 2019-02-16T08:08:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-07-13T17:24:34.000Z (7 months ago)
- Last Synced: 2025-07-13T17:42:00.083Z (7 months ago)
- Topics: database, elements-purged, expiration, golang, gplv3, http-protocol, in-memory, key, key-value, key-value-database, key-value-store, server, storage-server, ttl, ttl-cache, value
- Language: Go
- Homepage:
- Size: 87.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://goreportcard.com/report/github.com/proway2/kvserver)
# kvserver
Simple yet fully functional in-memory key-value storage server based on HTTP protocol with elements purged based on TTL. All operations run in constant time.
Operations provided by server:
- storing/updating value by its key
- getting value by its key
- deleting value by its key
- key-value element is cleaned up when expired (works automatically).
# Features
- all operations have time complexity of ```O(1)```, i.e. always run in constant time.
- hits TTL as much accurate as it's possible.
- lower CPU cycles consumption during approximation and idle.
- TTL approximation's divider is always 2, i.e. next check time = current time + (time to the next element to purge)/2.
# Installation
Clone and run ```go install``` in project folder.
# Usage
Command line arguments:
```bash
$ kvserver -h
Usage of kvserver:
-addr string
IP address to bind to (default "127.0.0.1")
-port int
port to listen to (default 8080)
-ttl uint
element's (key-value) lifetime in the storage, secs. (default 60)
```
# API
Base URL ```http://:/key/```, where `````` - is the name of the key to be stored. Key and its value are always string.
## Storing/Updating value by its key
_HTTP method_: ```POST```
_Request's parameter name_: ```value```
_Success code_: ```200```
_Error code_: ```400```, empty key is provided.
_Note_: TTL is reset for any subsequent requests for the same key.
## Getting value by its key
_HTTP method_: ```GET```
_Request's parameter name_: no parameter is needed.
_Success code_: ```200```, response's body contains string value for the key.
_Error code_: ```404```, key is not found in the storage.
## Deleting value by its key
_HTTP method_: ```POST```
_Request's parameter name_: no parameter is needed.
_Success code_: ```200```, value is successfully deleted.
_Error code_: ```404```, key is not found in the storage.
When error is occured code ```400``` is returned by server.
# Tests
Run ```go test -v -cover -count=1 ./...```.
# License
GPL v3