spring-data-redis
spring-data-redis copied to clipboard
randomMembers bug ??
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); }
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.
I think distinctRandomMembers
might be what you're looking for. Other than randomMembers
it won't return duplicates.
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.
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.