Open
Description
Hello, when I use golang to concurrently operate redis' set type spopN command at around 16000, I have a problem with multiple elements being the same. In the redis official state that spopn will be deleted immediately, and in the java language, I have been verified that there are duplicate elements in concurrent operations using golang, I suspect that either there is no immediate deletion or multiple links get the same element
The getId func repeats
redis config
func Redis() (redisClient *redis.Client) {
client := redis.NewClient(&redis.Options{
Addr: global.ServerConfig.Redis.Addr,
Password: global.ServerConfig.Redis.Password,
DB: global.ServerConfig.Redis.Db,
MinIdleConns: 10,
PoolSize: 50000,
})
ctx := context.Background()
ping, err := client.Ping(ctx).Result()
if err != nil {
global.Log.Error("redis start error ", zap.Error(err))
os.Exit(0)
}
global.Log.Info("redis start ping result", zap.String("key", ping))
return client
}
Source code example
func test(c *gin.Context{
go getId()
}
func getId(){
result, err := global.Redis.SPopN(context.Background(), global.UniqueIdBuildLockWorkingKey, 1).Result()
if err == nil {
return result
}
}
result, err := global.Redis.SPopN(context.Background(), global.UniqueIdBuildLockWorkingKey, size).Result()
Metadata
Metadata
Assignees
Labels
No labels