# redis

Redis over RESP2/RESP3 on `tcp.open`, or Upstash's REST API behind the same
calls. The whole of it is [docs/redis.md](../../docs/redis.md).

```text
use "pkg:redis/redis.mote"

redisSet("session:17", token, {ex: 3600})?
let l = redisLimit(`signin:${email}`, 5, 60000)?
let lock = redisLock("invoice:17", 30000)?
```

Settings: `REDIS_URL` (a secret: `redis://`, `rediss://`, or
`https://:<token>@<name>.upstash.io`), `REDIS_CA` (PEM, for a server's own
authority).

| File | |
|---|---|
| `redis.mote` | The address; RESP both ways; the pool; the typed calls; pipelines, MULTI/EXEC, pub/sub, streams; REST; the limiter, the lock, cache-aside. |
| `tests.mote` | Its tests: `use "pkg:redis/tests.mote"`, then `mote test`. |

**Covered**: strings with expiry and NX/XX, counters, hashes, lists (and a
pop that waits), sets, sorted sets, streams with consumer groups, any
command raw, pipelines, transactions, pub/sub with patterns, AUTH with an
ACL user, TLS, a pool, a connection tried again after the server closed it
(reads only); a sliding-window rate limiter, a lock with a fencing token,
cache-aside with a spread expiry.

**Left out on purpose**: Cluster (MOVED/ASK), Sentinel, client-side
caching, binary replies, `WATCH` across calls.

**Never run against a real Redis or Upstash**: against a stand-in over TCP,
TLS and REST (`tests/all.sh real_svc_redis`, `real_redis_live`). One command
runs `real_redis_live` against a real one: `MOTE_REDIS_URL=… tests/all.sh real_redis_live`.
