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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build&Test Go Report Card

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:

$ 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://<host>:<port>/key/<key_name>, where <key_name> - 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

About

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.

License:GNU General Public License v3.0


Languages

Language:Go 100.0%