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/redis

Quick 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") // 0

Features

  • Store — a thread-safe, single-mutex keyspace built with New or NewWithClock, plus generic Del, Exists, Keys (glob), TypeOf, DBSize and FlushAll
  • Strings — Set (with EX/PX/NX/XX SetOptions), Get, GetSet, Append, Strlen and Incr/Decr/IncrBy/DecrBy
  • Lists — LPush, RPush, LPop, RPop, LRange, LLen and LIndex
  • Hashes — HSet, HGet, HDel, HGetAll, HKeys, HVals, HLen and HExists
  • Sets — SAdd, SRem, SMembers, SIsMember, SCard plus SInter, SUnion and SDiff
  • Sorted sets — ZAdd, ZScore, ZRange, ZRevRange, ZRangeByScore, ZRank and ZRevRank, backed by a skiplist ordered by (score, member) for O(log n) rank queries
  • Lazy, deterministic expiry — Expire/PExpire/TTL/PTTL/Persist with an injectable Clock and a testable ManualClock
  • Dynamic dispatch — Store.Do runs a command by name and returns RESP-friendly Go values (SimpleString, int64, string, nil or []any)
  • RESP2 codec — Encoder and Decoder (NewEncoder/NewDecoder) implement the RESP wire format, and an optional Server (NewServer/ListenAndServe) speaks it to real Redis clients over TCP
  • Zero dependencies — pure Go standard library, no cgo, nothing to audit but the toolchain
Redis