https://github.com/mjc-gh/redis-test-hook
Capture commands set to go-redis for testing purposes
https://github.com/mjc-gh/redis-test-hook
golang redis redis-client
Last synced: 7 months ago
JSON representation
Capture commands set to go-redis for testing purposes
- Host: GitHub
- URL: https://github.com/mjc-gh/redis-test-hook
- Owner: mjc-gh
- License: mit
- Created: 2024-03-04T01:02:29.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-09T22:55:57.000Z (over 1 year ago)
- Last Synced: 2025-03-15T08:33:34.707Z (7 months ago)
- Topics: golang, redis, redis-client
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Go Redis Test Hooks
[](https://github.com/mjc-gh/go-redis-test-hook/actions/workflows/tests.yaml)
[](https://pkg.go.dev/github.com/mjc-gh/go-redis-test-hook)Capture commands set to Redis for testing purposes with a
[hook](https://pkg.go.dev/github.com/go-redis/redis/v9#Client.AddHook).```go
func TestDoesSomethingWithRedis(t *testing.T) {
// Setup
hook := redistesthooks.New()rdb := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
rdb.AddHook(hook)// Do stuff with redis
rdb.Set(ctx, "key", 42, time.Duration(0))
rdb.Get(ctx, "key")// Write assertions against captures
assert.Equal(t, "SET key 42", hook.Captures[0].String())
assert.Equal(t, "GET key", hook.Captures[1].String())// Clear captures
hook.Reset()
}
```