Coming from other databases

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#

RedisRaft DBNote
SET key valuePOST .../documents with {"key":"key","document":{"value":...}}The value is a JSON object, so wrap a plain string or number in a field.
GET keyGET .../documents/{key}404 when absent.
DEL keyDELETE .../documents/{key}
EXISTS keyGET, 404 or not
MSET / many SETNDJSON import, or pipelined requests on the binary protocol
SCAN with a patterna JSON filter or SQL over the tableKeep the part you search on (a prefix, a tag) as a field.
INCRnot atomic through the document API: read, add, writeA SQL front-end UPDATE ... SET n = n + 1 is the way to count safely.
EXPIRE, TTL, SETEXnot availableSee below.
lists, sets, sorted sets, hashes, streams, bitmaps, HyperLogLognot available as suchStore them as documents or as rows in a table.
PUBLISH / SUBSCRIBEnot available
Lua scripts, MULTI/EXECnot available through the document APISQL 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 expiresAt that your code checks on read, and a scheduled job that deletes old rows (the MySQL and MariaDB front-ends have CREATE EVENT for 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.