ZRANDMEMBER key [ [WITHSCORES]] */
| 4208 | |
| 4209 | /* ZRANDMEMBER key [<count> [WITHSCORES]] */ |
| 4210 | void zrandmemberCommand(client *c) { |
| 4211 | long l; |
| 4212 | int withscores = 0; |
| 4213 | robj_roptr zset; |
| 4214 | ziplistEntry ele; |
| 4215 | |
| 4216 | if (c->argc >= 3) { |
| 4217 | if (getRangeLongFromObjectOrReply(c,c->argv[2],-LONG_MAX,LONG_MAX,&l,NULL) != C_OK) return; |
| 4218 | if (c->argc > 4 || (c->argc == 4 && strcasecmp(szFromObj(c->argv[3]),"withscores"))) { |
| 4219 | addReplyErrorObject(c,shared.syntaxerr); |
| 4220 | return; |
| 4221 | } else if (c->argc == 4) { |
| 4222 | withscores = 1; |
| 4223 | if (l < -g_pserver->rand_total_threshold || l > g_pserver->rand_total_threshold) { |
| 4224 | addReplyError(c,"value is out of range"); |
| 4225 | return; |
| 4226 | } |
| 4227 | } |
| 4228 | zrandmemberWithCountCommand(c, l, withscores); |
| 4229 | return; |
| 4230 | } |
| 4231 | |
| 4232 | /* Handle variant without <count> argument. Reply with simple bulk string */ |
| 4233 | if ((zset = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp])) == nullptr || |
| 4234 | checkType(c,zset,OBJ_ZSET)) { |
| 4235 | return; |
| 4236 | } |
| 4237 | |
| 4238 | zsetTypeRandomElement(zset, zsetLength(zset), &ele,NULL); |
| 4239 | zsetReplyFromZiplistEntry(c,&ele); |
| 4240 | } |
nothing calls this directly
no test coverage detected