A key-value db api with multiple storage engines and key generation

Jet is a deadly-simple key-value api. The main goals of this project are :

  • Making a simple KV tool for our other projects.
  • Learn tests writing and github actions.

Getting started

In order to use the project, the most simple way is to use the already built image.

Just run the following command to get started:

docker run -p 8000:8000 gogems/jet

It will start and expose the jet api on your port 8000.

A more complete example :

docker run -p 8080:8080 -v /var/logs:/storage gogems/jet \
  -port 8080 \
  -storage.dir /storage \
  -generator.short 5

Will expose port 8080, and use /storage from the container as storage directory which will be mapped to /var/jet-storage folder. It will also use the short generator.

Api

The api exposes the following routes:

GET /

Returns an array of available keys, json format.

GET /{key}

Return the content stored for {key}.

POST /

Accept any content-type, and store it to a generated key. Returns the key.

PUT /{key}

Create or override the value for {key}. Returns the key.

DELETE /{key}

Deletes the value for {key}.

Storage

There are currently 2 types of storage engine, but feel free to add yours.

In Memory Storage (default)

By default, it will use the not persistent storage inMemory.

File Storage

You can use file storage which will basically store the file named like the key you have specified.

To use it, just specify on start the flag :

-storage.dir path/to/store

For docker for example with shared volume :

docker run -p 8000:8000 -v $PWD/storage:/storage gogems/jet -storage.dir /storage

Your Storage

If you want to add a storage, feel free to contribute. Just implement the Storage interface

type Storage interface {
Store(id string, content []byte) error
FetchOne(id string) ([]byte, error)
FetchAll() (map[string][]byte, error)
Delete(id string) error
KeyExists(id string) (bool, error)
}

Key Generation

There are currently 3 types of automated Key generations.

UuidGenerator (default)

By default, the key will be a UUID based on RFC 4122.

incrementalGenerator

The next integer available key starting at 1.

On start, it will begin at 1 and when a cell is available it will fill it. It won't start again unless you restart the program. This may lead to unexpected side effects for your and you should never rely on the id to get the size of the collection.

example of side effects : 

let's say you have the following used keys : 
-> 1,2,3,5,6

On startup it will check until 4, and add something on 4.
-> 1,2,3,4,5,6

Then you delete 2.
-> 1,3,4,5,6

On next value adding, it will start from 5 and add it to 7.
-> 1,3,4,5,6,7

If you restart it, assuming you have persistent storage, on next storage, it will be on 2.
-> 1,2,3,4,5,6,7

To use it, just specify on start the flag :

-generator.inc

For docker for example with shared volume :

docker run -p 8000:8000 gogems/jet -generator.inc

So please, be careful about using this generator on production

ShortGenerator

The short generator is a 63 characters (a-z, A-Z, 0-9 and -) based string clever generator which aims to generates shortest keys. The generator expects a "minimum character number" and will generate a string. If it collides, it will increase the current generation by one until it doesn't collides.

For example, let's start at 3 size char.

It will generate, "AxF"
If it collides on second time, it will generate "0HTe"
On third time, if it doesn't collides, it will generate "RRu"
On fourth time, if it collides at 3 chars, it will check at 4, and if it collides it will generate a 5 char id
And back to 3.

It's not a conventional way to generate keys, but I like the naive approach.

To use it, just specify on start the flag :

-generator.short MINIMUM_NUMBER

where MINIMUM_NUMBER is the starting number of characters in generation trial.

For docker for example with shared volume :

docker run -p 8000:8000 gogems/jet -generator.short 17

Your generator

Feel free to contribute by adding your generator. You just need to implement the KeyGeneratorInterface

type KeyGenerator interface {
GetRandomKey(storage StorageEngines.Storage) string
}

Configuration

If you want to change the Host or Port you can use the respective -host and -port. default to 127.0.0.1 and 8000.

Credits

Photo by Nick Nice on Unsplash

Similar Resources

PrimeKV is a Secure, REST API driven Key/Value store.

PrimeKV PrimeKV is a Secure, REST API driven Key/Value store. Features 100% In-memory. Encrypted by default, All stored values are bi-directionally en

Jan 10, 2022

Distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.

Olric Distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service. With

Jan 4, 2023

CrankDB is an ultra fast and very lightweight Key Value based Document Store.

CrankDB is a ultra fast, extreme lightweight Key Value based Document Store.

Apr 12, 2022

NutsDB a simple, fast, embeddable and persistent key/value store written in pure Go.

NutsDB a simple, fast, embeddable and persistent key/value store written in pure Go.

A simple, fast, embeddable, persistent key/value store written in pure Go. It supports fully serializable transactions and many data structures such as list, set, sorted set.

Jan 9, 2023

KV - a toy in-memory key value store built primarily in an effort to write more go and check out grpc

KV KV is a toy in-memory key value store built primarily in an effort to write more go and check out grpc. This is still a work in progress. // downlo

Dec 30, 2021

An embedded key/value database for Go.

Bolt Bolt is a pure Go key/value store inspired by Howard Chu's LMDB project. The goal of the project is to provide a simple, fast, and reliable datab

Dec 30, 2022

A disk-backed key-value store.

What is diskv? Diskv (disk-vee) is a simple, persistent key-value store written in the Go language. It starts with an incredibly simple API for storin

Jan 1, 2023

Distributed reliable key-value store for the most critical data of a distributed system

etcd Note: The master branch may be in an unstable or even broken state during development. Please use releases instead of the master branch in order

Dec 28, 2022

Simple, ordered, key-value persistence library for the Go Language

gkvlite gkvlite is a simple, ordered, ACID, key-value persistence library for Go. Overview gkvlite is a library that provides a simple key-value persi

Dec 21, 2022
Related tags
rosedb is a fast, stable and embedded key-value (k-v) storage engine based on bitcask.
rosedb is a fast, stable and embedded key-value (k-v) storage engine based on bitcask.

rosedb is a fast, stable and embedded key-value (k-v) storage engine based on bitcask. Its on-disk files are organized as WAL(Write Ahead Log) in LSM trees, optimizing for write throughput.

Dec 28, 2022
Distributed, fault-tolerant key-value storage written in go.
Distributed, fault-tolerant key-value storage written in go.

A simple, distributed, fault-tolerant key-value storage inspired by Redis. It uses Raft protocotol as consensus algorithm. It supports the following data structures: String, Bitmap, Map, List.

Jan 3, 2023
Fault tolerant, sharded key value storage written in GoLang
Fault tolerant, sharded key value storage written in GoLang

Ravel is a sharded, fault-tolerant key-value store built using BadgerDB and hashicorp/raft. You can shard your data across multiple clusters with mult

Nov 1, 2022
The TinyKV course builds a key-value storage system with the Raft consensus algorithm.
The TinyKV course builds a key-value storage system with the Raft consensus algorithm.

The TinyKV Course The TinyKV course builds a key-value storage system with the Raft consensus algorithm. It is inspired by MIT 6.824 and TiKV Project.

Jan 4, 2022
A key-value storage transaction interpretator.

kv-txn-interpreter A key-value storage transaction interpreter, which provides an etcd-like transaction interface to help you build a transaction over

Feb 22, 2022
The TinyKV course builds a key-value storage system with the Raft consensus algorithm
The TinyKV course builds a key-value storage system with the Raft consensus algorithm

The TinyKV Course The TinyKV course builds a key-value storage system with the Raft consensus algorithm. It is inspired by MIT 6.824 and TiKV Project.

Jul 26, 2022
Keyval - A simple key-value storage library written in Go

keyval keyval is a simple key-value storage library written in Go and its back c

Sep 16, 2022
Tinykv - The TinyKV course builds a key-value storage system with the Raft consensus algorithm
Tinykv - The TinyKV course builds a key-value storage system with the Raft consensus algorithm

The TinyKV Course The TinyKV course builds a key-value storage system with the R

Dec 7, 2022
ShockV is a simple key-value store with RESTful API
ShockV is a simple key-value store with RESTful API

ShockV is a simple key-value store based on badgerDB with RESTful API. It's best suited for experimental project which you need a lightweight data store.

Sep 26, 2021
A rest-api that works with golang as an in-memory key value store

In Store A rest-api that works with golang as an in-memory key value store Usage Fist of all, clone the repo with the command below. You must have gol

Oct 24, 2021