Clients #
The server speaks RESP, so a Redis client works — with three adjustments: type mismatches never error,
scan cursors must stay opaque, and there is no SELECT/MULTI.
redis-cli #
redis-cli -h 127.0.0.1 -p 11001
# with TLS and auth
redis-cli --tls --cacert ./ca.crt -a "$ICEFIREDB_AUTH" -h db1.internal -p 11001
SET user:1 '{"name":"ada"}' EX 300
HGETALL user:1
SCAN 0 MATCH 'user:*' COUNT 100
XSCAN HASH "" MATCH '^user:' COUNT 100
INFO
redis-cli --scan works: it starts at 0 and loops until the cursor is 0 again.
Go (github.com/redis/go-redis/v9)
#
package main
import (
"context"
"crypto/tls"
"fmt"
"github.com/redis/go-redis/v9"
)
func main() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "127.0.0.1:11001",
Password: "", // set when the server runs with --auth
TLSConfig: nil, // &tls.Config{...} when --tls-cert/--tls-key are used
DB: 0, // there is only database 0
})
defer rdb.Close()
if err := rdb.Set(ctx, "user:1", `{"name":"ada"}`, 0).Err(); err != nil {
panic(err)
}
v, err := rdb.Get(ctx, "user:1").Result()
fmt.Println(v, err) // {"name":"ada"} <nil>
fmt.Println(rdb.HSet(ctx, "user:1", "name", "ada").Val()) // 1
// Paginate keys: the cursor is opaque, handle it as a string.
cursor := uint64(0)
for {
keys, next, err := rdb.Scan(ctx, cursor, "user:*", 100).Result()
if err != nil {
panic(err)
}
fmt.Println(keys)
if next == 0 {
break
}
cursor = next
}
}
Caveat — typed scan helpers. rdb.HScan, rdb.SScan, rdb.ZScan and rdb.Scan all coerce the
cursor through strconv.ParseUint, and HScan/SScan/ZScan additionally expect a numeric cursor.
This engine returns the last field/member name as the cursor for those three, so the typed helpers
fail with a parse error. Use the generic API instead:
cursor := "0"
for {
vals, err := rdb.Do(ctx, "HSCAN", "user:1", cursor, "MATCH", "n*", "COUNT", 100).Slice()
if err != nil {
panic(err)
}
cursor = fmt.Sprint(vals[0])
pairs := vals[1].([]interface{})
for i := 0; i+1 < len(pairs); i += 2 {
fmt.Println(pairs[i], pairs[i+1])
}
if cursor == "0" || cursor == "" {
break
}
}
redis.NewClusterClient also works: CLUSTER SLOTS reports one range covering 0-16383 on the leader,
which is a valid single-shard topology. It is pointless for distribution, useful for client uniformity —
and it follows -MOVED redirects automatically.
Python (redis-py)
#
import redis
r = redis.Redis(
host="127.0.0.1", port=11001,
password=None, # set when the server runs with --auth
ssl=False, # True with --tls-cert/--tls-key
decode_responses=True,
)
r.set("user:1", '{"name":"ada"}')
print(r.get("user:1"))
print(r.hset("user:1", "name", "ada"))
print(r.ttl("user:1")) # works: TTL is per type
# The typed helpers coerce the cursor to int, which this engine's cursors are not.
cursor = "0"
while True:
cursor, pairs = r.execute_command("HSCAN", "user:1", cursor, "COUNT", 100)
print(pairs)
if cursor in ("0", b"0"):
break
Node (ioredis)
#
const Redis = require("ioredis");
const r = new Redis({ host: "127.0.0.1", port: 11001 /*, password, tls: {} */ });
(async () => {
await r.set("user:1", '{"name":"ada"}');
console.log(await r.get("user:1"));
console.log(await r.hset("user:1", "name", "ada"));
// hscan returns [cursor, flatArray]; ioredis keeps the cursor as a string
let [cursor, flat] = await r.hscan("user:1", "0", "COUNT", 100);
while (cursor !== "0") {
[cursor, flat] = await r.hscan("user:1", cursor, "COUNT", 100);
}
})();
Standard caveats #
| Caveat | What to do |
|---|---|
No WRONGTYPE | Enforce type rules in a key-naming convention or in the application |
No TYPE command | Track the type yourself; or probe with EXISTS/HKEYEXISTS/LKEYEXISTS/SKEYEXISTS |
No SELECT | Set DB: 0 and forget about it |
No MULTI/EXEC | Use SET … NX for atomic claims, BARRIER for read-your-writes |
No BLPOP | Poll LPOP, or use a queue designed for blocking reads |
HGET/GET of an empty value returns null on P2P drivers | Store a sentinel when “empty” must survive |
Follower reads need --openreads | Without it, expect -MOVED 0 <leader> |
INFO takes no arguments | Parse the single reply; do not call INFO memory |
Health from a client #
redis-cli -p 11001 PING # PONG when the process is up
redis-cli -p 11001 BARRIER # OK once this client's writes are applied
redis-cli -p 11001 RAFT LEADER # who to write to
curl -fsS http://127.0.0.1:11002/readyz # 200 "ready" once storage is initialized