NodeNsync is a high-performance, distributed key-value store designed for scalability and fault tolerance. It supports clustering, replication, pub/sub messaging, and snapshot-based persistence, making it ideal for applications requiring fast data access with resilience.
- Distributed Clustering: Automatic leader election and slot-based sharding.
- Replication: Async data synchronization across nodes.
- Persistence: Periodic snapshots to disk for recovery.
- Pub/Sub Messaging: Real-time message broadcasting.
- Role-Based Access: Admin/user roles with session tokens.
- RESP Protocol Support: Compatible with standard Redis CLI tools.
- Rate Limiting: Protect against abusive clients.
- Health Monitoring: Track connections, latency, and memory usage.
- TLS Support: Secure client-server communication.
- Go 1.21+
- Redis CLI (for testing commands)
-
Clone the repository:
git clone https://github.com/yourusername/nodensync.git cd nodensync -
Build the binary:
go build -o nodensync cmd/server/main.go
-
Start the server (default: :6379):
./nodensync --listenAddr :6379
| Flag | Description | Default |
|---|---|---|
--listenAddr |
Address to listen on | :6379 |
--dataDir |
Directory for snapshots | ./data |
--snapshotInterval |
Auto-snapshot interval | 1m |
--rateLimit |
Max commands/sec per client | 3 |
--enableTLS |
Enable TLS encryption | false |
Example:
./nodensync --listenAddr :6380 --dataDir /mnt/data --rateLimit 10 --enableTLS| Command | Syntax | Description |
|---|---|---|
| AUTH | AUTH <username> <password> |
Authenticate with role-based access |
| SET | SET <key> <value> |
Store a key-value pair |
| GET | GET <key> |
Retrieve value by key |
| DEL | DEL <key> |
Delete a key |
| INCR | INCR <key> |
Atomically increment integer value |
| Command | Syntax | Description |
|---|---|---|
| HSET | HSET <key> <field> <value> |
Set hash field value |
| HGET | HGET <key> <field> |
Get hash field value |
| Command | Syntax | Description |
|---|---|---|
| PUBLISH | PUBLISH <channel> <message> |
Broadcast message to channel |
| SUBSCRIBE | SUBSCRIBE <channel> |
Receive messages from channel |
| UNSUBSCRIBE | UNSUBSCRIBE [channel...] |
Stop listening to channels |
| Command | Syntax | Description |
|---|---|---|
| INFO | INFO |
Get server statistics & metrics |
| ROLE | ROLE |
Show node role (leader/follower) |
| REPLICAOF | REPLICAOF <host> <port> |
Configure replication |
| MONITOR | MONITOR |
Stream all executed commands |
| Command | Syntax | Description |
|---|---|---|
| PING | PING |
Check server responsiveness |
| HELP | HELP |
List available commands |
Start 3-node cluster:
# Node 1 (Leader)
./nodensync --listenAddr :7000
# Node 2
./nodensync --listenAddr :7001
# Node 3
./nodensync --listenAddr :7002Join cluster via Redis CLI:
REPLICAOF 127.0.0.1 7000
Configure node as replica:
127.0.0.1:6380> REPLICAOF 127.0.0.1 6379
Manual snapshot creation:
SAVE
127.0.0.1:6379> INFO
# Server
version:1.0.0
uptime:2h35m
connected_clients:8
used_memory:256MB
# Replication
role:master
connected_slaves:2
master_repl_offset:89234
# Keyspace
db0:keys=1532
-
Generate certificates:
openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365
-
Start server with TLS:
./nodensync --enableTLS --tlsCert cert.pem --tlsKey key.pem
-
Connect with Redis CLI:
redis-cli --tls --cert ./cert.pem --key ./key.pem -p 6379
-
Install dependencies:
go get github.com/tidwall/resp
-
Run tests:
go test ./... -
Build with optimizations:
go build -ldflags "-s -w" -o nodensync cmd/server/main.go
- Fork the repository
- Create feature branch:
git checkout -b feat/new-feature - Commit changes:
git commit -am 'Add awesome feature' - Push:
git push origin feat/new-feature - Submit pull request
Q: How is this different from Redis?
A: NodeNsync focuses on horizontal scaling and simplicity, while maintaining Redis protocol compatibility.
Q: Can I use existing Redis clients?
A: Yes! Any RESP-compatible client (redis-py, Jedis, etc.) will work.
Q: Where are snapshots stored?
A: In the dataDir specified at startup (default: ./data).
Q: How to reset the database?
A: Stop server and delete all .json files in the data directory.