Port db to C++
Former-commit-id: 54db278695a2df1ae08501b1518c1f7361610184
This commit is contained in:
parent
836e0aa80b
commit
149415cd20
@ -55,7 +55,7 @@ void updateLFU(robj *val) {
|
|||||||
robj *lookupKey(redisDb *db, robj *key, int flags) {
|
robj *lookupKey(redisDb *db, robj *key, int flags) {
|
||||||
dictEntry *de = dictFind(db->pdict,ptrFromObj(key));
|
dictEntry *de = dictFind(db->pdict,ptrFromObj(key));
|
||||||
if (de) {
|
if (de) {
|
||||||
robj *val = dictGetVal(de);
|
robj *val = (robj*)dictGetVal(de);
|
||||||
|
|
||||||
/* Update the access time for the ageing algorithm.
|
/* Update the access time for the ageing algorithm.
|
||||||
* Don't do it if we have a saving child, as this will trigger
|
* Don't do it if we have a saving child, as this will trigger
|
||||||
@ -173,7 +173,7 @@ robj *lookupKeyWriteOrReply(client *c, robj *key, robj *reply) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int dbAddCore(redisDb *db, robj *key, robj *val) {
|
int dbAddCore(redisDb *db, robj *key, robj *val) {
|
||||||
sds copy = sdsdup(ptrFromObj(key));
|
sds copy = sdsdup(szFromObj(key));
|
||||||
int retval = dictAdd(db->pdict, copy, val);
|
int retval = dictAdd(db->pdict, copy, val);
|
||||||
|
|
||||||
if (retval == DICT_OK)
|
if (retval == DICT_OK)
|
||||||
@ -225,7 +225,7 @@ void dbOverwrite(redisDb *db, robj *key, robj *val) {
|
|||||||
|
|
||||||
serverAssertWithInfo(NULL,key,de != NULL);
|
serverAssertWithInfo(NULL,key,de != NULL);
|
||||||
dictEntry auxentry = *de;
|
dictEntry auxentry = *de;
|
||||||
robj *old = dictGetVal(de);
|
robj *old = (robj*)dictGetVal(de);
|
||||||
if (server.maxmemory_policy & MAXMEMORY_FLAG_LFU) {
|
if (server.maxmemory_policy & MAXMEMORY_FLAG_LFU) {
|
||||||
val->lru = old->lru;
|
val->lru = old->lru;
|
||||||
}
|
}
|
||||||
@ -278,7 +278,7 @@ robj *dbRandomKey(redisDb *db) {
|
|||||||
de = dictGetRandomKey(db->pdict);
|
de = dictGetRandomKey(db->pdict);
|
||||||
if (de == NULL) return NULL;
|
if (de == NULL) return NULL;
|
||||||
|
|
||||||
key = dictGetKey(de);
|
key = (sds)dictGetKey(de);
|
||||||
keyobj = createStringObject(key,sdslen(key));
|
keyobj = createStringObject(key,sdslen(key));
|
||||||
if (dictFind(db->expires,key)) {
|
if (dictFind(db->expires,key)) {
|
||||||
if (allvolatile && listLength(server.masters) && --maxtries == 0) {
|
if (allvolatile && listLength(server.masters) && --maxtries == 0) {
|
||||||
@ -352,7 +352,7 @@ robj *dbUnshareStringValue(redisDb *db, robj *key, robj *o) {
|
|||||||
serverAssert(o->type == OBJ_STRING);
|
serverAssert(o->type == OBJ_STRING);
|
||||||
if (o->refcount != 1 || o->encoding != OBJ_ENCODING_RAW) {
|
if (o->refcount != 1 || o->encoding != OBJ_ENCODING_RAW) {
|
||||||
robj *decoded = getDecodedObject(o);
|
robj *decoded = getDecodedObject(o);
|
||||||
o = createRawStringObject(ptrFromObj(decoded), sdslen(ptrFromObj(decoded)));
|
o = createRawStringObject(szFromObj(decoded), sdslen(szFromObj(decoded)));
|
||||||
decrRefCount(decoded);
|
decrRefCount(decoded);
|
||||||
dbOverwrite(db,key,o);
|
dbOverwrite(db,key,o);
|
||||||
}
|
}
|
||||||
@ -449,7 +449,7 @@ void signalFlushedDb(int dbid) {
|
|||||||
int getFlushCommandFlags(client *c, int *flags) {
|
int getFlushCommandFlags(client *c, int *flags) {
|
||||||
/* Parse the optional ASYNC option. */
|
/* Parse the optional ASYNC option. */
|
||||||
if (c->argc > 1) {
|
if (c->argc > 1) {
|
||||||
if (c->argc > 2 || strcasecmp(ptrFromObj(c->argv[1]),"async")) {
|
if (c->argc > 2 || strcasecmp(szFromObj(c->argv[1]),"async")) {
|
||||||
addReply(c,shared.syntaxerr);
|
addReply(c,shared.syntaxerr);
|
||||||
return C_ERR;
|
return C_ERR;
|
||||||
}
|
}
|
||||||
@ -567,7 +567,7 @@ void randomkeyCommand(client *c) {
|
|||||||
void keysCommand(client *c) {
|
void keysCommand(client *c) {
|
||||||
dictIterator *di;
|
dictIterator *di;
|
||||||
dictEntry *de;
|
dictEntry *de;
|
||||||
sds pattern = ptrFromObj(c->argv[1]);
|
sds pattern = szFromObj(c->argv[1]);
|
||||||
int plen = sdslen(pattern), allkeys;
|
int plen = sdslen(pattern), allkeys;
|
||||||
unsigned long numkeys = 0;
|
unsigned long numkeys = 0;
|
||||||
void *replylen = addReplyDeferredLen(c);
|
void *replylen = addReplyDeferredLen(c);
|
||||||
@ -575,7 +575,7 @@ void keysCommand(client *c) {
|
|||||||
di = dictGetSafeIterator(c->db->pdict);
|
di = dictGetSafeIterator(c->db->pdict);
|
||||||
allkeys = (pattern[0] == '*' && pattern[1] == '\0');
|
allkeys = (pattern[0] == '*' && pattern[1] == '\0');
|
||||||
while((de = dictNext(di)) != NULL) {
|
while((de = dictNext(di)) != NULL) {
|
||||||
sds key = dictGetKey(de);
|
sds key = (sds)dictGetKey(de);
|
||||||
robj *keyobj;
|
robj *keyobj;
|
||||||
|
|
||||||
if (allkeys || stringmatchlen(pattern,plen,key,sdslen(key),0)) {
|
if (allkeys || stringmatchlen(pattern,plen,key,sdslen(key),0)) {
|
||||||
@ -595,23 +595,23 @@ void keysCommand(client *c) {
|
|||||||
* returned by the dictionary iterator into a list. */
|
* returned by the dictionary iterator into a list. */
|
||||||
void scanCallback(void *privdata, const dictEntry *de) {
|
void scanCallback(void *privdata, const dictEntry *de) {
|
||||||
void **pd = (void**) privdata;
|
void **pd = (void**) privdata;
|
||||||
list *keys = pd[0];
|
list *keys = (list*)pd[0];
|
||||||
robj *o = pd[1];
|
robj *o = (robj*)pd[1];
|
||||||
robj *key, *val = NULL;
|
robj *key, *val = NULL;
|
||||||
|
|
||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
sds sdskey = dictGetKey(de);
|
sds sdskey = (sds)dictGetKey(de);
|
||||||
key = createStringObject(sdskey, sdslen(sdskey));
|
key = createStringObject(sdskey, sdslen(sdskey));
|
||||||
} else if (o->type == OBJ_SET) {
|
} else if (o->type == OBJ_SET) {
|
||||||
sds keysds = dictGetKey(de);
|
sds keysds = (sds)dictGetKey(de);
|
||||||
key = createStringObject(keysds,sdslen(keysds));
|
key = createStringObject(keysds,sdslen(keysds));
|
||||||
} else if (o->type == OBJ_HASH) {
|
} else if (o->type == OBJ_HASH) {
|
||||||
sds sdskey = dictGetKey(de);
|
sds sdskey = (sds)dictGetKey(de);
|
||||||
sds sdsval = dictGetVal(de);
|
sds sdsval = (sds)dictGetVal(de);
|
||||||
key = createStringObject(sdskey,sdslen(sdskey));
|
key = createStringObject(sdskey,sdslen(sdskey));
|
||||||
val = createStringObject(sdsval,sdslen(sdsval));
|
val = createStringObject(sdsval,sdslen(sdsval));
|
||||||
} else if (o->type == OBJ_ZSET) {
|
} else if (o->type == OBJ_ZSET) {
|
||||||
sds sdskey = dictGetKey(de);
|
sds sdskey = (sds)dictGetKey(de);
|
||||||
key = createStringObject(sdskey,sdslen(sdskey));
|
key = createStringObject(sdskey,sdslen(sdskey));
|
||||||
val = createStringObjectFromLongDouble(*(double*)dictGetVal(de),0);
|
val = createStringObjectFromLongDouble(*(double*)dictGetVal(de),0);
|
||||||
} else {
|
} else {
|
||||||
@ -632,7 +632,7 @@ int parseScanCursorOrReply(client *c, robj *o, unsigned long *cursor) {
|
|||||||
/* Use strtoul() because we need an *unsigned* long, so
|
/* Use strtoul() because we need an *unsigned* long, so
|
||||||
* getLongLongFromObject() does not cover the whole cursor space. */
|
* getLongLongFromObject() does not cover the whole cursor space. */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
*cursor = strtoul(ptrFromObj(o), &eptr, 10);
|
*cursor = strtoul(szFromObj(o), &eptr, 10);
|
||||||
if (isspace(((char*)ptrFromObj(o))[0]) || eptr[0] != '\0' || errno == ERANGE)
|
if (isspace(((char*)ptrFromObj(o))[0]) || eptr[0] != '\0' || errno == ERANGE)
|
||||||
{
|
{
|
||||||
addReplyError(c, "invalid cursor");
|
addReplyError(c, "invalid cursor");
|
||||||
@ -672,7 +672,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
|
|||||||
/* Step 1: Parse options. */
|
/* Step 1: Parse options. */
|
||||||
while (i < c->argc) {
|
while (i < c->argc) {
|
||||||
j = c->argc - i;
|
j = c->argc - i;
|
||||||
if (!strcasecmp(ptrFromObj(c->argv[i]), "count") && j >= 2) {
|
if (!strcasecmp(szFromObj(c->argv[i]), "count") && j >= 2) {
|
||||||
if (getLongFromObjectOrReply(c, c->argv[i+1], &count, NULL)
|
if (getLongFromObjectOrReply(c, c->argv[i+1], &count, NULL)
|
||||||
!= C_OK)
|
!= C_OK)
|
||||||
{
|
{
|
||||||
@ -685,8 +685,8 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
i += 2;
|
i += 2;
|
||||||
} else if (!strcasecmp(ptrFromObj(c->argv[i]), "match") && j >= 2) {
|
} else if (!strcasecmp(szFromObj(c->argv[i]), "match") && j >= 2) {
|
||||||
pat = ptrFromObj(c->argv[i+1]);
|
pat = szFromObj(c->argv[i+1]);
|
||||||
patlen = sdslen(pat);
|
patlen = sdslen(pat);
|
||||||
|
|
||||||
/* The pattern always matches if it is exactly "*", so it is
|
/* The pattern always matches if it is exactly "*", so it is
|
||||||
@ -713,12 +713,12 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
|
|||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
ht = c->db->pdict;
|
ht = c->db->pdict;
|
||||||
} else if (o->type == OBJ_SET && o->encoding == OBJ_ENCODING_HT) {
|
} else if (o->type == OBJ_SET && o->encoding == OBJ_ENCODING_HT) {
|
||||||
ht = ptrFromObj(o);
|
ht = (dict*)ptrFromObj(o);
|
||||||
} else if (o->type == OBJ_HASH && o->encoding == OBJ_ENCODING_HT) {
|
} else if (o->type == OBJ_HASH && o->encoding == OBJ_ENCODING_HT) {
|
||||||
ht = ptrFromObj(o);
|
ht = (dict*)ptrFromObj(o);
|
||||||
count *= 2; /* We return key / value for this type. */
|
count *= 2; /* We return key / value for this type. */
|
||||||
} else if (o->type == OBJ_ZSET && o->encoding == OBJ_ENCODING_SKIPLIST) {
|
} else if (o->type == OBJ_ZSET && o->encoding == OBJ_ENCODING_SKIPLIST) {
|
||||||
zset *zs = ptrFromObj(o);
|
zset *zs = (zset*)ptrFromObj(o);
|
||||||
ht = zs->pdict;
|
ht = zs->pdict;
|
||||||
count *= 2; /* We return key / value for this type. */
|
count *= 2; /* We return key / value for this type. */
|
||||||
}
|
}
|
||||||
@ -745,11 +745,11 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
|
|||||||
int pos = 0;
|
int pos = 0;
|
||||||
int64_t ll;
|
int64_t ll;
|
||||||
|
|
||||||
while(intsetGet(ptrFromObj(o),pos++,&ll))
|
while(intsetGet((intset*)ptrFromObj(o),pos++,&ll))
|
||||||
listAddNodeTail(keys,createStringObjectFromLongLong(ll));
|
listAddNodeTail(keys,createStringObjectFromLongLong(ll));
|
||||||
cursor = 0;
|
cursor = 0;
|
||||||
} else if (o->type == OBJ_HASH || o->type == OBJ_ZSET) {
|
} else if (o->type == OBJ_HASH || o->type == OBJ_ZSET) {
|
||||||
unsigned char *p = ziplistIndex(ptrFromObj(o),0);
|
unsigned char *p = ziplistIndex((unsigned char*)ptrFromObj(o),0);
|
||||||
unsigned char *vstr;
|
unsigned char *vstr;
|
||||||
unsigned int vlen;
|
unsigned int vlen;
|
||||||
long long vll;
|
long long vll;
|
||||||
@ -759,7 +759,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
|
|||||||
listAddNodeTail(keys,
|
listAddNodeTail(keys,
|
||||||
(vstr != NULL) ? createStringObject((char*)vstr,vlen) :
|
(vstr != NULL) ? createStringObject((char*)vstr,vlen) :
|
||||||
createStringObjectFromLongLong(vll));
|
createStringObjectFromLongLong(vll));
|
||||||
p = ziplistNext(ptrFromObj(o),p);
|
p = ziplistNext((unsigned char*)ptrFromObj(o),p);
|
||||||
}
|
}
|
||||||
cursor = 0;
|
cursor = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -769,14 +769,14 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
|
|||||||
/* Step 3: Filter elements. */
|
/* Step 3: Filter elements. */
|
||||||
node = listFirst(keys);
|
node = listFirst(keys);
|
||||||
while (node) {
|
while (node) {
|
||||||
robj *kobj = listNodeValue(node);
|
robj *kobj = (robj*)listNodeValue(node);
|
||||||
nextnode = listNextNode(node);
|
nextnode = listNextNode(node);
|
||||||
int filter = 0;
|
int filter = 0;
|
||||||
|
|
||||||
/* Filter element if it does not match the pattern. */
|
/* Filter element if it does not match the pattern. */
|
||||||
if (!filter && use_pattern) {
|
if (!filter && use_pattern) {
|
||||||
if (sdsEncodedObject(kobj)) {
|
if (sdsEncodedObject(kobj)) {
|
||||||
if (!stringmatchlen(pat, patlen, ptrFromObj(kobj), sdslen(ptrFromObj(kobj)), 0))
|
if (!stringmatchlen(pat, patlen, szFromObj(kobj), sdslen(szFromObj(kobj)), 0))
|
||||||
filter = 1;
|
filter = 1;
|
||||||
} else {
|
} else {
|
||||||
char buf[LONG_STR_SIZE];
|
char buf[LONG_STR_SIZE];
|
||||||
@ -804,7 +804,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
|
|||||||
node = nextnode;
|
node = nextnode;
|
||||||
nextnode = listNextNode(node);
|
nextnode = listNextNode(node);
|
||||||
if (filter) {
|
if (filter) {
|
||||||
kobj = listNodeValue(node);
|
kobj = (robj*)listNodeValue(node);
|
||||||
decrRefCount(kobj);
|
decrRefCount(kobj);
|
||||||
listDelNode(keys, node);
|
listDelNode(keys, node);
|
||||||
}
|
}
|
||||||
@ -818,7 +818,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
|
|||||||
|
|
||||||
addReplyArrayLen(c, listLength(keys));
|
addReplyArrayLen(c, listLength(keys));
|
||||||
while ((node = listFirst(keys)) != NULL) {
|
while ((node = listFirst(keys)) != NULL) {
|
||||||
robj *kobj = listNodeValue(node);
|
robj *kobj = (robj*)listNodeValue(node);
|
||||||
addReplyBulk(c, kobj);
|
addReplyBulk(c, kobj);
|
||||||
decrRefCount(kobj);
|
decrRefCount(kobj);
|
||||||
listDelNode(keys, node);
|
listDelNode(keys, node);
|
||||||
@ -846,7 +846,7 @@ void lastsaveCommand(client *c) {
|
|||||||
|
|
||||||
void typeCommand(client *c) {
|
void typeCommand(client *c) {
|
||||||
robj *o;
|
robj *o;
|
||||||
char *type;
|
const char *type;
|
||||||
|
|
||||||
o = lookupKeyReadWithFlags(c->db,c->argv[1],LOOKUP_NOTOUCH);
|
o = lookupKeyReadWithFlags(c->db,c->argv[1],LOOKUP_NOTOUCH);
|
||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
@ -860,7 +860,7 @@ void typeCommand(client *c) {
|
|||||||
case OBJ_HASH: type = "hash"; break;
|
case OBJ_HASH: type = "hash"; break;
|
||||||
case OBJ_STREAM: type = "stream"; break;
|
case OBJ_STREAM: type = "stream"; break;
|
||||||
case OBJ_MODULE: {
|
case OBJ_MODULE: {
|
||||||
moduleValue *mv = ptrFromObj(o);
|
moduleValue *mv = (moduleValue*)ptrFromObj(o);
|
||||||
type = mv->type->name;
|
type = mv->type->name;
|
||||||
}; break;
|
}; break;
|
||||||
default: type = "unknown"; break;
|
default: type = "unknown"; break;
|
||||||
@ -876,9 +876,9 @@ void shutdownCommand(client *c) {
|
|||||||
addReply(c,shared.syntaxerr);
|
addReply(c,shared.syntaxerr);
|
||||||
return;
|
return;
|
||||||
} else if (c->argc == 2) {
|
} else if (c->argc == 2) {
|
||||||
if (!strcasecmp(ptrFromObj(c->argv[1]),"nosave")) {
|
if (!strcasecmp(szFromObj(c->argv[1]),"nosave")) {
|
||||||
flags |= SHUTDOWN_NOSAVE;
|
flags |= SHUTDOWN_NOSAVE;
|
||||||
} else if (!strcasecmp(ptrFromObj(c->argv[1]),"save")) {
|
} else if (!strcasecmp(szFromObj(c->argv[1]),"save")) {
|
||||||
flags |= SHUTDOWN_SAVE;
|
flags |= SHUTDOWN_SAVE;
|
||||||
} else {
|
} else {
|
||||||
addReply(c,shared.syntaxerr);
|
addReply(c,shared.syntaxerr);
|
||||||
@ -904,7 +904,7 @@ void renameGenericCommand(client *c, int nx) {
|
|||||||
|
|
||||||
/* When source and dest key is the same, no operation is performed,
|
/* When source and dest key is the same, no operation is performed,
|
||||||
* if the key exists, however we still return an error on unexisting key. */
|
* if the key exists, however we still return an error on unexisting key. */
|
||||||
if (sdscmp(ptrFromObj(c->argv[1]),ptrFromObj(c->argv[2])) == 0) samekey = 1;
|
if (sdscmp(szFromObj(c->argv[1]),szFromObj(c->argv[2])) == 0) samekey = 1;
|
||||||
|
|
||||||
if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr)) == NULL)
|
if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr)) == NULL)
|
||||||
return;
|
return;
|
||||||
@ -1010,7 +1010,7 @@ void scanDatabaseForReadyLists(redisDb *db) {
|
|||||||
dictEntry *de;
|
dictEntry *de;
|
||||||
dictIterator *di = dictGetSafeIterator(db->blocking_keys);
|
dictIterator *di = dictGetSafeIterator(db->blocking_keys);
|
||||||
while((de = dictNext(di)) != NULL) {
|
while((de = dictNext(di)) != NULL) {
|
||||||
robj *key = dictGetKey(de);
|
robj *key = (robj*)dictGetKey(de);
|
||||||
robj *value = lookupKey(db,key,LOOKUP_NOTOUCH);
|
robj *value = lookupKey(db,key,LOOKUP_NOTOUCH);
|
||||||
if (value && (value->type == OBJ_LIST ||
|
if (value && (value->type == OBJ_LIST ||
|
||||||
value->type == OBJ_STREAM ||
|
value->type == OBJ_STREAM ||
|
||||||
@ -1236,7 +1236,7 @@ int *getKeysUsingCommandTable(struct redisCommand *cmd,robj **argv, int argc, in
|
|||||||
|
|
||||||
last = cmd->lastkey;
|
last = cmd->lastkey;
|
||||||
if (last < 0) last = argc+last;
|
if (last < 0) last = argc+last;
|
||||||
keys = zmalloc(sizeof(int)*((last - cmd->firstkey)+1), MALLOC_SHARED);
|
keys = (int*)zmalloc(sizeof(int)*((last - cmd->firstkey)+1), MALLOC_SHARED);
|
||||||
for (j = cmd->firstkey; j <= last; j += cmd->keystep) {
|
for (j = cmd->firstkey; j <= last; j += cmd->keystep) {
|
||||||
if (j >= argc) {
|
if (j >= argc) {
|
||||||
/* Modules commands, and standard commands with a not fixed number
|
/* Modules commands, and standard commands with a not fixed number
|
||||||
@ -1292,7 +1292,7 @@ int *zunionInterGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *nu
|
|||||||
int i, num, *keys;
|
int i, num, *keys;
|
||||||
UNUSED(cmd);
|
UNUSED(cmd);
|
||||||
|
|
||||||
num = atoi(ptrFromObj(argv[2]));
|
num = atoi(szFromObj(argv[2]));
|
||||||
/* Sanity check. Don't return any key if the command is going to
|
/* Sanity check. Don't return any key if the command is going to
|
||||||
* reply with syntax error. */
|
* reply with syntax error. */
|
||||||
if (num < 1 || num > (argc-3)) {
|
if (num < 1 || num > (argc-3)) {
|
||||||
@ -1303,7 +1303,7 @@ int *zunionInterGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *nu
|
|||||||
/* Keys in z{union,inter}store come from two places:
|
/* Keys in z{union,inter}store come from two places:
|
||||||
* argv[1] = storage key,
|
* argv[1] = storage key,
|
||||||
* argv[3...n] = keys to intersect */
|
* argv[3...n] = keys to intersect */
|
||||||
keys = zmalloc(sizeof(int)*(num+1), MALLOC_SHARED);
|
keys = (int*)zmalloc(sizeof(int)*(num+1), MALLOC_SHARED);
|
||||||
|
|
||||||
/* Add all key positions for argv[3...n] to keys[] */
|
/* Add all key positions for argv[3...n] to keys[] */
|
||||||
for (i = 0; i < num; i++) keys[i] = 3+i;
|
for (i = 0; i < num; i++) keys[i] = 3+i;
|
||||||
@ -1321,7 +1321,7 @@ int *evalGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
|
|||||||
int i, num, *keys;
|
int i, num, *keys;
|
||||||
UNUSED(cmd);
|
UNUSED(cmd);
|
||||||
|
|
||||||
num = atoi(ptrFromObj(argv[2]));
|
num = atoi(szFromObj(argv[2]));
|
||||||
/* Sanity check. Don't return any key if the command is going to
|
/* Sanity check. Don't return any key if the command is going to
|
||||||
* reply with syntax error. */
|
* reply with syntax error. */
|
||||||
if (num <= 0 || num > (argc-3)) {
|
if (num <= 0 || num > (argc-3)) {
|
||||||
@ -1329,7 +1329,7 @@ int *evalGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
keys = zmalloc(sizeof(int)*num, MALLOC_SHARED);
|
keys = (int*)zmalloc(sizeof(int)*num, MALLOC_SHARED);
|
||||||
*numkeys = num;
|
*numkeys = num;
|
||||||
|
|
||||||
/* Add all key positions for argv[3...n] to keys[] */
|
/* Add all key positions for argv[3...n] to keys[] */
|
||||||
@ -1350,7 +1350,7 @@ int *sortGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
|
|||||||
UNUSED(cmd);
|
UNUSED(cmd);
|
||||||
|
|
||||||
num = 0;
|
num = 0;
|
||||||
keys = zmalloc(sizeof(int)*2, MALLOC_SHARED); /* Alloc 2 places for the worst case. */
|
keys = (int*)zmalloc(sizeof(int)*2, MALLOC_SHARED); /* Alloc 2 places for the worst case. */
|
||||||
|
|
||||||
keys[num++] = 1; /* <sort-key> is always present. */
|
keys[num++] = 1; /* <sort-key> is always present. */
|
||||||
|
|
||||||
@ -1359,7 +1359,7 @@ int *sortGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
|
|||||||
* next. However there are options with 1 or 2 arguments, so we
|
* next. However there are options with 1 or 2 arguments, so we
|
||||||
* provide a list here in order to skip the right number of args. */
|
* provide a list here in order to skip the right number of args. */
|
||||||
struct {
|
struct {
|
||||||
char *name;
|
const char *name;
|
||||||
int skip;
|
int skip;
|
||||||
} skiplist[] = {
|
} skiplist[] = {
|
||||||
{"limit", 2},
|
{"limit", 2},
|
||||||
@ -1370,10 +1370,10 @@ int *sortGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
|
|||||||
|
|
||||||
for (i = 2; i < argc; i++) {
|
for (i = 2; i < argc; i++) {
|
||||||
for (j = 0; skiplist[j].name != NULL; j++) {
|
for (j = 0; skiplist[j].name != NULL; j++) {
|
||||||
if (!strcasecmp(ptrFromObj(argv[i]),skiplist[j].name)) {
|
if (!strcasecmp(szFromObj(argv[i]),skiplist[j].name)) {
|
||||||
i += skiplist[j].skip;
|
i += skiplist[j].skip;
|
||||||
break;
|
break;
|
||||||
} else if (!strcasecmp(ptrFromObj(argv[i]),"store") && i+1 < argc) {
|
} else if (!strcasecmp(szFromObj(argv[i]),"store") && i+1 < argc) {
|
||||||
/* Note: we don't increment "num" here and continue the loop
|
/* Note: we don't increment "num" here and continue the loop
|
||||||
* to be sure to process the *last* "STORE" option if multiple
|
* to be sure to process the *last* "STORE" option if multiple
|
||||||
* ones are provided. This is same behavior as SORT. */
|
* ones are provided. This is same behavior as SORT. */
|
||||||
@ -1398,8 +1398,8 @@ int *migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkey
|
|||||||
/* But check for the extended one with the KEYS option. */
|
/* But check for the extended one with the KEYS option. */
|
||||||
if (argc > 6) {
|
if (argc > 6) {
|
||||||
for (i = 6; i < argc; i++) {
|
for (i = 6; i < argc; i++) {
|
||||||
if (!strcasecmp(ptrFromObj(argv[i]),"keys") &&
|
if (!strcasecmp(szFromObj(argv[i]),"keys") &&
|
||||||
sdslen(ptrFromObj(argv[3])) == 0)
|
sdslen(szFromObj(argv[3])) == 0)
|
||||||
{
|
{
|
||||||
first = i+1;
|
first = i+1;
|
||||||
num = argc-first;
|
num = argc-first;
|
||||||
@ -1408,7 +1408,7 @@ int *migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkey
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keys = zmalloc(sizeof(int)*num, MALLOC_SHARED);
|
keys = (int*)zmalloc(sizeof(int)*num, MALLOC_SHARED);
|
||||||
for (i = 0; i < num; i++) keys[i] = first+i;
|
for (i = 0; i < num; i++) keys[i] = first+i;
|
||||||
*numkeys = num;
|
*numkeys = num;
|
||||||
return keys;
|
return keys;
|
||||||
@ -1425,7 +1425,7 @@ int *georadiusGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numk
|
|||||||
/* Check for the presence of the stored key in the command */
|
/* Check for the presence of the stored key in the command */
|
||||||
int stored_key = -1;
|
int stored_key = -1;
|
||||||
for (i = 5; i < argc; i++) {
|
for (i = 5; i < argc; i++) {
|
||||||
char *arg = ptrFromObj(argv[i]);
|
char *arg = szFromObj(argv[i]);
|
||||||
/* For the case when user specifies both "store" and "storedist" options, the
|
/* For the case when user specifies both "store" and "storedist" options, the
|
||||||
* second key specified would override the first key. This behavior is kept
|
* second key specified would override the first key. This behavior is kept
|
||||||
* the same as in georadiusCommand method.
|
* the same as in georadiusCommand method.
|
||||||
@ -1441,7 +1441,7 @@ int *georadiusGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numk
|
|||||||
* argv[1] = key,
|
* argv[1] = key,
|
||||||
* argv[5...n] = stored key if present
|
* argv[5...n] = stored key if present
|
||||||
*/
|
*/
|
||||||
keys = zmalloc(sizeof(int) * num, MALLOC_SHARED);
|
keys = (int*)zmalloc(sizeof(int) * num, MALLOC_SHARED);
|
||||||
|
|
||||||
/* Add all key positions to keys[] */
|
/* Add all key positions to keys[] */
|
||||||
keys[0] = 1;
|
keys[0] = 1;
|
||||||
@ -1464,7 +1464,7 @@ int *xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
|
|||||||
* name of the stream key. */
|
* name of the stream key. */
|
||||||
int streams_pos = -1;
|
int streams_pos = -1;
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
char *arg = ptrFromObj(argv[i]);
|
char *arg = szFromObj(argv[i]);
|
||||||
if (!strcasecmp(arg, "block")) {
|
if (!strcasecmp(arg, "block")) {
|
||||||
i++; /* Skip option argument. */
|
i++; /* Skip option argument. */
|
||||||
} else if (!strcasecmp(arg, "count")) {
|
} else if (!strcasecmp(arg, "count")) {
|
||||||
@ -1490,7 +1490,7 @@ int *xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
|
|||||||
num /= 2; /* We have half the keys as there are arguments because
|
num /= 2; /* We have half the keys as there are arguments because
|
||||||
there are also the IDs, one per key. */
|
there are also the IDs, one per key. */
|
||||||
|
|
||||||
keys = zmalloc(sizeof(int) * num, MALLOC_SHARED);
|
keys = (int*)zmalloc(sizeof(int) * num, MALLOC_SHARED);
|
||||||
for (i = streams_pos+1; i < argc-num; i++) keys[i-streams_pos-1] = i;
|
for (i = streams_pos+1; i < argc-num; i++) keys[i-streams_pos-1] = i;
|
||||||
*numkeys = num;
|
*numkeys = num;
|
||||||
return keys;
|
return keys;
|
||||||
@ -1501,13 +1501,13 @@ int *xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
|
|||||||
* while rehashing the cluster and in other conditions when we need to
|
* while rehashing the cluster and in other conditions when we need to
|
||||||
* understand if we have keys for a given hash slot. */
|
* understand if we have keys for a given hash slot. */
|
||||||
void slotToKeyUpdateKey(robj *key, int add) {
|
void slotToKeyUpdateKey(robj *key, int add) {
|
||||||
unsigned int hashslot = keyHashSlot(ptrFromObj(key),sdslen(ptrFromObj(key)));
|
size_t keylen = sdslen(szFromObj(key));
|
||||||
|
unsigned int hashslot = keyHashSlot(szFromObj(key),keylen);
|
||||||
unsigned char buf[64];
|
unsigned char buf[64];
|
||||||
unsigned char *indexed = buf;
|
unsigned char *indexed = buf;
|
||||||
size_t keylen = sdslen(ptrFromObj(key));
|
|
||||||
|
|
||||||
server.cluster->slots_keys_count[hashslot] += add ? 1 : -1;
|
server.cluster->slots_keys_count[hashslot] += add ? 1 : -1;
|
||||||
if (keylen+2 > 64) indexed = zmalloc(keylen+2, MALLOC_SHARED);
|
if (keylen+2 > 64) indexed = (unsigned char*)zmalloc(keylen+2, MALLOC_SHARED);
|
||||||
indexed[0] = (hashslot >> 8) & 0xff;
|
indexed[0] = (hashslot >> 8) & 0xff;
|
||||||
indexed[1] = hashslot & 0xff;
|
indexed[1] = hashslot & 0xff;
|
||||||
memcpy(indexed+2,ptrFromObj(key),keylen);
|
memcpy(indexed+2,ptrFromObj(key),keylen);
|
Loading…
x
Reference in New Issue
Block a user