在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:alicebob/miniredis开源软件地址:https://github.com/alicebob/miniredis开源编程语言:Go 99.8%开源软件介绍:MiniredisPure 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 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:
CommandsImplemented commands:
TTLs, key expiration, and timeSince miniredis is intended to be used in unittests TTLs don't decrease
automatically. You can use
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 Commands which use randomness are: RANDOMKEY, SPOP, and SRANDMEMBER. Exampleimport (
...
"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 supportedCommands which will probably not be implemented:
&c.Integration tests are run against Redis 6.2.6. 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. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论