A Node.js SDK for DiceDB, a fast, reactive, in-memory database.
npm install dicedb.js
import { Dice } from 'dicedb.js';
// Initialize client
const client = new Dice({
host: 'your-dicedb-host', // Replace with your DiceDB host
port: 6379, // Default port
});
// Connect to server
await client.connect();
// Set a key
await client.set('user:1', JSON.stringify({ name: 'Alice' }));
// Get the key
const data = await client.get('user:1');
console.log(JSON.parse(data.ack)); // { name: 'Alice' }
// Delete the key
await client.del('user:1');
// Close connection
client.close();
Command | Method | Example |
---|---|---|
SET | .set(key, value) |
await client.set('key', 'value') |
GET | .get(key) |
await client.get('key') |
DECR | .decr(key, value?) |
await client.decr('counter', 5) |
DEL | .del(...keys) |
await client.del('key1', 'key2') |
INCR | .incr(key, value?) |
await client.incr('counter') |
EXISTS | .exists(...keys) |
await client.exists('key1', 'key2') |
EXPIRE | .expire(key, opts) |
await client.expire('key', { sec: 60 }) |
GETDEL | .getdel(key) |
await client.getdel('key') |
GETEX | .getex(key, opts) |
await client.getex('key', { ex: 60 }) |
FLUSHDB | .flush() |
await client.flush() |
TTL | .ttl(key) |
await client.ttl('key') |
TYPE | .type(key) |
await client.type('key') |
WATCH | .watch(key) |
await client.watch('key') |
UNWATCH |
await client.set('foo', 'bar');
const value = await client.get('foo');
console.log(value.ack); // 'bar'
await client.set('counter', 0);
await client.incr('counter');
console.log((await client.get('counter')).ack); // '1'
await client.set('session', 'active');
await client.expire('session', { sec: 60 });
await client.del('session');
const watch = await client.watch('user:1');
watch.on("data", (data) => {
console.log(data);
})
const client = new Dice({
host: 'your-dicedb-host',
port: 6379,
});
await client.connect();
client.close(); // Gracefully close the connection
- ✅ Auto Reconnection
- ✅ Connection Pooling
- ✅
WATCH
/UNWATCH
Support - ✅ Comprehensive Test Coverage
- DiceDB Official Website
- DiceDB Benchmarks
- DiceDB Commands
- DiceDB GitHub
- DiceDB Discord
- Follow DiceDB on Twitter
This SDK is actively in development. Do not use in production - breaking changes may occur.