mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
CLUSTER GETKEYSINSLOT implemented
This commit is contained in:
parent
1eb713a4c1
commit
484354ff95
@ -1209,6 +1209,27 @@ void clusterCommand(redisClient *c) {
|
|||||||
sds key = c->argv[2]->ptr;
|
sds key = c->argv[2]->ptr;
|
||||||
|
|
||||||
addReplyLongLong(c,keyHashSlot(key,sdslen(key)));
|
addReplyLongLong(c,keyHashSlot(key,sdslen(key)));
|
||||||
|
} else if (!strcasecmp(c->argv[1]->ptr,"getkeysinslot") && c->argc == 4) {
|
||||||
|
long long maxkeys, slot;
|
||||||
|
unsigned int numkeys;
|
||||||
|
int j;
|
||||||
|
robj **keys;
|
||||||
|
|
||||||
|
if (getLongLongFromObjectOrReply(c,c->argv[2],&slot,NULL) != REDIS_OK)
|
||||||
|
return;
|
||||||
|
if (getLongLongFromObjectOrReply(c,c->argv[3],&maxkeys,NULL) != REDIS_OK)
|
||||||
|
return;
|
||||||
|
if (slot < 0 || slot >= REDIS_CLUSTER_SLOTS || maxkeys < 0 ||
|
||||||
|
maxkeys > 1024*1024) {
|
||||||
|
addReplyError(c,"Invalid slot or number of keys");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
keys = zmalloc(sizeof(robj*)*maxkeys);
|
||||||
|
numkeys = GetKeysInSlot(slot, keys, maxkeys);
|
||||||
|
addReplyMultiBulkLen(c,numkeys);
|
||||||
|
for (j = 0; j < numkeys; j++) addReplyBulk(c,keys[j]);
|
||||||
|
zfree(keys);
|
||||||
} else {
|
} else {
|
||||||
addReplyError(c,"Wrong CLUSTER subcommand or number of arguments");
|
addReplyError(c,"Wrong CLUSTER subcommand or number of arguments");
|
||||||
}
|
}
|
||||||
|
10
src/db.c
10
src/db.c
@ -725,14 +725,18 @@ void SlotToKeyDel(robj *key) {
|
|||||||
zslDelete(server.cluster.slots_to_keys,hashslot,key);
|
zslDelete(server.cluster.slots_to_keys,hashslot,key);
|
||||||
}
|
}
|
||||||
|
|
||||||
robj *GetKeyInSlot(unsigned int hashslot) {
|
unsigned int GetKeysInSlot(unsigned int hashslot, robj **keys, unsigned int count) {
|
||||||
zskiplistNode *n;
|
zskiplistNode *n;
|
||||||
zrangespec range;
|
zrangespec range;
|
||||||
|
int j = 0;
|
||||||
|
|
||||||
range.min = range.max = hashslot;
|
range.min = range.max = hashslot;
|
||||||
range.minex = range.maxex = 0;
|
range.minex = range.maxex = 0;
|
||||||
|
|
||||||
n = zslFirstInRange(server.cluster.slots_to_keys, range);
|
n = zslFirstInRange(server.cluster.slots_to_keys, range);
|
||||||
if (!n) return NULL;
|
while(n && n->score == hashslot && count--) {
|
||||||
return n->obj;
|
keys[j++] = n->obj;
|
||||||
|
n = n->level[0].forward;
|
||||||
|
}
|
||||||
|
return j;
|
||||||
}
|
}
|
||||||
|
@ -1065,6 +1065,7 @@ long long emptyDb();
|
|||||||
int selectDb(redisClient *c, int id);
|
int selectDb(redisClient *c, int id);
|
||||||
void signalModifiedKey(redisDb *db, robj *key);
|
void signalModifiedKey(redisDb *db, robj *key);
|
||||||
void signalFlushedDb(int dbid);
|
void signalFlushedDb(int dbid);
|
||||||
|
unsigned int GetKeysInSlot(unsigned int hashslot, robj **keys, unsigned int count);
|
||||||
|
|
||||||
/* API to get key arguments from commands */
|
/* API to get key arguments from commands */
|
||||||
#define REDIS_GETKEYS_ALL 0
|
#define REDIS_GETKEYS_ALL 0
|
||||||
|
Loading…
Reference in New Issue
Block a user