Skip to content

Commit

Permalink
feat: add redis bigkey hook
Browse files Browse the repository at this point in the history
  • Loading branch information
aiden.ma authored and aiden.ma committed Sep 23, 2024
1 parent 9bbfa17 commit 5588c6c
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions core/stores/redis/bigkeyhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"bytes"
"context"
"testing"
"time"

"github.com/alicebob/miniredis/v2"
"github.com/stretchr/testify/assert"

"github.com/zeromicro/go-zero/core/logx"
)

Expand Down Expand Up @@ -320,35 +320,3 @@ func TestBigKeyHook_AfterProcess_Zrange(t *testing.T) {
_, _ = r.ZrangebyscoreWithScoresAndLimit("foo", 0, 100, 0, 10)
assert.Contains(t, buf.String(), "BigKey limit")
}

func TestBigKeyHook_stat(t *testing.T) {
var buf bytes.Buffer
logx.Reset()
logx.SetLevel(logx.InfoLevel)
logx.SetWriter(logx.NewWriter(&buf))
defer logx.Reset()

r := MustNewRedis(RedisConf{
Host: miniredis.RunT(t).Addr(),
Type: "node",
VerifyBigKey: BigKeyHookConfig{
Enable: true,
LimitSize: 5,
LimitCount: 1,
BufferLen: 100,
StatInterval: time.Millisecond * 100,
},
})

err := r.Set("foo", "123456")
assert.NoError(t, err)

for i := 0; i < 99; i++ {
_, _ = r.Get("foo")
}

time.Sleep(time.Second)

assert.Contains(t, buf.String(), "[REDIS] BigKey limit, key: foo, size: 6, count: 100")

}

0 comments on commit 5588c6c

Please sign in to comment.