Skip to main content
Swytch Documentation
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

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.

Quick Start

# 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

Supported Commands

Swytch implements a comprehensive set of Redis commands across all major data types.

Strings

CommandDescription
GET, SET, SETNX, SETEX, PSETEXBasic get/set operations
MGET, MSET, MSETNXMulti-key operations
GETEX, GETDEL, GETSETGet with side effects
INCR, DECR, INCRBY, DECRBY, INCRBYFLOATAtomic counters
APPEND, STRLENString manipulation
GETRANGE, SETRANGESubstring operations
LCSLongest common subsequence

Keys

CommandDescription
DEL, EXISTS, TYPEKey inspection and deletion
EXPIRE, EXPIREAT, PEXPIRE, PEXPIREATSet expiration
TTL, PTTL, EXPIRETIME, PEXPIRETIMEGet expiration
PERSISTRemove expiration
RENAME, RENAMENXRename keys
COPY, MOVECopy/move between databases
KEYS, SCAN, RANDOMKEYKey enumeration
SORT, SORT_ROSort list/set/zset contents

Bitmaps

CommandDescription
SETBIT, GETBITIndividual bit operations
BITCOUNTCount set bits
BITPOSFind first set/clear bit
BITOPBitwise AND, OR, XOR, NOT
BITFIELD, BITFIELD_ROArbitrary bit field operations

Lists

CommandDescription
LPUSH, RPUSH, LPUSHX, RPUSHXAdd elements
LPOP, RPOPRemove and return elements
BLPOP, BRPOPBlocking pop
LMPOP, BLMPOPPop from multiple lists
LMOVE, BLMOVEAtomically move elements
RPOPLPUSH, BRPOPLPUSHPop and push (deprecated)
LLEN, LRANGE, LINDEXInspection
LSET, LINSERT, LPOSModification
LREM, LTRIMRemoval

Hashes

CommandDescription
HGET, HSET, HSETNX, HMGET, HMSETGet/set fields
HDEL, HEXISTSDelete and check fields
HGETALL, HKEYS, HVALS, HLENEnumerate hash
HINCRBY, HINCRBYFLOATAtomic field increment
HSTRLEN, HRANDFIELDField utilities
HSCANIncremental iteration
HEXPIRE, HPEXPIRE, HTTL, HPTTLPer-field expiration
HGETDEL, HSETEX, HGETEXExtended operations

Sets

CommandDescription
SADD, SREM, SPOPAdd/remove members
SCARD, SISMEMBER, SMISMEMBERMembership tests
SMEMBERS, SRANDMEMBERRetrieve members
SINTER, SINTERSTORE, SINTERCARDIntersection
SUNION, SUNIONSTOREUnion
SDIFF, SDIFFSTOREDifference
SMOVEMove between sets

Sorted Sets

CommandDescription
ZADD, ZREM, ZINCRBYAdd/remove/increment
ZSCORE, ZMSCORE, ZCARDScore lookup
ZRANK, ZREVRANKRank lookup
ZRANGE, ZREVRANGERange by rank
ZRANGEBYSCORE, ZREVRANGEBYSCORERange by score
ZRANGEBYLEX, ZREVRANGEBYLEXRange by lex
ZCOUNT, ZLEXCOUNTCount in range
ZPOPMIN, ZPOPMAX, BZPOPMIN, BZPOPMAXPop min/max
ZMPOP, BZMPOPPop from multiple zsets
ZREMRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYLEXRemove ranges
ZUNION, ZINTER, ZDIFFSet operations
ZUNIONSTORE, ZINTERSTORE, ZDIFFSTOREStore set operations
ZINTERCARDIntersection cardinality
ZRANGESTORE, ZRANDMEMBERUtilities

Streams

CommandDescription
XADD, XLEN, XDEL, XTRIMBasic stream operations
XRANGE, XREVRANGE, XREADRead entries
XGROUPConsumer group management
XREADGROUPRead as consumer group
XACK, XPENDINGAcknowledgment
XCLAIM, XAUTOCLAIMClaim pending entries
XINFO, XSETIDStream information

HyperLogLog

CommandDescription
PFADDAdd elements
PFCOUNTEstimate cardinality
PFMERGEMerge HyperLogLogs

Geospatial

CommandDescription
GEOADDAdd locations
GEODISTDistance between points
GEOHASH, GEOPOSGet hash/coordinates
GEORADIUS, GEORADIUSBYMEMBERSearch by radius (deprecated)
GEOSEARCH, GEOSEARCHSTORESearch locations

Pub/Sub

CommandDescription
SUBSCRIBE, UNSUBSCRIBEChannel subscription
PSUBSCRIBE, PUNSUBSCRIBEPattern subscription
PUBLISHPublish message
PUBSUBIntrospection

Transactions

CommandDescription
MULTIStart transaction
EXECExecute transaction
DISCARDAbort transaction
WATCH, UNWATCHOptimistic locking

Scripting

CommandDescription
EVAL, EVALSHAExecute Lua scripts
EVAL_RO, EVALSHA_RORead-only script execution
SCRIPTScript management
FUNCTION, FCALL, FCALL_ROFunction library support

Server

CommandDescription
PING, ECHOConnection test
AUTH, HELLOAuthentication
SELECT, SWAPDBDatabase selection
INFO, DBSIZE, TIMEServer information
FLUSHDB, FLUSHALLClear databases
CONFIG, CLIENT, MEMORYServer management
COMMANDCommand introspection
SHUTDOWNStop server

Command-Line Options

Standard Redis Options

OptionDefaultDescription
--port6379TCP port to listen on
--bind127.0.0.1Bind address
--unixsocket-Unix socket path
--unixsocketperm0700Unix socket permissions
--databases16Number of databases
--maxmemory64mbMemory limit (e.g., 256mb, 4gb). Default is suitable for testing
--requirepass-Password for AUTH
--maxclients0Max connections (0 = unlimited)
--timeout0Client idle timeout in seconds
--threads0Sets 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.

Swytch Extensions

OptionDefaultDescription
--persistentfalseEnable persistent tiered storage
--db-pathredis.dbPath to persistent storage file
--defragmentfalseDefragment log file on startup
--ghostfalseGhost mode: write-back instead of write-through
--pprof-Enable pprof on this port
--metrics-port-Enable Prometheus metrics on this port
-vfalseVerbose output
--debugfalseLog all commands processed

Persistence Modes

Swytch offers two persistence modes that go far beyond traditional Redis persistence. See Tiered Storage for the complete guide.

In-Memory Mode (Default)

By default, Swytch runs as a pure in-memory cache. Data is lost on restart but performance is maximised.

swytch redis --maxmemory=4gb

Persistent Mode (Tiered Storage)

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 (Write-Back)

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.

Unsupported Features

TLS

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.

Cluster Mode

Redis Cluster commands are not supported. Swytch is designed for vertical scaling on a single node.

Replication

Replication commands (SYNC, PSYNC, REPLCONF, WAIT) are stubbed but non-functional. There is no master/replica support.

ACL

Access Control Lists are not implemented. Use --requirepass for simple password authentication.

Modules

Redis modules are not supported.

Specific Commands

  • OBJECT - Object introspection isn’t implemented
  • DEBUG - Most debug subcommands not implemented
  • SLOWLOG - Slow query log not implemented
  • LATENCY - Latency monitoring not implemented
  • CLIENT PAUSE/UNPAUSE - Not implemented
  • CLUSTER * - All cluster commands

Differences from Redis

Eviction Policy

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 Reporting

Memory usage statistics may differ from Redis due to different internal data structures and Go’s memory allocator.

Lua Scripting

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.

Multi-Database

All 16 databases (or configured number) share the same memory pool. The SELECT command works as expected.

Example Usage

# 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

Monitoring

Prometheus Metrics

Enable Prometheus metrics for monitoring:

swytch redis --metrics-port=9090

Scrape metrics from http://localhost:9090/metrics.

INFO Command

Use the standard Redis INFO command for server statistics:

redis-cli INFO

Version

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

Operations

Signal Handling

Swytch handles POSIX signals for graceful shutdown:

SignalBehavior
SIGTERMGraceful shutdown. Completes in-flight requests, flushes pending writes, exits
SIGINTSame as SIGTERM (Ctrl+C)
SIGHUPNot handled (no config reload)

For container orchestration (Kubernetes, Docker), send SIGTERM to gracefully stop the server. Swytch will:

  1. Stop accepting new connections
  2. Complete in-flight commands
  3. Flush any pending writes to disk (in persistent mode)
  4. Exit cleanly

There is no drain period configuration; shutdown completes as fast as pending work allows.

Durability Tuning

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.