Coordination in one command

Use cases

Ruvio speaks RESP, so any Redis client can talk to it. What sets it apart is a set of commands that finish a coordination job on the shard that owns the key, in one call. Below are the jobs people reach for, with the commands as you would type them in redis-cli and a link to the reference. To see the main ones run in a few seconds against a local server, use the building blocks tour.

Rate limits and quotas

A fixed window per API key, per user, or per tenant, in one command on the shard that owns the key.

ClientLIMITApptokens leftrejectedRequests pass while tokens last.Bucket empty: the next requests are rejected.Refilled: requests pass again.
Rate limits in one commandLIMIT does the fixed-window, sliding-window or token-bucket check atomically on the shard.

LIMIT key max window_ms returns the remaining allowance, or a null bulk when the window is full. A rejected call is not counted. The window is the key's deadline, so a quiet key disappears by itself. SLIDING weighs the previous window by how much of it still overlaps, so a burst at a window edge is not doubled. TOKENS is a token bucket that refills continuously and takes COST tokens per call. Both keep a few bytes per key, and WITHRETRY adds the wait to the reply for a Retry-After header. In WAL-backed modes the accepted call is a log record.

Keep in mindA key keeps the mode it was created with. The sliding window is an estimate from two counters, not an exact log of calls.

ReferenceLIMIT

.NET packageRuvio.AspNetCore.RateLimiting

LIMIT api:key-7 100 60000
# 99    -> 99 calls left in this 60 s window
# (nil) -> window is full, nothing was counted

LIMIT api:key-7 100 60000 SLIDING
LIMIT api:key-7 10 1000 TOKENS COST 2 WITHRETRY
# [8, 0]   -> 8 tokens left, go ahead
# [-1, 150] -> refused, retry in 150 ms

Locks, leader election and fencing

One worker at a time holds a named resource; others get a null reply until it frees or expires.

Worker 1Worker 2LEASEStoretoken 41token 42paused…✕ stale 41Worker 1 takes the lease and gets fencing token 41.Worker 1 stalls. The lease expires.Worker 2 takes it with token 42. Worker 1 wakes up…The store rejects the stale token 41. No split brain.Only the holder of the newest token can write.
Locks that stay safe when workers stallEvery LEASE returns a fencing token; a stale holder is rejected instead of corrupting data.

Each grant returns a token that grows. Send it with writes to the thing you protect and have that side reject older tokens. A long job calls RENEW with its token to keep the lock without releasing it. Tokens are opaque 64-bit integers that only grow.

Keep in mindTokens never go backwards, also after expiry, a restart or a failover. For a lock that survives a failover, take it on a connection that sent CLIENT DURABILITY REPLICAS 1, keep the nodes' clocks synchronized, and have the protected resource reject a token lower than the last one it saw.

ReferenceLEASE, RENEW and RELEASE

.NET packageRuvio.AspNetCore.DistributedLock

LEASE job:nightly-report 30000
# token -> you hold it
# (nil) -> someone else holds it
RENEW job:nightly-report 17 30000
# 1     -> deadline moved to now + 30 s (0 if the token no longer holds it)
RELEASE job:nightly-report 17
# 1     -> released (0 if the token no longer matches)

Concurrency limits for workers

At most N holders at once: image resizers, export jobs, calls to a slow upstream.

Every holder has its own TTL, so a crashed worker frees its slot when the TTL ends. The key is removed when the last holder leaves.

Keep in mindPick a TTL longer than the longest normal job, and release as soon as you finish.

ReferenceSEMAPHORE

SEMAPHORE upstream:billing 8 15000
# 1700000000123 -> a slot, this is your token
# (nil)         -> all 8 slots are taken
RELEASE upstream:billing 1700000000123

Inventory, tickets and seat counts

Sell from a counter without overselling, with no script and no read-then-write race.

Buyersstock:423210left✕ sold outEach TAKE removes one unit atomically.Stock is 0: the next TAKE is refused.
Stock that never goes below zeroTAKE removes an amount only when enough is left, so overselling cannot happen.

TAKE subtracts only when the key holds enough. INCRBY … MAX adds only while the result stays at or below the cap. Both answer with a null bulk and write nothing when they refuse. EX or PX on INCR and INCRBY sets a deadline only when the call creates the counter, so a daily counter needs one command.

Keep in mindA refused call writes nothing, neither to the key nor to the WAL.

ReferenceTAKEINCRBY MAXTTL on create

SET stock:ticket-42 500
TAKE stock:ticket-42 2
# 498   -> took 2, 498 left
# (nil) -> not enough, the key is unchanged

INCRBY seats:room-9 1 MAX 120
# 57    -> joined
# (nil) -> room is full, nothing was written

INCR hits:user-7:2026-10-19 EX 86400
# 1     -> first hit, the day's deadline is set
# 2, 3… -> later hits leave the deadline alone

Credits, points and wallet moves

Move an amount from one balance to another only when the first one has enough, with no script and no retry loop.

account:aaccount:b1002070503090?✕ not enoughTRANSFER a b 30 …Moved in one atomic step: a 70, b 50.TRANSFER a b 90 is refused. Balances stay put.
Balances that cannot go negativeTRANSFER moves an amount between two keys only when the source holds enough.

TRANSFER moves an amount between two integer keys, HTRANSFER between two fields of one hash. Both balances change in one WAL record, and a refusal (short source, or a destination past MAX) answers with a null bulk and writes nothing.

Keep in mindTRANSFER keys must share a slot; a hash tag such as {user:42} keeps them together.

ReferenceTRANSFERHTRANSFER

SET {user:42}:wallet 50
TRANSFER {user:42}:wallet {user:42}:escrow 30
# 1) 20  -> wallet after
# 2) 30  -> escrow after
# (nil)  -> not enough, nothing changed

HTRANSFER account:7 available held 30 MAX 1000
# 1) 20  -> available after
# 2) 30  -> held after

Idempotent APIs and payments

A retry of the same request replays the stored answer instead of running the handler again.

ClientIDEMPaymentpay-7✕ reply loststoredFirst call: executed once, the answer is stored.The reply is lost. The client retries.Retry: the stored answer comes back. Payment is not hit again.One charge, however many retries.
Retries that run onceIDEM stores the answer to a request key, so a replay returns it instead of running again.

BEGIN answers acquired, pending, conflict (same key, different fingerprint), or completed with the saved result. For plain once-only work such as a webhook delivery id, ONCE key ttl_ms is the lighter tool: 1 the first time, 0 until the deadline.

Keep in mindThis does not make an outside effect exactly-once. A handler can crash before COMPLETE, so the payment provider still needs its own idempotency key.

ReferenceIDEMONCE

.NET packagesRuvio.AspNetCore.IdempotencyRuvio.Extensions.Idempotency

IDEM order:42 BEGIN request-digest attempt-1 60000
# ["acquired"]                 -> run the handler once
IDEM order:42 COMPLETE request-digest attempt-1 saved-result
# 1
IDEM order:42 BEGIN request-digest attempt-2 60000
# ["completed","saved-result"]

Lost-update protection

Two editors open the same record; only the one holding the current version may save.

Optimistic concurrency without WATCH or a script. Only keys written with SETV carry a version.

Keep in mindA plain SET replaces a versioned string.

ReferenceSETV

SETV profile:ada "{...}"
# 1     -> version 1 created
SETV profile:ada "{...}" 1
# 2     -> accepted, now version 2
SETV profile:ada "{...}" 1
# error -> stale version, value unchanged

Watermarks and best values

Keep the newest timestamp, the highest version or the lowest price, no matter in which order writers arrive.

SET key number IFGT writes only when the number is greater than the stored integer (IFLT for smaller) and takes the usual expiry options. One command replaces a read-compare-write script.

Keep in mindIntegers only. A stored value that is not an integer is an error and is left unchanged.

ReferenceSET

SET watermark:orders 1700000200 IFGT
# OK    -> written (key was missing or smaller)
SET watermark:orders 1700000100 IFGT
# (nil) -> stored number is greater, nothing written
SET price:best 499 IFLT PX 3600000
# OK    -> new lowest price, expires in an hour

Sessions and sliding expiry

Reading a session keeps it alive; an idle one expires on its own.

GETEX returns the string and moves its deadline in one step, so there is no separate EXPIRE call. GET does not move a deadline.

ReferenceGETEX

.NET packagesRuvio.Extensions.CachingRuvio.AspNetCore.DataProtection

SET session:9f3 "{...}" PX 1800000
GETEX session:9f3 1800000
# "{...}" and the deadline is now 30 min from now

Cache fills without stampedes

When a hot key expires, one caller refills it and the others wait or serve the stale copy.

App 1App 2CacheDBv1freshv1expiredv1refillingv2freshv2freshApp 2 waits orgets the stale copyFILLGET: cache hit, served from memory.Key expired: only one caller refills it from the DB.The DB is hit once, not once per caller.Cache fresh again: a stampede avoided.
Caches without stampedesWhen a hot key expires, one caller refills it while the others wait or get the stale copy.

One round trip decides who loads from the database. WAIT holds a caller that would get BUSY until the filler writes, so there is no retry loop in the client. On one shared connection use GetOrCreate (C# and the other clients): it polls without WAIT, so no other command waits behind a held connection.

Keep in mindFill markers live in memory only and lapse after fill_ms. WAIT is refused inside MULTI and scripts.

ReferenceFILLGET and FILLSET

.NET packagesRuvio.Extensions.CachingRuvio.AspNetCore.OutputCachingRuvio.Extensions.FusionCache

FILLGET product:42 5000 WAIT 200
# [HIT, value]          -> served from memory
# [FILL, token]         -> you refill it
# [BUSY, nil]           -> someone else is filling
# [STALE, value, token] -> stale copy, and you refresh it (SWR window)
# [STALE, value, nil]   -> stale copy, another caller is refreshing
FILLSET product:42 "{...}" 60000 <token> SWR 30000
# 1 -> stored (0 if the token is no longer live)

Delayed jobs and queues

Schedule work for later with a stream and a consumer group, without a separate scheduler.

Delayed queueWorker+3s+6s+9snow+12s3 jobs doneJobs wait, hidden, until their time comes.A job is due: ZPOPBYSCORE hands it to a worker.Each due job is taken once, by one worker.Nothing is polled, nothing is run early.
Delayed jobs that run on timeZPOPBYSCORE and ZMOVEDUE take only the members whose time has come, in one command.

The entry is stored right away. XREADGROUP skips it until the delay passes, and XREAD can still see it. Pending entries, XCLAIM and XAUTOCLAIM work as in Redis streams. For a plain schedule keep the run time as the score of a sorted set: ZPOPBYSCORE returns the members that are due and removes them, and ZMOVEDUE moves them to a list in one recorded step, up to 10000 per call.

Keep in mindThe hold is a WAL record and is written only when a delay is set.

ReferenceXADD DELAYZPOPBYSCORE and ZMOVEDUE

XGROUP CREATE jobs workers $ MKSTREAM
XADD jobs DELAY 30000 * kind send-reminder user 42
XREADGROUP GROUP workers w1 COUNT 10 BLOCK 5000 STREAMS jobs >
# nil until the 30 s delay has passed; the worker keeps reading in a loop
XACK jobs workers <id>

ZADD due:jobs 1700000300 job:9 1700000360 job:10
ZPOPBYSCORE due:jobs 1700000330 COUNT 10
# job:9 -> due and removed in the same call
ZMOVEDUE due:jobs queue:ready 1700000400 COUNT 100
# 1     -> moved to the tail of the list queue:ready

Change feeds

React to writes (cache invalidation, search indexing, audit) by reading a feed instead of polling.

Shard write log#1#2#3#4#5#6Consumercursor 2cursor 4cursor 6Writes append to the shard log.The consumer reads from its cursor: only new entries.No key polling. After a restart it resumes from the cursor.
A change feed from a cursorCHANGES returns the writes on a shard after a cursor, so consumers never poll keys.

The durable feed is built from the WAL and can resume from a saved position, with optional key patterns, types and values. CHANGES START is the lighter in-memory feed of up to 1024 notes per shard.

Keep in mindThe stream needs a durability profile with a WAL and is refused on a replica. It takes over its connection, so give it a connection of its own. Limits and retention are under Change stream in the configuration reference.

ReferenceCHANGESChange stream settings

CHANGES SUBSCRIBE FROM NOW MATCH user:* TYPES put,del
# a durable stream of changes, resumable with FROM <shard>:<seq>

Scale reads with replicas

Send read-heavy traffic to replicas while writes stay on the primaries.

ClientPrimaryReplica 1Replica 2writes →primaryreads →replicas
Spread reads across replicasWrites go to the primary; replicas stay in sync and serve reads, so read capacity scales out.

A replica tells its primary where clients reach it. Once it has finished copying, the primary lists it after its own shard in CLUSTER SLOTS, CLUSTER SHARDS, CLUSTER NODES, ROLE and INFO replication. Every Ruvio client takes a read policy: primary (the default), prefer-replica or replica. Reads go to one replica per shard, picked when the slot map loads; writes, transactions, blocking commands and any pipeline with a write stay on the primary. A replica that is down or still copying is skipped.

Keep in mindReplication is asynchronous: a read from a replica can miss a write the primary already acknowledged, including your own. Set advertised_host on replicas behind NAT or in containers; replication.announced = false keeps a replica out of the topology.

ReferenceClient behaviorReplication settings

CLUSTER SLOTS
# 1) 0, 8191,     [10.0.0.5, 7000, <id>], [10.0.0.6, 7000, <id>]
# 2) 8192, 16383, [10.0.0.5, 7001, <id>], [10.0.0.6, 7001, <id>]
#    each range: the primary shard, then its replicas
ROLE
# master, <sequence>, [[10.0.0.6, 7000, <acknowledged>]]

Move slots off a busy shard

One shard takes most of the traffic while the other cores idle.

Node ANode Bslotsslot 016383■ owned by A ■ moved to BRebalance starts. Clients keep reading and writing.Moving slots: a key already gone gets ASK → B.Done: B owns them (MOVED). Clients update their table.
Slots move between nodes under loadCOORDINATOR MOVE and REBALANCE hand slots over without pausing traffic.

Both shards keep serving the range while it moves. The source copies it in bounded steps, sends the keys written meanwhile again, and hands over in one short step; clients that still route to the old shard are forwarded, and pick up the new owner on their next slot map load. With a log the move survives a crash at any step, and the old shard's CHANGES feed says where the range continues.

Keep in mindSlots move between the shards of one server, one move at a time, and not while replication is on. The hand-over pauses the source shard briefly (well under a millisecond without a log, around 15 ms with one on a Mac, mostly the log sync). A server that moved slots writes WAL records an older release cannot read.

ReferenceRUVIO MOVESLOTSMoved slot ranges

RUVIO MOVESLOTS 0-2047 3
# OK: slots 0-2047 start moving to shard 3 (shards count from 0)
RUVIO MOVESLOTS STATUS
# state copying, keys 120544, ...  then cleaning, then done
CLUSTER SLOTS
# 0-2047 now on shard 3

Spread the slots over several machines

One machine is not enough for the writes or the data.

ClientSET / GETNode ANode BNode CPRIMARYOFFLINEREPLICAPRIMARYREPLICA✕ unreachableNormal: A takes writes, B and C stay in sync.A drops off the network. B and C vote by majority…B becomes primary. The client follows it automatically.Writes continue where they left off.
A node drops off, Ruvio keeps servingThe coordinator promotes a replica by majority vote; clients follow the new primary on their own.

Each group (a primary and its replicas) serves the slots the map gives it, split over its own shards, and answers MOVED with the owning shard's address for every other slot, so cluster clients go straight to the right machine. CLUSTER SLOTS describes the whole map on every node. With ruvio coordinator managing the groups, every node gets a newer map after a failover, so MOVED names the new primary, and COORDINATOR REBALANCE evens out the slots after a group joins.

Keep in mindThe map is fixed when the cluster is created: slots do not move between machines yet, and a node that holds keys of slots the map serves elsewhere does not start. Keyless commands, WAIT and classic PUBLISH stay on the node that receives them; use SPUBLISH for channels the whole cluster shares.

ReferenceMulti-node settingsCoordinator

# topology.toml, the same on every node
version = 1

[[groups]]
name = "a"
address = "10.0.0.5:7000"
shards = 4
slots = ["0-8191"]

[[groups]]
name = "b"
address = "10.0.0.6:7000"
shards = 4
slots = ["8192-16383"]

# on 10.0.0.5: cluster_topology = "topology.toml", cluster_group = "a"
GET user:1      # a key of group b, sent to 10.0.0.5
# -MOVED 10778 10.0.0.6:7001

Leaderboards, geo and documents

The data types you already use, plus JSON documents with an exact-match index.

Strings, lists, sets, hashes, sorted sets, streams, geo, Bloom filters and JSON are covered. JSON.INDEX is an exact-equality index on one scalar field; it works on database 0 and keeps its postings in memory.

ReferenceData typesCommands

ZADD leaderboard 1200 ada 980 grace
ZRANGE leaderboard 0 9 REV WITHSCORES
# cities was filled earlier with GEOADD
GEOSEARCH cities FROMLONLAT 13.36 38.11 BYRADIUS 50 km COUNT 10
JSON.SET user:7 $ '{"plan":"pro","country":"TR"}'
JSON.INDEX CREATE by_plan PREFIX user: PATH $.plan TYPE string
JSON.FIND by_plan VALUE pro COUNT 20
# ERR index is building -> the first build runs in the background; retry

Moving from Redis

Ruvio is not a full Redis clone. It speaks RESP2 and covers the commands listed in the command reference. Check that the commands you use are there before you switch.

ruvio-ctl import copies keys with their TTLs from a running Redis and can verify the copy. It does not move consumer groups, Lua scripts, ACL users or module types.

Start with Get started, then pick a client. For durability modes and what each one promises, see Configuration and Recovery.

ReferenceImportCompatibilityCommands

Try it on your machine

One Docker command or a prebuilt binary, then redis-cli. Or try three of these commands in the browser.