allow srandmembers to take an optional parameter for the number of eleme... #98

Merged
merged 2 commits into from Apr 1, 2014

Conversation

Projects
None yet
3 participants
@xgess
Contributor

xgess commented Feb 17, 2014

Redis supports an optional parameter for srandmember. This adds that behavior.

Documentation for SRANDMEMBER: http://redis.io/commands/srandmember
"Starting from Redis version 2.6, when called with the additional count argument, return an array of count distinct elements if count is positive. If called with a negative count the behavior changes and the command is allowed to return the same element multiple times. In this case the number of returned elements is the absolute value of the specified count."

  1. when the set cannot be found in redis, it returns an empty array if there's a number passed
  2. when passed a positive number, it will sample for that many random elements WITHOUT replacement
  3. when passed a negative number, it will sample for that many random elements WITH replacement

xgess added some commits Feb 17, 2014

allow srandmembers to take an optional parameter for the number of el…
…ements

* with negative numbers, redis supports repeated samplings
* behavior with empty sets is different: empty array instead of nil
@TheTeaNerd

This comment has been minimized.

Show comment Hide comment
@TheTeaNerd

TheTeaNerd Apr 1, 2014

👍 for more closely tracking the Redis API.

👍 for more closely tracking the Redis API.

guilleiguaran added a commit that referenced this pull request Apr 1, 2014

Merge pull request #98 from xgess/add-support-for-multiple-srandmembers
allow srandmembers to take an optional parameter for the number of eleme...

@guilleiguaran guilleiguaran merged commit 17bed61 into guilleiguaran:master Apr 1, 2014

1 check passed

default The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment