-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis_test.go
53 lines (49 loc) · 1.12 KB
/
redis_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @Author: feymanlee@gmail.com
* @Description:
* @File: redis_test
* @Date: 2023/4/10 13:42
*/
package logit
import (
"context"
"testing"
"time"
"github.com/go-redis/redis/v8"
)
func TestRedisLogger(t *testing.T) {
logger, err := NewRedisLogger(RedisLoggerOptions{
Name: "redis",
CallerSkip: 4,
SlowThreshold: 10 * time.Millisecond,
OutputPaths: []string{"stdout"},
InitialFields: map[string]interface{}{
"key1": "value1",
},
DisableCaller: false,
DisableStacktrace: false,
EncoderConfig: &defaultEncoderConfig,
})
if err != nil {
t.Errorf("new gorm logger failed: %v", err)
}
if logger == (RedisLogger{}) {
t.Error("CtxGormLogger return empty GormLogger")
}
redisClient := redis.NewClient(&redis.Options{
Addr: "127.0.0.1:6379",
})
redisClient.AddHook(logger)
ctx := context.Background()
// redisClient.Get(ctx, "a")
// redisClient.Set(ctx, "b", 1, -1)
// redisClient.Get(ctx, "b")
pipeline := redisClient.Pipeline()
pipeline.Set(ctx, "c", 1, -1)
pipeline.Get(ctx, "a")
_, err = pipeline.Exec(ctx)
if err != nil {
return
}
redisClient.Del(ctx, "b", "c")
}