A Redis-compatible server built from scratch in Go. The server is compatible with standard Redis clients including redis-cli, making it a drop-in replacement for development and learning purposes.
This project was inspired by ideas from the memkv project.
- High-Performance I/O Multiplexing: Single-threaded, non-blocking TCP server using platform-native mechanisms: kqueue on macOS and epoll on Linux. Handles thousands of concurrent connections efficiently without threading overhead.
- RESP Compliant: Full implementation of Redis Serialization Protocol (RESP), ensuring compatibility with all standard Redis clients including
redis-cli. - Core Data Structures: Strings, Lists, Sets, Hashes, Sorted Sets, and Geo indexes with extensive command support.
- Probabilistic Data Structures:
- Bloom Filter: Space-efficient membership testing with configurable false positive rate
- Cuckoo Filter: Membership testing with deletion support and better space efficiency
- HyperLogLog: Cardinality estimation using minimal memory (~12KB for billions of elements)
- Count-Min Sketch: Frequency estimation for streaming data
- Key Expiration: Supports TTL-based key expiration with two strategies:
- Passive expiration: Keys are checked and removed when accessed
- Active expiration: A CPU-bounded (1ms) background cycle runs periodically (every 100ms) to sample and remove expired keys
- Eviction Policies: Memory management with configurable eviction policies:
noeviction: Return errors when memory limit is reachedallkeys-lru: Evict least recently used keysallkeys-lfu: Evict least frequently used keysallkeys-random: Evict random keysvolatile-lru: Evict least recently used keys with TTLvolatile-lfu: Evict least frequently used keys with TTLvolatile-ttl: Evict keys with shortest TTLvolatile-random: Evict random keys with TTL
# Pull the image
docker pull manhhung2111/go-redis:1.0.0
# Run the server
docker run -d --name go-redis -p 6379:6379 manhhung2111/go-redis:1.0.0
# Interact with the server using redis-cli
docker exec -it go-redis redis-cli- Go 1.25 or later
# Clone the repository
git clone https://github.com/manhhung2111/go-redis.git
cd go-redis
# Build
go build -o go-redis ./cmd
# Run
./go-redis
# Run redis-cli
redis-cli -h 0.0.0.0 -p 6379PING [message]DEL key [key ...]TTL keyEXPIRE key seconds [NX | XX | GT | LT]
SET key value [NX | XX] [EX seconds]GET keyINCR keyINCRBY key incrementDECR keyDECRBY key decrementMGET key [key ...]MSET key value [key value ...]
LPUSH key element [element ...]LPUSHX key element [element ...]LPOP key [count]RPUSH key element [element ...]RPUSHX key element [element ...]RPOP key [count]LRANGE key start stopLINDEX key indexLLEN keyLREM key count elementLSET key index elementLTRIM key start stop
SADD key member [member ...]SCARD keySISMEMBER key memberSMEMBERS keySMISMEMBER key member [member ...]SREM key member [member ...]SPOP key [count]SRANDMEMBER key [count]
HSET key field value [field value ...]HSETNX key field valueHGET key fieldHGETALL keyHMGET key field [field ...]HINCRBY key field incrementHKEYS keyHVALS keyHLEN keyHDEL key field [field ...]HEXISTS key field
ZADD key [NX | XX] [GT | LT] [CH] score member [score member ...]ZCARD keyZCOUNT key min maxZINCRBY key increment memberZLEXCOUNT key min maxZMSCORE key member [member ...]ZPOPMAX key [count]ZPOPMIN key [count]ZRANDMEMBER key [count [WITHSCORES]]ZRANGE key start stop [BYSCORE | BYLEX] [REV] [WITHSCORES]ZRANK key member [WITHSCORE]ZREM key member [member ...]ZREVRANK key member [WITHSCORE]ZSCORE key member
GEOADD key [NX | XX] [CH] longitude latitude member [longitude latitude member ...]GEODIST key member1 member2 [M | KM | FT | MI]GEOHASH key member [member ...]GEOPOS key member [member ...]GEOSEARCH key [FROMMEMBER member | FROMLONLAT longitude latitude] [BYRADIUS radius M | KM | FT | MI | BYBOX width height M | KM | FT | MI] [ASC | DESC] [COUNT count [ANY]] [WITHCOORD] [WITHDIST] [WITHHASH]
BF.ADD key itemBF.CARD keyBF.EXISTS key itemBF.INFO key [CAPACITY | SIZE | FILTERS | ITEMS | EXPANSION]BF.MADD key item [item ...]BF.MEXISTS key item [item ...]BF.RESERVE key error_rate capacity [EXPANSION expansion]
CF.ADD key itemCF.ADDNX key itemCF.COUNT key itemCF.DEL key itemCF.EXISTS key itemCF.INFO keyCF.MEXISTS key item [item ...]CF.RESERVE key capacity [BUCKETSIZE bucketsize] [MAXITERATIONS maxiterations] [EXPANSION expansion]
PFADD key [element [element ...]]PFCOUNT key [key ...]PFMERGE destkey [sourcekey [sourcekey ...]]
CMS.INCRBY key item increment [item increment ...]CMS.INFO keyCMS.INITBYDIM key width depthCMS.INITBYPROB key error probabilityCMS.QUERY key item [item ...]