All Projects → alicebob → Miniredis

alicebob / Miniredis

Licence: mit
Pure Go Redis server for Go unittests

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Miniredis

Pytruth
Assertion framework for Python unit tests
Stars: ✭ 118 (-93.81%)
Mutual labels:  unittest
Ledokku
Beautiful web UI for all things Dokku
Stars: ✭ 103 (-94.6%)
Mutual labels:  redis
Simpleue
PHP queue worker and consumer - Ready for AWS SQS, Redis, Beanstalkd and others.
Stars: ✭ 124 (-93.5%)
Mutual labels:  redis
Aeraki
Manage any layer 7 traffic in Istio Service Mesh.
Stars: ✭ 119 (-93.76%)
Mutual labels:  redis
Cash
HTTP response caching for Koa. Supports Redis, in-memory store, and more!
Stars: ✭ 122 (-93.6%)
Mutual labels:  redis
X Admin
致力于快速开发中小型后台管理系统项目模板(更新中......)
Stars: ✭ 123 (-93.55%)
Mutual labels:  redis
Live Mutex
High-performance networked mutex for Node.js libraries.
Stars: ✭ 118 (-93.81%)
Mutual labels:  redis
Charroom
PHP + Swoole 聊天室
Stars: ✭ 125 (-93.45%)
Mutual labels:  redis
Ssm Demo
🍌Spring+SpringMVC+Mybatis+easyUI实现简单的后台管理系统
Stars: ✭ 1,639 (-14.05%)
Mutual labels:  redis
Redis Game Transaction
在大型游戏中经常使用分布式,分布式中因为游戏逻辑会经常游戏事务,借助redis特性我们可以实现分布式锁和分布式事务。很多redis集群不支持redis的事务特性。 这个框架用来解决分布式服务器下redis集群事务失效的情况下,基于分布式锁完成分布式事务。支持独占锁,共享锁,读写锁,并且支持事务提交失败情况下的回滚操作,让开发者可以有更多时间侧重游戏逻辑.
Stars: ✭ 124 (-93.5%)
Mutual labels:  redis
Slides
it is a repository to store all slides used by Triton Ho's public presentation and course.
Stars: ✭ 1,782 (-6.55%)
Mutual labels:  redis
Mdserver Mac
mdserver (mac version, secondary development)
Stars: ✭ 121 (-93.65%)
Mutual labels:  redis
Uexam Mysql
学之思在线考试系统,支持多种题型:选择题、多选题、判断题、填空题、解答题以及数学公式,包含PC端、小程序端,扩展性强,部署方便、界面设计友好、代码结构清晰
Stars: ✭ 124 (-93.5%)
Mutual labels:  redis
Ipokemon Server
iPokeMon Server.
Stars: ✭ 119 (-93.76%)
Mutual labels:  redis
Go Chat Api
Chat in Golang with Websockets and Redis
Stars: ✭ 125 (-93.45%)
Mutual labels:  redis
Playground
A new kind of virtual event platform 🐧
Stars: ✭ 120 (-93.71%)
Mutual labels:  redis
Pyproxy Async
基于 Python Asyncio + Redis 实现的代理池
Stars: ✭ 123 (-93.55%)
Mutual labels:  redis
Nest Cnode
CNode 社区 Nest 版本 https://cnodejs.org/
Stars: ✭ 125 (-93.45%)
Mutual labels:  redis
Distributed framework
python通用分布式函数调度框架 pip install function_scheduling_distributed_framework
Stars: ✭ 123 (-93.55%)
Mutual labels:  redis
Apiproject
[https://www.sofineday.com], golang项目开发脚手架,集成最佳实践(gin+gorm+go-redis+mongo+cors+jwt+json日志库zap(支持日志收集到kafka或mongo)+消息队列kafka+微信支付宝支付gopay+api加密+api反向代理+go modules依赖管理+headless爬虫chromedp+makefile+二进制压缩+livereload热加载)
Stars: ✭ 124 (-93.5%)
Mutual labels:  redis

Miniredis

Pure Go Redis test server, used in Go unittests.

Sometimes you want to test code which uses Redis, without making it a full-blown integration test. Miniredis implements (parts of) the Redis server, to be used in unittests. It enables a simple, cheap, in-memory, Redis replacement, with a real TCP interface. Think of it as the Redis version of net/http/httptest.

It saves you from using mock code, and since the redis server lives in the test process you can query for values directly, without going through the server stack.

There are no dependencies on external binaries, so you can easily integrate it in automated build processes.

Be sure to import v2:

import "github.com/alicebob/miniredis/v2"

Commands

Implemented commands:

  • Connection (complete)
    • AUTH -- see RequireAuth()
    • ECHO
    • HELLO -- see RequireUserAuth()
    • PING
    • SELECT
    • SWAPDB
    • QUIT
  • Key
    • DEL
    • EXISTS
    • EXPIRE
    • EXPIREAT
    • KEYS
    • MOVE
    • PERSIST
    • PEXPIRE
    • PEXPIREAT
    • PTTL
    • RENAME
    • RENAMENX
    • RANDOMKEY -- see m.Seed(...)
    • SCAN
    • TOUCH
    • TTL
    • TYPE
    • UNLINK
  • Transactions (complete)
    • DISCARD
    • EXEC
    • MULTI
    • UNWATCH
    • WATCH
  • Server
    • DBSIZE
    • FLUSHALL
    • FLUSHDB
    • TIME -- returns time.Now() or value set by SetTime()
  • String keys (complete)
    • APPEND
    • BITCOUNT
    • BITOP
    • BITPOS
    • DECR
    • DECRBY
    • GET
    • GETBIT
    • GETRANGE
    • GETSET
    • GETDEL
    • INCR
    • INCRBY
    • INCRBYFLOAT
    • MGET
    • MSET
    • MSETNX
    • PSETEX
    • SET
    • SETBIT
    • SETEX
    • SETNX
    • SETRANGE
    • STRLEN
  • Hash keys (complete)
    • HDEL
    • HEXISTS
    • HGET
    • HGETALL
    • HINCRBY
    • HINCRBYFLOAT
    • HKEYS
    • HLEN
    • HMGET
    • HMSET
    • HSET
    • HSETNX
    • HSTRLEN
    • HVALS
    • HSCAN
  • List keys (complete)
    • BLPOP
    • BRPOP
    • BRPOPLPUSH
    • LINDEX
    • LINSERT
    • LLEN
    • LPOP
    • LPUSH
    • LPUSHX
    • LRANGE
    • LREM
    • LSET
    • LTRIM
    • RPOP
    • RPOPLPUSH
    • RPUSH
    • RPUSHX
  • Pub/Sub (complete)
    • PSUBSCRIBE
    • PUBLISH
    • PUBSUB
    • PUNSUBSCRIBE
    • SUBSCRIBE
    • UNSUBSCRIBE
  • Set keys (complete)
    • SADD
    • SCARD
    • SDIFF
    • SDIFFSTORE
    • SINTER
    • SINTERSTORE
    • SISMEMBER
    • SMEMBERS
    • SMOVE
    • SPOP -- see m.Seed(...)
    • SRANDMEMBER -- see m.Seed(...)
    • SREM
    • SUNION
    • SUNIONSTORE
    • SSCAN
  • Sorted Set keys (complete)
    • ZADD
    • ZCARD
    • ZCOUNT
    • ZINCRBY
    • ZINTERSTORE
    • ZLEXCOUNT
    • ZPOPMIN
    • ZPOPMAX
    • ZRANDMEMBER
    • ZRANGE
    • ZRANGEBYLEX
    • ZRANGEBYSCORE
    • ZRANK
    • ZREM
    • ZREMRANGEBYLEX
    • ZREMRANGEBYRANK
    • ZREMRANGEBYSCORE
    • ZREVRANGE
    • ZREVRANGEBYLEX
    • ZREVRANGEBYSCORE
    • ZREVRANK
    • ZSCORE
    • ZUNIONSTORE
    • ZSCAN
  • Stream keys
    • XACK
    • XADD
    • XDEL
    • XGROUP CREATE
    • XINFO STREAM -- partly
    • XLEN
    • XRANGE
    • XREAD
    • XREADGROUP
    • XREVRANGE
    • XPENDING
    • XTRIM
  • Scripting
    • EVAL
    • EVALSHA
    • SCRIPT LOAD
    • SCRIPT EXISTS
    • SCRIPT FLUSH
  • GEO
    • GEOADD
    • GEODIST
    • GEOHASH
    • GEOPOS
    • GEORADIUS
    • GEORADIUS_RO
    • GEORADIUSBYMEMBER
    • GEORADIUSBYMEMBER_RO
  • Server
    • COMMAND -- partly
  • Cluster
    • CLUSTER SLOTS
    • CLUSTER KEYSLOT
    • CLUSTER NODES
  • HyperLogLog (complete)
    • PFADD
    • PFCOUNT
    • PFMERGE

TTLs, key expiration, and time

Since miniredis is intended to be used in unittests TTLs don't decrease automatically. You can use TTL() to get the TTL (as a time.Duration) of a key. It will return 0 when no TTL is set.

m.FastForward(d) can be used to decrement all TTLs. All TTLs which become <= 0 will be removed.

EXPIREAT and PEXPIREAT values will be converted to a duration. For that you can either set m.SetTime(t) to use that time as the base for the (P)EXPIREAT conversion, or don't call SetTime(), in which case time.Now() will be used.

SetTime() also sets the value returned by TIME, which defaults to time.Now(). It is not updated by FastForward, only by SetTime.

Randomness and Seed()

Miniredis will use math/rand's global RNG for randomness unless a seed is provided by calling m.Seed(...). If a seed is provided, then miniredis will use its own RNG based on that seed.

Commands which use randomness are: RANDOMKEY, SPOP, and SRANDMEMBER.

Example

import (
    ...
    "github.com/alicebob/miniredis/v2"
    ...
)

func TestSomething(t *testing.T) {
	s := miniredis.RunT(t)

	// Optionally set some keys your code expects:
	s.Set("foo", "bar")
	s.HSet("some", "other", "key")

	// Run your code and see if it behaves.
	// An example using the redigo library from "github.com/gomodule/redigo/redis":
	c, err := redis.Dial("tcp", s.Addr())
	_, err = c.Do("SET", "foo", "bar")

	// Optionally check values in redis...
	if got, err := s.Get("foo"); err != nil || got != "bar" {
		t.Error("'foo' has the wrong value")
	}
	// ... or use a helper for that:
	s.CheckGet(t, "foo", "bar")

	// TTL and expiration:
	s.Set("foo", "bar")
	s.SetTTL("foo", 10*time.Second)
	s.FastForward(11 * time.Second)
	if s.Exists("foo") {
		t.Fatal("'foo' should not have existed anymore")
	}
}

Not supported

Commands which will probably not be implemented:

  • CLUSTER (all)
    • CLUSTER *
    • READONLY
    • READWRITE
  • Key
    • DUMP
    • MIGRATE
    • OBJECT
    • RESTORE
    • WAIT
  • Scripting
    • SCRIPT DEBUG
    • SCRIPT KILL
  • Server
    • BGSAVE
    • BGWRITEAOF
    • CLIENT *
    • CONFIG *
    • DEBUG *
    • INFO
    • LASTSAVE
    • MONITOR
    • ROLE
    • SAVE
    • SHUTDOWN
    • SLAVEOF
    • SLOWLOG
    • SYNC

&c.

Integration tests are run against Redis 6.2.4. The ./integration subdir compares miniredis against a real redis instance.

The Redis 6 RESP3 protocol is supported. If there are problems, please open an issue.

If you want to test Redis Sentinel have a look at minisentinel.

A changelog is kept at CHANGELOG.md.

Build Status Go Reference

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].