• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

geohash/H24-Jun-2020-341222

integration/H24-Jun-2020-5,4634,597

server/H24-Jun-2020-977825

testdata/H24-Jun-2020-124119

.gitignoreH A D24-Jun-202076 54

.travis.ymlH A D24-Jun-2020151 148

CHANGELOG.mdH A D24-Jun-20201.2 KiB6436

LICENSEH A D24-Jun-20201 KiB2217

MakefileH A D24-Jun-2020129 138

README.mdH A D24-Jun-20206.1 KiB314278

check.goH A D24-Jun-20201.8 KiB6951

cmd_cluster.goH A D24-Jun-20201.6 KiB5945

cmd_cluster_test.goH A D24-Jun-20201.1 KiB6448

cmd_command.goH A D24-Jun-20209.6 KiB2,0502,040

cmd_connection.goH A D24-Jun-20203.3 KiB182149

cmd_connection_test.goH A D24-Jun-20204 KiB194147

cmd_generic.goH A D24-Jun-20209.7 KiB554451

cmd_generic_test.goH A D24-Jun-202015.8 KiB786611

cmd_geo.goH A D24-Jun-202012.1 KiB602529

cmd_geo_test.goH A D24-Jun-202013.7 KiB449367

cmd_hash.goH A D24-Jun-202010.7 KiB617512

cmd_hash_test.goH A D24-Jun-202013.1 KiB617487

cmd_list.goH A D24-Jun-202012.5 KiB728620

cmd_list_test.goH A D24-Jun-202024.6 KiB1,096888

cmd_pubsub.goH A D24-Jun-20204.4 KiB239194

cmd_pubsub_test.goH A D24-Jun-20209.5 KiB406325

cmd_scripting.goH A D24-Jun-20205.5 KiB266221

cmd_scripting_test.goH A D24-Jun-202013.7 KiB658540

cmd_server.goH A D24-Jun-20202 KiB11191

cmd_server_test.goH A D24-Jun-20202.3 KiB12089

cmd_set.goH A D24-Jun-202011.6 KiB680563

cmd_set_test.goH A D24-Jun-202017.4 KiB738577

cmd_sorted_set.goH A D24-Jun-202027.4 KiB1,4661,283

cmd_sorted_set_test.goH A D24-Jun-202039.6 KiB1,5621,262

cmd_stream.goH A D24-Jun-20209.7 KiB499397

cmd_stream_test.goH A D24-Jun-202012.2 KiB421329

cmd_string.goH A D24-Jun-202020.9 KiB1,146977

cmd_string_test.goH A D24-Jun-202028.6 KiB1,2981,030

cmd_transactions.goH A D24-Jun-20203 KiB180142

cmd_transactions_test.goH A D24-Jun-20205 KiB261190

db.goH A D24-Jun-202016.7 KiB806668

direct.goH A D24-Jun-202018.3 KiB746496

example_test.goH A D24-Jun-20201.3 KiB5534

geo.goH A D24-Jun-20201.4 KiB4925

geo_test.goH A D24-Jun-2020372 1814

go.modH A D24-Jun-2020228 107

go.sumH A D24-Jun-20202.1 KiB2322

keys.goH A D24-Jun-20201.7 KiB8467

keys_test.goH A D24-Jun-20202.9 KiB143131

lua.goH A D24-Jun-20204.4 KiB214189

miniredis.goH A D24-Jun-202013.4 KiB581436

miniredis_test.goH A D24-Jun-20205.2 KiB257218

pubsub.goH A D24-Jun-20204.9 KiB241178

redis.goH A D24-Jun-20205.4 KiB221180

sorted_set.goH A D24-Jun-20201.9 KiB9976

sorted_set_test.goH A D24-Jun-20201.5 KiB8770

stream.goH A D24-Jun-20202.9 KiB152118

stream_test.goH A D24-Jun-2020963 3834

test_test.goH A D24-Jun-2020883 4433

README.md

1# Miniredis
2
3Pure Go Redis test server, used in Go unittests.
4
5
6##
7
8Sometimes you want to test code which uses Redis, without making it a full-blown
9integration test.
10Miniredis implements (parts of) the Redis server, to be used in unittests. It
11enables a simple, cheap, in-memory, Redis replacement, with a real TCP interface. Think of it as the Redis version of `net/http/httptest`.
12
13It saves you from using mock code, and since the redis server lives in the
14test process you can query for values directly, without going through the server
15stack.
16
17There are no dependencies on external binaries, so you can easily integrate it in automated build processes.
18
19## Commands
20
21Implemented commands:
22
23 - Connection (complete)
24   - AUTH -- see RequireAuth()
25   - ECHO
26   - PING
27   - SELECT
28   - SWAPDB
29   - QUIT
30 - Key
31   - DEL
32   - EXISTS
33   - EXPIRE
34   - EXPIREAT
35   - KEYS
36   - MOVE
37   - PERSIST
38   - PEXPIRE
39   - PEXPIREAT
40   - PTTL
41   - RENAME
42   - RENAMENX
43   - RANDOMKEY -- see m.Seed(...)
44   - SCAN
45   - TOUCH
46   - TTL
47   - TYPE
48   - UNLINK
49 - Transactions (complete)
50   - DISCARD
51   - EXEC
52   - MULTI
53   - UNWATCH
54   - WATCH
55 - Server
56   - DBSIZE
57   - FLUSHALL
58   - FLUSHDB
59   - TIME -- returns time.Now() or value set by SetTime()
60 - String keys (complete)
61   - APPEND
62   - BITCOUNT
63   - BITOP
64   - BITPOS
65   - DECR
66   - DECRBY
67   - GET
68   - GETBIT
69   - GETRANGE
70   - GETSET
71   - INCR
72   - INCRBY
73   - INCRBYFLOAT
74   - MGET
75   - MSET
76   - MSETNX
77   - PSETEX
78   - SET
79   - SETBIT
80   - SETEX
81   - SETNX
82   - SETRANGE
83   - STRLEN
84 - Hash keys (complete)
85   - HDEL
86   - HEXISTS
87   - HGET
88   - HGETALL
89   - HINCRBY
90   - HINCRBYFLOAT
91   - HKEYS
92   - HLEN
93   - HMGET
94   - HMSET
95   - HSET
96   - HSETNX
97   - HVALS
98   - HSCAN
99 - List keys (complete)
100   - BLPOP
101   - BRPOP
102   - BRPOPLPUSH
103   - LINDEX
104   - LINSERT
105   - LLEN
106   - LPOP
107   - LPUSH
108   - LPUSHX
109   - LRANGE
110   - LREM
111   - LSET
112   - LTRIM
113   - RPOP
114   - RPOPLPUSH
115   - RPUSH
116   - RPUSHX
117 - Pub/Sub (complete)
118   - PSUBSCRIBE
119   - PUBLISH
120   - PUBSUB
121   - PUNSUBSCRIBE
122   - SUBSCRIBE
123   - UNSUBSCRIBE
124 - Set keys (complete)
125   - SADD
126   - SCARD
127   - SDIFF
128   - SDIFFSTORE
129   - SINTER
130   - SINTERSTORE
131   - SISMEMBER
132   - SMEMBERS
133   - SMOVE
134   - SPOP -- see m.Seed(...)
135   - SRANDMEMBER -- see m.Seed(...)
136   - SREM
137   - SUNION
138   - SUNIONSTORE
139   - SSCAN
140 - Sorted Set keys (complete)
141   - ZADD
142   - ZCARD
143   - ZCOUNT
144   - ZINCRBY
145   - ZINTERSTORE
146   - ZLEXCOUNT
147   - ZPOPMIN
148   - ZPOPMAX
149   - ZRANGE
150   - ZRANGEBYLEX
151   - ZRANGEBYSCORE
152   - ZRANK
153   - ZREM
154   - ZREMRANGEBYLEX
155   - ZREMRANGEBYRANK
156   - ZREMRANGEBYSCORE
157   - ZREVRANGE
158   - ZREVRANGEBYLEX
159   - ZREVRANGEBYSCORE
160   - ZREVRANK
161   - ZSCORE
162   - ZUNIONSTORE
163   - ZSCAN
164 - Stream keys
165   - XACK
166   - XADD
167   - XDEL
168   - XGROUP CREATE
169   - XINFO STREAM -- partly
170   - XLEN
171   - XRANGE
172   - XREADGROUP -- partly
173   - XREVRANGE
174 - Scripting
175   - EVAL
176   - EVALSHA
177   - SCRIPT LOAD
178   - SCRIPT EXISTS
179   - SCRIPT FLUSH
180 - GEO
181   - GEOADD
182   - GEODIST
183   - ~~GEOHASH~~
184   - GEOPOS
185   - GEORADIUS
186   - GEORADIUS_RO
187   - GEORADIUSBYMEMBER
188   - GEORADIUSBYMEMBER_RO
189 - Server
190   - COMMAND -- partly
191 - Cluster
192   - CLUSTER SLOTS
193   - CLUSTER KEYSLOT
194   - CLUSTER NODES
195
196
197## TTLs, key expiration, and time
198
199Since miniredis is intended to be used in unittests TTLs don't decrease
200automatically. You can use `TTL()` to get the TTL (as a time.Duration) of a
201key. It will return 0 when no TTL is set.
202
203`m.FastForward(d)` can be used to decrement all TTLs. All TTLs which become <=
2040 will be removed.
205
206EXPIREAT and PEXPIREAT values will be
207converted to a duration. For that you can either set m.SetTime(t) to use that
208time as the base for the (P)EXPIREAT conversion, or don't call SetTime(), in
209which case time.Now() will be used.
210
211SetTime() also sets the value returned by TIME, which defaults to time.Now().
212It is not updated by FastForward, only by SetTime.
213
214## Randomness and Seed()
215
216Miniredis will use `math/rand`'s global RNG for randomness unless a seed is
217provided by calling `m.Seed(...)`. If a seed is provided, then miniredis will
218use its own RNG based on that seed.
219
220Commands which use randomness are: RANDOMKEY, SPOP, and SRANDMEMBER.
221
222## Example
223
224``` Go
225
226import (
227    ...
228    "github.com/alicebob/miniredis/v2"
229    ...
230)
231
232func TestSomething(t *testing.T) {
233	s, err := miniredis.Run()
234	if err != nil {
235		panic(err)
236	}
237	defer s.Close()
238
239	// Optionally set some keys your code expects:
240	s.Set("foo", "bar")
241	s.HSet("some", "other", "key")
242
243	// Run your code and see if it behaves.
244	// An example using the redigo library from "github.com/gomodule/redigo/redis":
245	c, err := redis.Dial("tcp", s.Addr())
246	_, err = c.Do("SET", "foo", "bar")
247
248	// Optionally check values in redis...
249	if got, err := s.Get("foo"); err != nil || got != "bar" {
250		t.Error("'foo' has the wrong value")
251	}
252	// ... or use a helper for that:
253	s.CheckGet(t, "foo", "bar")
254
255	// TTL and expiration:
256	s.Set("foo", "bar")
257	s.SetTTL("foo", 10*time.Second)
258	s.FastForward(11 * time.Second)
259	if s.Exists("foo") {
260		t.Fatal("'foo' should not have existed anymore")
261	}
262}
263```
264
265## Not supported
266
267Commands which will probably not be implemented:
268
269 - CLUSTER (all)
270    - ~~CLUSTER *~~
271    - ~~READONLY~~
272    - ~~READWRITE~~
273 - HyperLogLog (all) -- unless someone needs these
274    - ~~PFADD~~
275    - ~~PFCOUNT~~
276    - ~~PFMERGE~~
277 - Key
278    - ~~DUMP~~
279    - ~~MIGRATE~~
280    - ~~OBJECT~~
281    - ~~RESTORE~~
282    - ~~WAIT~~
283 - Scripting
284    - ~~SCRIPT DEBUG~~
285    - ~~SCRIPT KILL~~
286 - Server
287    - ~~BGSAVE~~
288    - ~~BGWRITEAOF~~
289    - ~~CLIENT *~~
290    - ~~CONFIG *~~
291    - ~~DEBUG *~~
292    - ~~INFO~~
293    - ~~LASTSAVE~~
294    - ~~MONITOR~~
295    - ~~ROLE~~
296    - ~~SAVE~~
297    - ~~SHUTDOWN~~
298    - ~~SLAVEOF~~
299    - ~~SLOWLOG~~
300    - ~~SYNC~~
301
302
303## &c.
304
305Tests are run against Redis 6.0.5. The [./integration](./integration/) subdir
306compares miniredis against a real redis instance.
307
308If you want to test Redis Sentinel have a look at [minisentinel](https://github.com/Bose/minisentinel).
309
310A changelog is kept at [CHANGELOG.md](https://github.com/alicebob/miniredis/blob/master/CHANGELOG.md).
311
312[![Build Status](https://travis-ci.org/alicebob/miniredis.svg?branch=master)](https://travis-ci.org/alicebob/miniredis)
313[![GoDoc](https://godoc.org/github.com/alicebob/miniredis?status.svg)](https://godoc.org/github.com/alicebob/miniredis)
314