|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | 03-May-2022 | - |
| geohash/ | H | 24-Jun-2020 | - | 341 | 222 |
| integration/ | H | 24-Jun-2020 | - | 5,463 | 4,597 |
| server/ | H | 24-Jun-2020 | - | 977 | 825 |
| testdata/ | H | 24-Jun-2020 | - | 124 | 119 |
| .gitignore | H A D | 24-Jun-2020 | 76 | 5 | 4 |
| .travis.yml | H A D | 24-Jun-2020 | 151 | 14 | 8 |
| CHANGELOG.md | H A D | 24-Jun-2020 | 1.2 KiB | 64 | 36 |
| LICENSE | H A D | 24-Jun-2020 | 1 KiB | 22 | 17 |
| Makefile | H A D | 24-Jun-2020 | 129 | 13 | 8 |
| README.md | H A D | 24-Jun-2020 | 6.1 KiB | 314 | 278 |
| check.go | H A D | 24-Jun-2020 | 1.8 KiB | 69 | 51 |
| cmd_cluster.go | H A D | 24-Jun-2020 | 1.6 KiB | 59 | 45 |
| cmd_cluster_test.go | H A D | 24-Jun-2020 | 1.1 KiB | 64 | 48 |
| cmd_command.go | H A D | 24-Jun-2020 | 9.6 KiB | 2,050 | 2,040 |
| cmd_connection.go | H A D | 24-Jun-2020 | 3.3 KiB | 182 | 149 |
| cmd_connection_test.go | H A D | 24-Jun-2020 | 4 KiB | 194 | 147 |
| cmd_generic.go | H A D | 24-Jun-2020 | 9.7 KiB | 554 | 451 |
| cmd_generic_test.go | H A D | 24-Jun-2020 | 15.8 KiB | 786 | 611 |
| cmd_geo.go | H A D | 24-Jun-2020 | 12.1 KiB | 602 | 529 |
| cmd_geo_test.go | H A D | 24-Jun-2020 | 13.7 KiB | 449 | 367 |
| cmd_hash.go | H A D | 24-Jun-2020 | 10.7 KiB | 617 | 512 |
| cmd_hash_test.go | H A D | 24-Jun-2020 | 13.1 KiB | 617 | 487 |
| cmd_list.go | H A D | 24-Jun-2020 | 12.5 KiB | 728 | 620 |
| cmd_list_test.go | H A D | 24-Jun-2020 | 24.6 KiB | 1,096 | 888 |
| cmd_pubsub.go | H A D | 24-Jun-2020 | 4.4 KiB | 239 | 194 |
| cmd_pubsub_test.go | H A D | 24-Jun-2020 | 9.5 KiB | 406 | 325 |
| cmd_scripting.go | H A D | 24-Jun-2020 | 5.5 KiB | 266 | 221 |
| cmd_scripting_test.go | H A D | 24-Jun-2020 | 13.7 KiB | 658 | 540 |
| cmd_server.go | H A D | 24-Jun-2020 | 2 KiB | 111 | 91 |
| cmd_server_test.go | H A D | 24-Jun-2020 | 2.3 KiB | 120 | 89 |
| cmd_set.go | H A D | 24-Jun-2020 | 11.6 KiB | 680 | 563 |
| cmd_set_test.go | H A D | 24-Jun-2020 | 17.4 KiB | 738 | 577 |
| cmd_sorted_set.go | H A D | 24-Jun-2020 | 27.4 KiB | 1,466 | 1,283 |
| cmd_sorted_set_test.go | H A D | 24-Jun-2020 | 39.6 KiB | 1,562 | 1,262 |
| cmd_stream.go | H A D | 24-Jun-2020 | 9.7 KiB | 499 | 397 |
| cmd_stream_test.go | H A D | 24-Jun-2020 | 12.2 KiB | 421 | 329 |
| cmd_string.go | H A D | 24-Jun-2020 | 20.9 KiB | 1,146 | 977 |
| cmd_string_test.go | H A D | 24-Jun-2020 | 28.6 KiB | 1,298 | 1,030 |
| cmd_transactions.go | H A D | 24-Jun-2020 | 3 KiB | 180 | 142 |
| cmd_transactions_test.go | H A D | 24-Jun-2020 | 5 KiB | 261 | 190 |
| db.go | H A D | 24-Jun-2020 | 16.7 KiB | 806 | 668 |
| direct.go | H A D | 24-Jun-2020 | 18.3 KiB | 746 | 496 |
| example_test.go | H A D | 24-Jun-2020 | 1.3 KiB | 55 | 34 |
| geo.go | H A D | 24-Jun-2020 | 1.4 KiB | 49 | 25 |
| geo_test.go | H A D | 24-Jun-2020 | 372 | 18 | 14 |
| go.mod | H A D | 24-Jun-2020 | 228 | 10 | 7 |
| go.sum | H A D | 24-Jun-2020 | 2.1 KiB | 23 | 22 |
| keys.go | H A D | 24-Jun-2020 | 1.7 KiB | 84 | 67 |
| keys_test.go | H A D | 24-Jun-2020 | 2.9 KiB | 143 | 131 |
| lua.go | H A D | 24-Jun-2020 | 4.4 KiB | 214 | 189 |
| miniredis.go | H A D | 24-Jun-2020 | 13.4 KiB | 581 | 436 |
| miniredis_test.go | H A D | 24-Jun-2020 | 5.2 KiB | 257 | 218 |
| pubsub.go | H A D | 24-Jun-2020 | 4.9 KiB | 241 | 178 |
| redis.go | H A D | 24-Jun-2020 | 5.4 KiB | 221 | 180 |
| sorted_set.go | H A D | 24-Jun-2020 | 1.9 KiB | 99 | 76 |
| sorted_set_test.go | H A D | 24-Jun-2020 | 1.5 KiB | 87 | 70 |
| stream.go | H A D | 24-Jun-2020 | 2.9 KiB | 152 | 118 |
| stream_test.go | H A D | 24-Jun-2020 | 963 | 38 | 34 |
| test_test.go | H A D | 24-Jun-2020 | 883 | 44 | 33 |
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