Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
2abb95a9
Commit
2abb95a9
authored
Oct 21, 2009
by
antirez
Browse files
SRANDMEMBER added
parent
f69f2cba
Changes
2
Hide whitespace changes
Inline
Side-by-side
redis-cli.c
View file @
2abb95a9
...
...
@@ -81,6 +81,7 @@ static struct redisCommand cmdTable[] = {
{
"sismember"
,
3
,
REDIS_CMD_BULK
},
{
"scard"
,
2
,
REDIS_CMD_INLINE
},
{
"spop"
,
2
,
REDIS_CMD_INLINE
},
{
"srandmember"
,
2
,
REDIS_CMD_INLINE
},
{
"sinter"
,
-
2
,
REDIS_CMD_INLINE
},
{
"sinterstore"
,
-
3
,
REDIS_CMD_INLINE
},
{
"sunion"
,
-
2
,
REDIS_CMD_INLINE
},
...
...
redis.c
View file @
2abb95a9
...
...
@@ -385,6 +385,7 @@ static void smoveCommand(redisClient *c);
static void sismemberCommand(redisClient *c);
static void scardCommand(redisClient *c);
static void spopCommand(redisClient *c);
static void srandmemberCommand(redisClient *c);
static void sinterCommand(redisClient *c);
static void sinterstoreCommand(redisClient *c);
static void sunionCommand(redisClient *c);
...
...
@@ -436,6 +437,7 @@ static struct redisCommand cmdTable[] = {
{"sismember",sismemberCommand,3,REDIS_CMD_BULK},
{"scard",scardCommand,2,REDIS_CMD_INLINE},
{"spop",spopCommand,2,REDIS_CMD_INLINE},
{"srandmember",srandmemberCommand,2,REDIS_CMD_INLINE},
{"sinter",sinterCommand,-2,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM},
{"sinterstore",sinterstoreCommand,-3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM},
{"sunion",sunionCommand,-2,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM},
...
...
@@ -3387,6 +3389,31 @@ static void spopCommand(redisClient *c) {
}
}
static void srandmemberCommand(redisClient *c) {
robj *set;
dictEntry *de;
set = lookupKeyRead(c->db,c->argv[1]);
if (set == NULL) {
addReply(c,shared.nullbulk);
} else {
if (set->type != REDIS_SET) {
addReply(c,shared.wrongtypeerr);
return;
}
de = dictGetRandomKey(set->ptr);
if (de == NULL) {
addReply(c,shared.nullbulk);
} else {
robj *ele = dictGetEntryKey(de);
addReplyBulkLen(c,ele);
addReply(c,ele);
addReply(c,shared.crlf);
}
}
}
static int qsortCompareSetsByCardinality(const void *s1, const void *s2) {
dict **d1 = (void*) s1, **d2 = (void*) s2;
...
...
@@ -4629,6 +4656,7 @@ static struct redisFunctionSym symsTable[] = {
{"sismemberCommand", (unsigned long)sismemberCommand},
{"scardCommand", (unsigned long)scardCommand},
{"spopCommand", (unsigned long)spopCommand},
{"srandmemberCommand", (unsigned long)srandmemberCommand},
{"sinterCommand", (unsigned long)sinterCommand},
{"sinterstoreCommand", (unsigned long)sinterstoreCommand},
{"sunionCommand", (unsigned long)sunionCommand},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment