feat/redis_hook (#4233)

This commit is contained in:
MarkJoyMa 2024-07-07 12:50:30 +08:00 committed by GitHub
parent c9cbd74bf3
commit fed835bc25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View File

@ -90,6 +90,18 @@ type (
StringCmd = red.StringCmd StringCmd = red.StringCmd
// Script is an alias of redis.Script. // Script is an alias of redis.Script.
Script = red.Script Script = red.Script
// Hook is an alias of redis.Hook.
Hook = red.Hook
// DialHook is an alias of redis.DialHook.
DialHook = red.DialHook
// ProcessHook is an alias of redis.ProcessHook.
ProcessHook = red.ProcessHook
// ProcessPipelineHook is an alias of redis.ProcessPipelineHook.
ProcessPipelineHook = red.ProcessPipelineHook
// Cmder is an alias of redis.Cmder.
Cmder = red.Cmder
) )
// MustNewRedis returns a Redis with given options. // MustNewRedis returns a Redis with given options.
@ -2363,9 +2375,9 @@ func WithTLS() Option {
} }
} }
// withHook customizes the given Redis with given durationHook, only for private use now, // WithHook customizes the given Redis with given durationHook, only for private use now,
// maybe expose later. // maybe expose later.
func withHook(hook red.Hook) Option { func WithHook(hook Hook) Option {
return func(r *Redis) { return func(r *Redis) {
r.hooks = append(r.hooks, hook) r.hooks = append(r.hooks, hook)
} }

View File

@ -160,7 +160,7 @@ func TestRedis_NonBlock(t *testing.T) {
Host: s.Addr(), Host: s.Addr(),
NonBlock: true, NonBlock: true,
Type: NodeType, Type: NodeType,
}, withHook(myHook{includePing: true})) }, WithHook(myHook{includePing: true}))
assert.NoError(t, err) assert.NoError(t, err)
}) })
@ -170,7 +170,7 @@ func TestRedis_NonBlock(t *testing.T) {
Host: s.Addr(), Host: s.Addr(),
NonBlock: false, NonBlock: false,
Type: NodeType, Type: NodeType,
}, withHook(myHook{includePing: true})) }, WithHook(myHook{includePing: true}))
assert.ErrorContains(t, err, "redis connect error") assert.ErrorContains(t, err, "redis connect error")
}) })
} }