/
del.go
64 lines (57 loc) 路 1.22 KB
/
del.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
54
55
56
57
58
59
60
61
62
63
64
package kredis
import (
"context"
"errors"
"fmt"
"github.com/go-redis/redis/v8"
"github.com/keploy/go-sdk/keploy"
internal "github.com/keploy/go-sdk/pkg/keploy"
"go.keploy.io/server/pkg/models"
)
// For Del Method
type KIntCmd struct {
Val int64
Err string
}
func (rc *RedisClient) Del(ctx context.Context, keys ...string) *redis.IntCmd {
if internal.GetModeFromContext(ctx) == internal.MODE_OFF {
return rc.Client.Del(ctx, keys...)
}
kctx, err := internal.GetState(ctx)
var (
resp = &redis.IntCmd{}
output = &KIntCmd{}
)
if err != nil {
return resp
}
mode := kctx.Mode
meta := map[string]string{
"name": "redis",
"type": string(models.NoSqlDB),
"operation": "Del",
"keys": fmt.Sprintf("%v", keys),
}
switch mode {
case internal.MODE_TEST:
// don't call the actual del method of redis
case internal.MODE_RECORD:
resp = rc.Client.Del(ctx, keys...)
x, er := resp.Result()
output.Val = x
if er != nil {
output.Err = er.Error()
}
default:
return resp
}
mock, _ := keploy.ProcessDep(ctx, rc.log, meta, output)
if mock {
resp = rc.Client.Del(ctx, keys...)
if output.Err != "" {
resp.SetErr(errors.New(output.Err))
}
resp.SetVal(output.Val)
}
return resp
}