Redis Compatibility
Swytch provides a Redis-compatible server that supports the vast majority of Redis commands. It can operate in pure in-memory mode or with persistent tiered storage that survives restarts.
# Start with defaults (64MB memory, port 6379)
swytch redis
# Production setup with 4GB memory
swytch redis --maxmemory=4gb --bind=0.0.0.0
# Enable persistence
swytch redis --persistent --db-path=/data/redis.db
# With authentication
swytch redis --requirepass=mysecret --bind=0.0.0.0
Swytch implements a comprehensive set of Redis commands across all major data types.
| Command | Description |
|---|---|
GET, SET, SETNX, SETEX, PSETEX | Basic get/set operations |
MGET, MSET, MSETNX | Multi-key operations |
GETEX, GETDEL, GETSET | Get with side effects |
INCR, DECR, INCRBY, DECRBY, INCRBYFLOAT | Atomic counters |
APPEND, STRLEN | String manipulation |
GETRANGE, SETRANGE | Substring operations |
LCS | Longest common subsequence |
| Command | Description |
|---|---|
DEL, EXISTS, TYPE | Key inspection and deletion |
EXPIRE, EXPIREAT, PEXPIRE, PEXPIREAT | Set expiration |
TTL, PTTL, EXPIRETIME, PEXPIRETIME | Get expiration |
PERSIST | Remove expiration |
RENAME, RENAMENX | Rename keys |
COPY, MOVE | Copy/move between databases |
KEYS, SCAN, RANDOMKEY | Key enumeration |
SORT, SORT_RO | Sort list/set/zset contents |
| Command | Description |
|---|---|
SETBIT, GETBIT | Individual bit operations |
BITCOUNT | Count set bits |
BITPOS | Find first set/clear bit |
BITOP | Bitwise AND, OR, XOR, NOT |
BITFIELD, BITFIELD_RO | Arbitrary bit field operations |
| Command | Description |
|---|---|
LPUSH, RPUSH, LPUSHX, RPUSHX | Add elements |
LPOP, RPOP | Remove and return elements |
BLPOP, BRPOP | Blocking pop |
LMPOP, BLMPOP | Pop from multiple lists |
LMOVE, BLMOVE | Atomically move elements |
RPOPLPUSH, BRPOPLPUSH | Pop and push (deprecated) |
LLEN, LRANGE, LINDEX | Inspection |
LSET, LINSERT, LPOS | Modification |
LREM, LTRIM | Removal |
| Command | Description |
|---|---|
HGET, HSET, HSETNX, HMGET, HMSET | Get/set fields |
HDEL, HEXISTS | Delete and check fields |
HGETALL, HKEYS, HVALS, HLEN | Enumerate hash |
HINCRBY, HINCRBYFLOAT | Atomic field increment |
HSTRLEN, HRANDFIELD | Field utilities |
HSCAN | Incremental iteration |
HEXPIRE, HPEXPIRE, HTTL, HPTTL | Per-field expiration |
HGETDEL, HSETEX, HGETEX | Extended operations |
| Command | Description |
|---|---|
SADD, SREM, SPOP | Add/remove members |
SCARD, SISMEMBER, SMISMEMBER | Membership tests |
SMEMBERS, SRANDMEMBER | Retrieve members |
SINTER, SINTERSTORE, SINTERCARD | Intersection |
SUNION, SUNIONSTORE | Union |
SDIFF, SDIFFSTORE | Difference |
SMOVE | Move between sets |
| Command | Description |
|---|---|
ZADD, ZREM, ZINCRBY | Add/remove/increment |
ZSCORE, ZMSCORE, ZCARD | Score lookup |
ZRANK, ZREVRANK | Rank lookup |
ZRANGE, ZREVRANGE | Range by rank |
ZRANGEBYSCORE, ZREVRANGEBYSCORE | Range by score |
ZRANGEBYLEX, ZREVRANGEBYLEX | Range by lex |
ZCOUNT, ZLEXCOUNT | Count in range |
ZPOPMIN, ZPOPMAX, BZPOPMIN, BZPOPMAX | Pop min/max |
ZMPOP, BZMPOP | Pop from multiple zsets |
ZREMRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYLEX | Remove ranges |
ZUNION, ZINTER, ZDIFF | Set operations |
ZUNIONSTORE, ZINTERSTORE, ZDIFFSTORE | Store set operations |
ZINTERCARD | Intersection cardinality |
ZRANGESTORE, ZRANDMEMBER | Utilities |
| Command | Description |
|---|---|
XADD, XLEN, XDEL, XTRIM | Basic stream operations |
XRANGE, XREVRANGE, XREAD | Read entries |
XGROUP | Consumer group management |
XREADGROUP | Read as consumer group |
XACK, XPENDING | Acknowledgment |
XCLAIM, XAUTOCLAIM | Claim pending entries |
XINFO, XSETID | Stream information |
| Command | Description |
|---|---|
PFADD | Add elements |
PFCOUNT | Estimate cardinality |
PFMERGE | Merge HyperLogLogs |
| Command | Description |
|---|---|
GEOADD | Add locations |
GEODIST | Distance between points |
GEOHASH, GEOPOS | Get hash/coordinates |
GEORADIUS, GEORADIUSBYMEMBER | Search by radius (deprecated) |
GEOSEARCH, GEOSEARCHSTORE | Search locations |
| Command | Description |
|---|---|
SUBSCRIBE, UNSUBSCRIBE | Channel subscription |
PSUBSCRIBE, PUNSUBSCRIBE | Pattern subscription |
PUBLISH | Publish message |
PUBSUB | Introspection |
| Command | Description |
|---|---|
MULTI | Start transaction |
EXEC | Execute transaction |
DISCARD | Abort transaction |
WATCH, UNWATCH | Optimistic locking |
| Command | Description |
|---|---|
EVAL, EVALSHA | Execute Lua scripts |
EVAL_RO, EVALSHA_RO | Read-only script execution |
SCRIPT | Script management |
FUNCTION, FCALL, FCALL_RO | Function library support |
| Command | Description |
|---|---|
PING, ECHO | Connection test |
AUTH, HELLO | Authentication |
SELECT, SWAPDB | Database selection |
INFO, DBSIZE, TIME | Server information |
FLUSHDB, FLUSHALL | Clear databases |
CONFIG, CLIENT, MEMORY | Server management |
COMMAND | Command introspection |
SHUTDOWN | Stop server |
| Option | Default | Description |
|---|---|---|
--port | 6379 | TCP port to listen on |
--bind | 127.0.0.1 | Bind address |
--unixsocket | - | Unix socket path |
--unixsocketperm | 0700 | Unix socket permissions |
--databases | 16 | Number of databases |
--maxmemory | 64mb | Memory limit (e.g., 256mb, 4gb). Default is suitable for testing |
--requirepass | - | Password for AUTH |
--maxclients | 0 | Max connections (0 = unlimited) |
--timeout | 0 | Client idle timeout in seconds |
--threads | 0 | Sets GOMAXPROCS (0 = all CPUs) |
Note: There is no --maxmemory-policy flag. Swytch uses a self-tuning frequency-based eviction algorithm that
automatically adapts to your workload. See Eviction Policy below.
| Option | Default | Description |
|---|---|---|
--persistent | false | Enable persistent tiered storage |
--db-path | redis.db | Path to persistent storage file |
--defragment | false | Defragment log file on startup |
--ghost | false | Ghost mode: write-back instead of write-through |
--pprof | - | Enable pprof on this port |
--metrics-port | - | Enable Prometheus metrics on this port |
-v | false | Verbose output |
--debug | false | Log all commands processed |
Swytch offers two persistence modes that go far beyond traditional Redis persistence. See Tiered Storage for the complete guide.
By default, Swytch runs as a pure in-memory cache. Data is lost on restart but performance is maximised.
swytch redis --maxmemory=4gb
Enable tiered storage for full durability. Unlike Redis AOF/RDB, Swytch uses a write-ahead log with batched fsync, providing:
- 10ms maximum data loss on power failure (vs. seconds for Redis AOF)
- Passthrough semantics - L1 cache over L2 disk, no data duplication
- Fast recovery – Indexed log rebuild, not command replay
swytch redis --persistent --db-path=/data/redis.db --maxmemory=4gb
Ghost mode uses write-back semantics: data is kept in memory and only persisted when evicted or on shutdown. This maximises write performance at the cost of potential data loss on crash.
swytch redis --persistent --ghost --db-path=/data/redis.db
See Tiered Storage for detailed durability guarantees, metrics, and performance characteristics.
TLS/SSL encryption is not currently supported. Use a TLS-terminating proxy (e.g. stunnel, nginx, HAProxy) if encryption is required between clients and Swytch.
Redis Cluster commands are not supported. Swytch is designed for vertical scaling on a single node.
Replication commands (SYNC, PSYNC, REPLCONF, WAIT) are stubbed but non-functional. There is no master/replica
support.
Access Control Lists are not implemented. Use --requirepass for simple password authentication.
Redis modules are not supported.
OBJECT- Object introspection isn’t implementedDEBUG- Most debug subcommands not implementedSLOWLOG- Slow query log not implementedLATENCY- Latency monitoring not implementedCLIENT PAUSE/UNPAUSE- Not implementedCLUSTER *- All cluster commands
Swytch uses a self-tuning frequency-based eviction algorithm instead of Redis’s configurable LRU/LFU policies. This typically results in better hit rates without manual tuning.
Memory usage statistics may differ from Redis due to different internal data structures and Go’s memory allocator.
Lua scripts are supported via the gopher-lua interpreter. Most redis.* API calls work, but the following features are
not available:
- cjson - JSON encoding/decoding (
cjson.encode,cjson.decode) is not implemented - cmsgpack - MessagePack serialization is not implemented
- redis.sha1hex() – SHA1 hashing helper is not implemented
- bit.tohex – Has a known bug with certain edge cases
If you encounter other incompatibilities, please report them at the issue tracker.
All 16 databases (or configured number) share the same memory pool. The SELECT command works as expected.
# Connect with redis-cli
$ redis-cli -p 6379
# Basic operations
127.0.0.1:6379> SET mykey "Hello World"
OK
127.0.0.1:6379> GET mykey
"Hello World"
# With expiration
127.0.0.1:6379> SETEX session:123 3600 "user-data"
OK
127.0.0.1:6379> TTL session:123
(integer) 3600
# Lists
127.0.0.1:6379> RPUSH mylist a b c
(integer) 3
127.0.0.1:6379> LRANGE mylist 0 -1
1) "a"
2) "b"
3) "c"
# Hashes
127.0.0.1:6379> HSET user:1 name "Alice" age 30
(integer) 2
127.0.0.1:6379> HGETALL user:1
1) "name"
2) "Alice"
3) "age"
4) "30"
# Transactions
127.0.0.1:6379> MULTI
OK
127.0.0.1:6379> INCR counter
QUEUED
127.0.0.1:6379> INCR counter
QUEUED
127.0.0.1:6379> EXEC
1) (integer) 1
2) (integer) 2
Enable Prometheus metrics for monitoring:
swytch redis --metrics-port=9090
Scrape metrics from http://localhost:9090/metrics.
Use the standard Redis INFO command for server statistics:
redis-cli INFO
Check the Swytch version:
# CLI version
swytch --version
# Server version (via redis-cli)
redis-cli INFO server | grep redis_version
# Returns: redis_version:8.4.0-swytch
Swytch handles POSIX signals for graceful shutdown:
| Signal | Behavior |
|---|---|
SIGTERM | Graceful shutdown. Completes in-flight requests, flushes pending writes, exits |
SIGINT | Same as SIGTERM (Ctrl+C) |
SIGHUP | Not handled (no config reload) |
For container orchestration (Kubernetes, Docker), send SIGTERM to gracefully stop the server. Swytch will:
- Stop accepting new connections
- Complete in-flight commands
- Flush any pending writes to disk (in persistent mode)
- Exit cleanly
There is no drain period configuration; shutdown completes as fast as pending work allows.
In persistent mode, writes are batched and fsynced every 10 ms by default. This interval is hardcoded for an optimal balance between durability and throughput. The 10 ms guarantee means:
- Best case: Data is durable within 10 ms of acknowledgement
- Worst case (power loss): At most 10 ms of acknowledged writes may be lost
- Process crash: No data loss (OS page cache survives)
For workloads requiring synchronous durability (fsync on every write), consider using Redis in fsync=always configuration.