From dc4be23ec895c6ec49afc75cd037cac230a21771 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 21 Apr 2010 11:31:29 +0200 Subject: [PATCH] binary safe keys ready implementation of RANDOMKEYS --- redis.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/redis.c b/redis.c index 1d3958ab..31c6f5ca 100644 --- a/redis.c +++ b/redis.c @@ -4234,18 +4234,25 @@ static void selectCommand(redisClient *c) { static void randomkeyCommand(redisClient *c) { dictEntry *de; + robj *key; while(1) { de = dictGetRandomKey(c->db->dict); if (!de || expireIfNeeded(c->db,dictGetEntryKey(de)) == 0) break; } + if (de == NULL) { - addReply(c,shared.plus); - addReply(c,shared.crlf); + addReply(c,shared.nullbulk); + return; + } + + key = dictGetEntryKey(de); + if (server.vm_enabled) { + key = dupStringObject(key); + addReplyBulk(c,key); + decrRefCount(key); } else { - addReply(c,shared.plus); - addReply(c,dictGetEntryKey(de)); - addReply(c,shared.crlf); + addReplyBulk(c,key); } }