Coming from Redis
What Raft DB can do for a Redis workload (keys with JSON values, durable writes) and what it cannot (the protocol, data structures, expiry, publish and subscribe), with a mapping of the common commands.
Be clear about the fit before you start. Raft DB is a durable database, not a Redis replacement for every use. It can replace Redis as a key-value store whose values are JSON and must survive a restart. It cannot replace Redis where you rely on data structures, expiry or publish and subscribe, and a Redis client cannot connect to it: there is no Redis protocol.
Mapping#
| Redis | Raft DB | Note |
|---|---|---|
SET key value | POST .../documents with {"key":"key","document":{"value":...}} | The value is a JSON object, so wrap a plain string or number in a field. |
GET key | GET .../documents/{key} | 404 when absent. |
DEL key | DELETE .../documents/{key} | |
EXISTS key | GET, 404 or not | |
MSET / many SET | NDJSON import, or pipelined requests on the binary protocol | |
SCAN with a pattern | a JSON filter or SQL over the table | Keep the part you search on (a prefix, a tag) as a field. |
INCR | not atomic through the document API: read, add, write | A SQL front-end UPDATE ... SET n = n + 1 is the way to count safely. |
EXPIRE, TTL, SETEX | not available | See below. |
| lists, sets, sorted sets, hashes, streams, bitmaps, HyperLogLog | not available as such | Store them as documents or as rows in a table. |
PUBLISH / SUBSCRIBE | not available | |
Lua scripts, MULTI/EXEC | not available through the document API | SQL transactions exist on the SQL front-ends. |
Expiry#
There is no time-to-live. If your cache expires keys, you need one of:
- a field such as
expiresAtthat your code checks on read, and a scheduled job that deletes old rows (the MySQL and MariaDB front-ends haveCREATE EVENTfor scheduled jobs:DELETE FROM sessions WHERE expires_at < NOW()), or - keeping Redis for the expiring part.
Where it fits#
- Session stores, settings, feature flags, small state that must not be lost on restart.
- Data you also want to query, count, join or index, which Redis cannot do.
Where it does not#
- A cache that expires entries on its own, a rate limiter, a leaderboard on sorted sets, a job queue on lists, a message bus.
- Latency expectations of an in-memory protocol: Raft DB acknowledges a write only after it is on disk.
Moving the data#
Redis has no portable text export, so write a small script that walks the keys (SCAN), reads each value (GET, HGETALL, ...) and writes {"key": ..., "document": ...} lines, then import them through .../import in batches. Keys with an expiry have to be given an expiresAt field by the script (TTL tells you the remaining seconds). Do it on a replica or a copy of the Redis data.