guilleiguaran/fakeredis — pull request #98 by xgess (2014-02-17 23:04:11+00:00)
Title: allow srandmembers to take an optional parameter for the number of eleme...

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 with a cap of the actual cardinality of the set
3. when passed a negative number, it ignores the cardinality of the set and continues to sample with repetition