Redis for Go
github.com/malcolmston/redis
An embeddable, Redis-style in-memory data store in pure Go.
GitHubports redis/redis
A thread-safe, Redis-style keyspace built entirely on the Go standard library — no cgo and no third-party dependencies. A single-mutex Store holds the core Redis data types (strings, lists, hashes, sets and skiplist-backed sorted sets), exposed both as typed Go methods and through a dynamic Do(...) dispatcher that mirrors sending a RESP command array. Expiration is lazy and driven by an injectable Clock so TTL behaviour is fully deterministic in tests, and a RESP2 codec plus an optional TCP Server let real Redis clients speak to the same store over the wire.
Install
shell
$ go get github.com/malcolmston/redisQuick start
main.go
import "github.com/malcolmston/redis"
s := redis.New()
s.Set("name", "alice", redis.SetOptions{})
name, _, _ := s.Get("name") // "alice"
s.RPush("tasks", "a", "b", "c")
items, _ := s.LRange("tasks", 0, -1) // [a b c]
s.ZAdd("board", redis.ZMember{Member: "bob", Score: 25})
rank, _, _ := s.ZRevRank("board", "bob") // 0Features
Store— a thread-safe, single-mutex keyspace built withNeworNewWithClock, plus genericDel,Exists,Keys(glob),TypeOf,DBSizeandFlushAll- Strings —
Set(with EX/PX/NX/XXSetOptions),Get,GetSet,Append,StrlenandIncr/Decr/IncrBy/DecrBy - Lists —
LPush,RPush,LPop,RPop,LRange,LLenandLIndex - Hashes —
HSet,HGet,HDel,HGetAll,HKeys,HVals,HLenandHExists - Sets —
SAdd,SRem,SMembers,SIsMember,SCardplusSInter,SUnionandSDiff - Sorted sets —
ZAdd,ZScore,ZRange,ZRevRange,ZRangeByScore,ZRankandZRevRank, backed by askiplistordered by (score, member) for O(log n) rank queries - Lazy, deterministic expiry —
Expire/PExpire/TTL/PTTL/Persistwith an injectableClockand a testableManualClock - Dynamic dispatch —
Store.Doruns a command by name and returns RESP-friendly Go values (SimpleString,int64,string,nilor[]any) - RESP2 codec —
EncoderandDecoder(NewEncoder/NewDecoder) implement the RESP wire format, and an optionalServer(NewServer/ListenAndServe) speaks it to real Redis clients over TCP - Zero dependencies — pure Go standard library, no cgo, nothing to audit but the toolchain