spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

randomMembers bug ??

Open feng-wzf opened this issue 1 year ago • 4 comments

version: 2.7.x

org.springframework.data.redis.core.DefaultSetOperations#randomMembers

// 这个 -count 是啥意思? , 如果set中有1条数据, count值为 10, 那么会返回 10条一样的数据 // What does this count mean, If there is 1 piece of data in the set and the count value is 10, 10 pieces of the same data will be returned

connection.sRandMember(rawKey, -count)

@Override public List<V> randomMembers(K key, long count) {

Assert.isTrue(count >= 0, "Use a positive number for count; This method is already allowing duplicate elements");

byte[] rawKey = rawKey(key); List<byte[]> rawValues = execute(connection -> connection.sRandMember(rawKey, -count));

return deserializeValues(rawValues); }

feng-wzf avatar Sep 30 '22 08:09 feng-wzf

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it. Right now, we struggle to understand what you want to achieve. From the Redis documentation its defined as

if count is bigger than the set's cardinality, the command will only return the whole set without additional elements.

christophstrobl avatar Sep 30 '22 08:09 christophstrobl

image

feng-wzf avatar Sep 30 '22 08:09 feng-wzf

I think distinctRandomMembers might be what you're looking for. Other than randomMembers it won't return duplicates.

christophstrobl avatar Oct 04 '22 10:10 christophstrobl

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues avatar Oct 11 '22 10:10 spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

spring-projects-issues avatar Oct 18 '22 10:10 spring-projects-issues