memdb is a simple key-value in-memory database. Just for learning.
- in-memory key-value store
- eviction policies like LFU, LRU
- TTL (per key)
- concurrent
- HTTP/CLI access
Running the command
memdb --port 9300 --eviction-policy LRU
This database will contain some data structures that will store data:
- Strings: single key-value
- Hash: multiple key-value data
- Set: a collection of not repeating values
The path represent the data structure to use, for example: /key, /hash, /set and the HTTP method the action
Creating/Replacing a key
POST /key
STATUS:
201: When new Item
200: When Item already exists
400: bad input data
BODY:
{
"key": "",
"value": ""
}
RESPONSE:
{
"affected_keys": 0,
}
Getting a key
GET /key/{key}
STATUS:
200: success response
204 (no content): item does not exists
RESPONSE (when 200):
{
"value": ""
}
Deleting a key
DELETE /key/{key}
STATUS:
200: success response
RESPONSE:
{
"affected_keys": 0,
}
Creating/Replacing a hash
POST /hash
STATUS:
201: When new Item
200: When Item already exists
400: bad input data
BODY:
{
"key": "",
"value": {
"key1": "",
"key2": ""
}
}
RESPONSE:
{
"affected_keys": 1,
}
Adding/Replacing the hash properties
PUT /hash/{key}
STATUS:
200: Succes response
400: bad input data
404: key not found
BODY:
{
"value": {
"key1": "",
"key2": ""
}
}
RESPONSE:
{
"affected_keys": 1,
}
Getting a hash
GET /hash/{key}
STATUS:
200: success response
204 (no content): item does not exists
RESPONSE (when 200):
{
"value": {
"key1": "",
"key2": ""
}
}
Deleting a hash
DELETE /hash/{key}
STATUS:
200: success response
RESPONSE:
{
"affected_keys": 0,
}
Deleting hash properties (can delete multiple keys separated by spaces)
DELETE /hash/{key}?keys={key, ...}
STATUS:
200: success response
RESPONSE:
{
"affected_keys": 0,
}
Defines how to use memdb by using the CLI
Creating/Updating a key
KEY {keyname} SET {value}
Getting a key
KEY {keyname} GET
Deleting a key
KEY {keyname} DEL
Creating/Replacing the hash (can set multiple key-values separated by spaces)
HASH {keyname} SET {key} {value} ...
Adding/Replacing the hash properties (can set multiple key-values separated by spaces)
HASH {keyname} PUT {key} {value} ...
Getting a hash
HASH {keyname} GET
Deleting a hash
HASH {keyname} DEL
Deleting hash keys (can delete multiple keys separated by spaces)
HASH {keyname} DEL {key} ...