Giter VIP home page Giter VIP logo

kvserver's Introduction

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

kvserver's People

Contributors

proway2 avatar

Stargazers

 avatar

Watchers

 avatar

kvserver's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.