Tencent / Tendis

Tendis is a high-performance distributed storage system fully compatible with the Redis protocol.
http://tendis.cn
Other
2.87k stars 317 forks source link

使用go-redis库访问Tendis,Scan命令持续返回重复的key #218

Open illidanzheng opened 1 year ago

illidanzheng commented 1 year ago

image 如图所示,scan次数,表示代码中调用scan命令的次数。keys,表示被scan命令扫出来的key的数量。

scan次数持续增大,但是key数量不变

takenliu commented 1 year ago

你问题的描述感觉不够清晰,不知道你是怎么用和怎么测的,我们这边测试是没有问题的。返回的cusor为0之后,就表示数据scan结束了。

takenliu commented 1 year ago
127.0.0.1:52000> scan 0 match a* count 2
1) "3"
2) 1) "a1"
   2) "a3"
127.0.0.1:52000> scan 3 match a* count 2
1) "5"
2) 1) "a2"
   2) "a5"
127.0.0.1:52000> scan 5 match a* count 2
1) "0"
2) 1) "a4"
127.0.0.1:52000> keys a*
1) "a1"
2) "a3"
3) "a2"
4) "a5"
5) "a4"
illidanzheng commented 1 year ago
image

我们是通过代码调用的,如下图:

image
illidanzheng commented 1 year ago

img_v2_8cb7a31c-349b-41c1-aaf6-e12c07d572eg 有查到文档中说scan会有这种问题,是否有解决方案?

illidanzheng commented 1 year ago

好,我先看看

另外,我看了系统监控,我们对tendis的写入qps,不超过100,应该算小的了

takenliu commented 1 year ago

嗯,跟你贴的这个问题应该不是一件事情。 执行下这个看看: redis-cli -p 54005 info dataset | grep rocksdb.estimate-num-key

takenliu commented 1 year ago

原因是客户端代码有误,修改之后问题得到解决:

func GetKeys(redisCli *redis.ClusterClient) error {
    err := redisCli.ForEachMaster(context.Background(), func(ctx context.Context, client *redis.Client) error {
        for true {
            scanCmd := redisCli.Scan(ctx, cursor, "*", 1000)  // redisCli(集群客户端)需要改为client(单节点客户端)
            keys, cursor, err = scanCmd.Result()
        }
    }
}
raffertyyu commented 1 year ago

经过沟通,确认为Go代码有误。