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