Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manipulate redis spopn repeat elements #3212

Open
bravelionet opened this issue Dec 16, 2024 · 0 comments
Open

Manipulate redis spopn repeat elements #3212

bravelionet opened this issue Dec 16, 2024 · 0 comments

Comments

@bravelionet
Copy link

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant