mirror of
https://github.com/tiny-craft/tiny-rdm.git
synced 2025-10-06 23:52:52 +08:00
Initial commit
This commit is contained in:
38
backend/utils/redis/log_hook.go
Normal file
38
backend/utils/redis/log_hook.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
type LogHook struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func NewHook(name string) LogHook {
|
||||
return LogHook{
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (LogHook) DialHook(next redis.DialHook) redis.DialHook {
|
||||
return func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return next(ctx, network, addr)
|
||||
}
|
||||
}
|
||||
func (LogHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
|
||||
return func(ctx context.Context, cmd redis.Cmder) error {
|
||||
log.Println(cmd.String())
|
||||
return next(ctx, cmd)
|
||||
}
|
||||
}
|
||||
func (LogHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook {
|
||||
return func(ctx context.Context, cmds []redis.Cmder) error {
|
||||
for _, cmd := range cmds {
|
||||
log.Println(cmd.String())
|
||||
}
|
||||
return next(ctx, cmds)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user