This project is a memory database implementation in C++ as a personal side project to get back to the language after a long time being a PHP developer.
The idea initially popped up to my mind while reading the book Designing Data Intensive Applications as Database implementations look pretty interesting problems to get into and solve. However, it was when my team had to implement a Circuit breaker using Redis that I started to wonder how a Rater data type could implement in Redis that could fit the circuit breaker use case.
And here it is, Sider.
To follow the development, you can check the project page or the issues.
So far, there is only a PHP client implemented.
It is still not published in packagist. For now, you can take a look in the >
clients/php
directory. Let's see when I will finally publish it :)
Sider is a basic memory database that uses a key-value store to store different
kind of data idenfied by a pair scope
and key
. It utilises C++
unordered_map
to store different types of data type.
Sider listens to the port 7963
and assumes it is running on a safe network as
it does not provide any authentication layer.
For running the project on local, you need to have Docker >= 2.32 installed.
-
To start the server, run the following commands in one terminal:
$ make build dev/up
-
To run the tests, run the following commands in another terminal:
$ make server/tests clients/php/tests
-
GET scope key [partition]
Return value stored in the entry identified by
key
inside of thescope
. Depending on the entry's data type associated with the entry, apartition
may be required in order to retrieve the value. -
CLEAR scope [key]
Remove entry identified by
key
inside of thescope
. If onlyscope
is provided, removes all entries inside of the scope. -
KEEP scope key value [ttl]
Keep the
value
stored associated with the providedscope:key
. Ifttl
is provided, the entry will be cleared after its expiration. -
COUNT scope key step [ttl]
Increment by
step
the counter identified bykey
inside of thescope
. Ifttl
is provided, thestep
is decremented after its expiration and the entry is removed in case the counter comes back to 0. -
RATE scope key step partition [ttl]
Increment by
step
the raterpartition
identified bykey
inside of thescope
. Ifttl
is provided, thestep
is decremented after its expiration and the entry is removed in case the rater comes back to 0. -
QUEUE scope key value
Add
value
to the queue identified bykey
inside of thescope
. -
DEQUEUE scope key
Remove oldest value from the queue identified by
key
inside of thescope
.
Currently, a custom protocol is implemented for the communication between server and clients and it is as follows:
Checksum | Version | Content Type | Content Length | Arguments |
---|---|---|---|---|
4 bytes | 2 bytes | 2 bytes | 4 bytes | X bytes |
Where the arguments part and its format depends on the content type provided which determines the command to be executed:
Command | Value in Decimal : Hex |
---|---|
CLEAR |
20 : 00 14 |
GET |
21 : 00 15 |
KEEP |
22 : 00 16 |
COUNT |
23 : 00 17 |
RATE |
24 : 00 18 |
QUEUE |
30 : 00 1e |
DEQUEUE |
31 : 00 1f |