Giter VIP home page Giter VIP logo

go-kv-store's Introduction

About this project

This is a simple implementation of key-value store in Go. It serves as simple caching server that can store data for specified duration with sub 1ms read and write speed.

Detailed description of the code and design decisions I took when writing it is in this Medium article.

Installation

Clone the repository and run:

go run .

Build

You can create optimized build by running:

go build .

How to use

After building and running the application, the API will be exposed on port 3000, the storage has 3 methods, PUT, GET, DELETE

  • PUT - creates new write, accepts json with key-value pairs, value can be any data compatible with json:
PUT http://127.0.0.1:3000/

{
  "foo": "bar",
  "complexVal": {"foo": 0, "bar": 3.14}
}
  • GET - reads data from storage by key
GET http://127.0.0.1:3000/

{
  "key": "complexVal"
}

returns:

{
  "complexVal": {
    "bar": 3.14,
    "foo": 0
  }
}
  • DELETE - deletes write:
DELETE http://127.0.0.1:3000/

{
  "key": "complexVal"
}

Expiration

Main usage of the store is intended to be caching, therefore the data will expire after specified time (default 3min).

Logs

During operation the app can write logs into a .txt file which then can be read to reconstruct the database if it were to go offline.

Environmental variables

The applications includes number of variables that can be set by the user. The variables are:

  • use_logs - boolean - ff true, logs will be written to logs_filename
  • reconstruct_from_logs - boolean - reconstruct database from existing log file
  • logs_filename - string - name of the log file, has to be .txt
  • expiration - time.Duration - how long to store key-value pairs for
  • port - int - port at which to run the server

Example run:

go run . --use_logs=false --reconstruct_from_logs=false --logs_filename=logs.txt --expiration=1m30s --port=3000

go-kv-store's People

Contributors

martinkratochvilprogramy avatar

Watchers

 avatar

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.