NimbusDB is a key value store. The aim of this project is to understand the core behaviour of Redis and its design. It provides various set of commands similar to Redis along with various data structures and more.
- Key-Value Store Supports commands like
SET
,GET
,DEL
,INCR
,INCRBY
etc. - Data type support String, Numbers, Set, List.
- Pub/Sub support For Publishers and Subscribers channels.
- Disk Persistence Supports Append Only Logs (AOF) for data recovery mechanism.
- Fork the repo and clone it.
- Open 2 terminals.
- Run command
go run main.go
in one terminal and Run commandtelnet localhost 6379
in other one. - Important Note: NimbusDB runs on port 6379.
Set the key in the store.
Syntax: SET key value
nimbusdb > SET name john
OK
Get the key from the store.
Syntax: GET key
nimbusdb > SET name john
OK
nimbusdb > GET name
john
Delete key from the store.
Syntax: DEL key
nimbusdb > SET name john
OK
nimbusdb > GET name
john
nimbusdb > DEL name
john Deleted
Note
It works with smallcase set
, get
, del
commands also.
NimbusDB support few important datatypes.
Nimbus supports the string data type, and you can use the SET
and GET
commands mentioned above to work with strings.
Nimbus supports the number data type and also offers a separate set of commands designed to work with it. Below is a detailed explanation of these commands.
Increase the value by 1.
Syntax: INCR key
nimbusdb > SET count 1
OK
nimbusdb > INCR count
2
Increase the value by some x
value.
Syntax: INCRBY key x
nimbusdb > SET count 1
OK
nimbusdb > INCR count
2
nimbusdb > INCRBY count 5
7
Decrease the value by 1.
Syntax: DECR key
nimbusdb > GET count
7
nimbusdb > DECR count
6
Decrease the value by some x
value.
Syntax: DECRBY key value
nimbusdb > GET count
7
nimbusdb > DECRBY count 4
3
List also offers it separate set of commands designed to work with it. Below are the detaled explanation of commands.
Push the element to the left side of the list.
Syntax: LPUSH key value
nimbusdb > LPUSH cities delhi
1
nimbusdb > LPUSH cities jaipur
2
Push the element to the right side of the list.
Syntax: RPUSH key value
nimbusdb > RPUSH cities lucknow
3
nimbusdb > RPUSH cities bhopal
4
Returns the length of the list.
Syntax: LLEN key
nimbusdb > LLEN cities
4
Removes the leftmost element from the list.
Syntax: LPOP key
nimbusdb > LPOP cities
jaipur
Removes the rightmost element from the list.
Syntax: RPOP key
nimbusdb > RPOP cities
bhopal
Returns the element from the list at that index.
Syntax: LINDEX key value
nimbusdb > LINDEX cities 0
delhi
nimbusdb > LINDEX cities 1
lucknow
Set also offers it separate set of commands designed to work with it. Below are the detailed explanation of commands.
Returns the 1 when insert successfull else 0.
Syntax: SADD key value
nimbusdb > SADD cities lucknow
1
nimbusdb > SADD cities jaipur
1
nimbusdb > SADD cities lucknow
0
Returns the list of all elements present in the set.
Synatx: SMEMBERS key
nimbusdb > SMEMBERS cities
[lucknow jaipur]
Returns 1 if the element exists in the set else 0.
Syntax: SISMEMBER key value
nimbusdb > SADD cities delhi
1
nimbusdb > SMEMBERS cities
[lucknow jaipur delhi]
nimbusdb > SISMEMBER cities delhi
1
Returns 1 if the element removed successfully else 0 if the element doesn't exists
Syntax: SREM key value
nimbusdb > SREM cities jaipur
1
nimbusdb > SMEMBERS cities
[lucknow delhi]
nimbusdb > SISMEMBER cities jaipur
0
nimbusdb > SREM cities jaipur
0
NimbubsDB also supports dealing with channels. It provides SUBSCRIBE
and PUBLISH
command to handle them.
Subscribes to the channel.
Syntax: SUBSCRIBE channel_name
Publishes to the channel.
Syntax: PUBLISH channel_name message
Below example is the simulation of SUBSCRIBE
AND PUBLISH
command.
nimbusdb > SUBSCRIBE chat-1
SUBSCRIBED
nimbusdb > PUBLISH chat-1 hello
+hello
nimbusdb > PUBLISHED
nimbusdb > +hey, how are you
nimbusdb > SUBSCRIBE chat-1
SUBSCRIBED
nimbusdb > +hello
nimbusdb > PUBLISH chat-1 hey, how are you
+hey, how are you
nimbusdb > PUBLISHED
NimbusDB provides Pub/Sub support to deal with channels. For more info, checkout the command section here.
NimbusDB uses Append-Only Logs for disk persistence and data recovery. Each time a command is executed, NimbusDB records it in a file to ensure data is saved. When the database restarts, it loads the entire log file at once, allowing it to resume from the point it was last at without any data loss.