}
/* Initialize an iterator at the specified index. */
-listTypeIterator *listTypeInitIterator(robj *subject, int index, unsigned char direction) {
+listTypeIterator *listTypeInitIterator(robj *subject, long index, unsigned char direction) {
listTypeIterator *li = zmalloc(sizeof(listTypeIterator));
li->subject = subject;
li->encoding = subject->encoding;
void lindexCommand(redisClient *c) {
robj *o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk);
if (o == NULL || checkType(c,o,REDIS_LIST)) return;
- int index = atoi(c->argv[2]->ptr);
+ long index;
robj *value = NULL;
+ if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != REDIS_OK))
+ return;
+
if (o->encoding == REDIS_ENCODING_ZIPLIST) {
unsigned char *p;
unsigned char *vstr;
void lsetCommand(redisClient *c) {
robj *o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr);
if (o == NULL || checkType(c,o,REDIS_LIST)) return;
- int index = atoi(c->argv[2]->ptr);
+ long index;
robj *value = (c->argv[3] = tryObjectEncoding(c->argv[3]));
+ if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != REDIS_OK))
+ return;
+
listTypeTryConversion(o,value);
if (o->encoding == REDIS_ENCODING_ZIPLIST) {
unsigned char *p, *zl = o->ptr;
void lrangeCommand(redisClient *c) {
robj *o;
- int start = atoi(c->argv[2]->ptr);
- int end = atoi(c->argv[3]->ptr);
- int llen;
- int rangelen;
+ long start, end, llen, rangelen;
+
+ if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) ||
+ (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptymultibulk)) == NULL
|| checkType(c,o,REDIS_LIST)) return;
void ltrimCommand(redisClient *c) {
robj *o;
- int start = atoi(c->argv[2]->ptr);
- int end = atoi(c->argv[3]->ptr);
- int llen;
- int j, ltrim, rtrim;
+ long start, end, llen, j, ltrim, rtrim;
list *list;
listNode *ln;
+ if ((getLongFromObjectOrReply(c, c->argv[2], &start, NULL) != REDIS_OK) ||
+ (getLongFromObjectOrReply(c, c->argv[3], &end, NULL) != REDIS_OK)) return;
+
if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.ok)) == NULL ||
checkType(c,o,REDIS_LIST)) return;
llen = listTypeLength(o);
void lremCommand(redisClient *c) {
robj *subject, *obj;
obj = c->argv[3] = tryObjectEncoding(c->argv[3]);
- int toremove = atoi(c->argv[2]->ptr);
- int removed = 0;
+ long toremove;
+ long removed = 0;
listTypeEntry entry;
+ if ((getLongFromObjectOrReply(c, c->argv[2], &toremove, NULL) != REDIS_OK))
+ return;
+
subject = lookupKeyWriteOrReply(c,c->argv[1],shared.czero);
if (subject == NULL || checkType(c,subject,REDIS_LIST)) return;
incrRefCount(keys[j]);
redisAssertWithInfo(c,keys[j],retval == DICT_OK);
} else {
- l = dictGetEntryVal(de);
+ l = dictGetVal(de);
}
listAddNodeTail(l,c);
}
/* Remove this client from the list of clients waiting for this key. */
de = dictFind(c->db->blocking_keys,c->bpop.keys[j]);
redisAssertWithInfo(c,c->bpop.keys[j],de != NULL);
- l = dictGetEntryVal(de);
+ l = dictGetVal(de);
listDelNode(l,listSearchKey(l,c));
/* If the list is empty we need to remove it to avoid wasting memory */
if (listLength(l) == 0)
de = dictFind(c->db->blocking_keys,key);
if (de == NULL) return 0;
- clients = dictGetEntryVal(de);
+ clients = dictGetVal(de);
numclients = listLength(clients);
/* Try to handle the push as long as there are clients waiting for a push.