MemFast Key-Value DataStore
Introduction
MemFast is an In-Memory Key-Value DataStore built with Rust Lang and Axum.rs. It is very fast and simple to use.
Note: The project is still in Alpha.
Features
- Fast (Benchmarks coming soon)
- No Driver required
- Supports Serverless
- Persistence (Partial)
- Key Synchronization (Naive)
- more to come...
Libraries used:
About MemFast
MemFast is a super fast and simple to use Key-Value store built in Rust Lang and Axum.rs.
Fast and Memory Safety
All because of Rust's Memory Safety and Axum's Speed.
Serverless
Traditional Key-Value stores like Redis are not Serverless by default. But MemFast includes a simple POST endpoint that can be used to send queries from a Serverless Context.
Driverless
MemFast exposes two simple services: WS and POST. Use WS for continuous queries and POST for one-off queries.
Lazy Persistence
MemFast can dump all the Key-Value pairs into a CSV file on demand.
Key Synchronization
MemFast has the ability to synchronize keys between multiple MemFast instances.
Basic Architecture
Getting Started
There are two ways to install MemFast:
Specify the Port as a first argument while running the executable or build from source.
Connect to MemFast
There are two ways to connect to a MemFast instance:
- WebSocket Endpoint
- POST Endpoint
Making Queries
- From WebSocket Endpoint: Send the query as a simple text message.
SET key value
- From POST Endpoint: Send the query as a JSON object.
{
"query": "SET key value",
}
Commands
MemFast ships with commands for basic CRUD operations and lazy persistence and key synchronization. These include:
- SET
- GET
- DEL
- EXISTS
- LEN
- ISEMPTY
- CLEAR
- DUMP
- NET
- SETSYNC
All the commands are case-sensitive.
SET
To set a Key-Value pair in the data store use the SET command.
Syntax:
SET <key> <value>
Example:
This would set world
to hello
:
Command: SET hello world
Returns: Inserted!
To update hello
to universe
, use the SET command again:
Command: SET hello universe
Returns: world
This command returns the previous value of hello
.
GET
To get the Value associated with a Key use the GET command.
Syntax:
GET <key>
Example:
Command: GET hello
Returns: universe
DEL
To delete a Key-Value pair in the data store use the DEL command.
Syntax:
DEL <key>
Example:
Command: DEL hello
Returns: Deleted!
EXISTS
Check if a key exists in the data store.
Syntax:
EXISTS <key>
Examples:
Command: EXISTS hello
Returns: false
Command: SET hello world
Command: EXISTS hello
Returns: true
LEN
Get the total number of keys in the data store.
Syntax:
LEN
Example:
Command: LEN
Returns: 1
Returns 1 because there is only one key(hello
) in the data store.
ISEMPTY
Check if the data store is empty.
Syntax:
ISEMPTY
Example:
Command: ISEMPTY
Returns: false
Command returns false
because the key hello
exists in the data store.
CLEAR
Clears/Empties the data store.
Syntax:
CLEAR
Example:
Command: CLEAR
Returns: Cleared!
Command: ISEMPTY
Returns: true
DUMP
Dumps all the Key-Value pairs into a CSV file on demand.
Syntax
DUMP <path-to-file>
Example:
Command: SET name Sheldon
Command: SET friend Leonard
Command: SET wife Amy
Command: DUMP dump.csv
Returns: Dumped!
The table below shows the Key-Value pairs in the dump.csv
file.
Key | Value |
---|---|
name | Sheldon |
friend | Leonard |
wife | Amy |
NET
Creates a network of MemFast nodes that needs to be synchrnoized.
Syntax:
NET <name> <num-of-nodes> [...<node-ip>]
Example:
Command: NET dummy_net 2 http://localhost:3030 http://localhost:3031
Returns: Created!
This command creates dummy_net
network with 2 nodes. To be used with SETSYNC
command.
Note: Make sure that the nodes are running before running this command.
SETSYNC
Set a Key-Value pair and sync it to other nodes in the network.
Syntax:
SETSYNC <network-name> <key> <value>
Example:
Connect to ws://localhost:3030
and set hello
to world
.
Command: SETSYNC dummy_net hello world
Returns: Synced!
Now connect to ws://localhost:3031
and check if hello
is world
.
Command: GET hello
Returns: world
You can even change the value of hello
from 3031
node and sync it to other nodes.
Command: SETSYNC dummy_net hello universe
Returns: Synced!
Performance Benchmark
MemFast vs Redis SET Speeds: