• Yang Bodong's avatar
    Add HRANDFIELD and ZRANDMEMBER. improvements to SRANDMEMBER (#8297) · b9a0500f
    Yang Bodong authored
    
    
    New commands:
    `HRANDFIELD [<count> [WITHVALUES]]`
    `ZRANDMEMBER [<count> [WITHSCORES]]`
    Algorithms are similar to the one in SRANDMEMBER.
    
    Both return a simple bulk response when no arguments are given, and an array otherwise.
    In case values/scores are requested, RESP2 returns a long array, and RESP3 a nested array.
    note: in all 3 commands, the only option that also provides random order is the one with negative count.
    
    Changes to SRANDMEMBER
    * Optimization when count is 1, we can use the more efficient algorithm of non-unique random
    * optimization: work with sds strings rather than robj
    
    Other changes:
    * zzlGetScore: when zset needs to convert string to double, we use safer memcpy (in
      case the buffer is too small)
    * Solve a "bug" in SRANDMEMBER test: it intended to test a positive count (case 3 or
      case 4) and by accident used a negative count
    Co-authored-by: default avatarxinluton <xinluton@qq.com>
    Co-authored-by: default avatarOran Agra <oran@redislabs.com>
    b9a0500f
server.h 125 KB