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).
- 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.
Clone and run go install
in project folder.
Command line arguments:
$ 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)
Base URL http://<host>:<port>/key/<key_name>
, where <key_name>
- is the name of the key to be stored. Key and its value are always string.
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.
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.
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.
Run go test -v -cover -count=1 ./...
.
GPL v3