Skip to content

ryanreadbooks/LiteKV

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LiteKV

LiteKV is a simple key-value storage implementation.


Build

mkdir build
cd build
cmake ..
make

Supported data types

  • integer
  • string
  • list
  • hash
  • set

Supported modes

  • Pub/Sub

Supported persistence

  • AOF
  • LiteKV Binary Format

Supported Commands

Type Command Usage Description
Generic
ping ping Ping the server
del del key [key...] Remove the specified keys
exists exists key [key...] Return if specified keys exist
type type key  Return data type of specified key
expire expire key seconds Set expiration for key
expireat expireat key unix-timestamp Set key expire in unix-timestamp
ttl ttl key Get the time to live (TTL) in seconds of key
Integer or String
set set key value Set key to store string or integer value
get get key  Get the value of key
Integer
incr incr key Increase int value by 1 on given key
decr decr key Decrease int value by 1 on given key
incrby incrby key value Increase int value by n on given key
decrby decry key value Decrease int value by n on given key
String
strlen strlen key Return the length of value at key
append append key value  Append value to existing value at key
List
llen llen key  Return the size of list at key
lpop lpop key  Remove and return the first item of list at key
lpush lpush key value [value...]  Insert all values at the head of list at key
rpop rpop key Remove and return the last item of list at key
rpush rpush key value [value...]  Insert all values at the end of list at key
lrange lrange key begin end Return all items in specified range of list at key
lsetindex lsetindex key index value  Set the item to value at index.
lindex lindex key index  Return the item at index
Hash
hset hset key field value [field value...] Set field-value pair in hash at key
hget hget key field [field...] Get values of fields in hash at key
hdel hdel key field [field...]  Remove fields in hash at key
hexists hexists key field  Check the existence of field in hash at key
hgetall hgetall key  Return all field-value pairs in hash at key
hkeys hkeys key  Return all fields in hash at key
hvals hvals key  Return all values in hash at key
hlen hlen key  Return the number of pairs in hash at key
Set
sadd sadd key member [member...] Add members into set at key
sismember sismember key member Check a member is inside set at key
smismember smismember key member [member...] Check multiple members are inside set at key
smembers smembers key Return all members inside set at key
srem srem key member [member...] Remove the specified members inside set at key
scard scard key  Return the number of members inside set at key
Pub/Sub
publish publish chan msg Publish a message to specific channel
subscribe subscribe chan1 [chan2...] Subscribe to specific channels
unsubscribe unsubscribe chan1 [chan2...] Unsubscribe from specific channels

Benchmark Results

Since our communication protocol is based on RESP, the redis-benchmark tool from redis can be used to benchmark this repository.

The following command is used for benchmarking. We make N_CLIENTS and N_THREADS as two variables;

redis-benchmark -h 127.0.0.1 -p 9527 \
	-c $N_CLIENTS \
	-n 100000 \
	-t set,get,incr,lpush,rpush,lpop,rpop,lrange,hset \
	--threads $N_THREADS \
	-r 10000 \
	--csv

Results (server and clients run in the same local machine)

Environments
Server

Machine: 64bit AMD 3600 CPU + 16G RAM

System: Ubuntu 16.04

Compiler: gcc 5.4.0

Client

redis-benchmark version: 7.0.2


Single thread case

response per second in single thread case

average latency in milliseconds in single-thread case

Multiple threads case

requests per second in multiple threads case

average latency in millisecond in multiple threads case

Future Works

  • Performance Optimization
    • string object optimization (COW or SSO)
    • dlist optimization (redesign and reconstruct)
  • Features
    • support more data structure, such as set, sorted sets, etc.
    • transaction
    • make it distributed
    • master-slave mode
    • pub/sub mode
    • sentinel
    • use connection pool

About

A simple key-value storage implemented in C++.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published