Commit 1cd92e7f authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

function to create a new ziplist encoded list

parent 23f96494
...@@ -2984,9 +2984,17 @@ static robj *dupStringObject(robj *o) { ...@@ -2984,9 +2984,17 @@ static robj *dupStringObject(robj *o) {
static robj *createListObject(void) { static robj *createListObject(void) {
list *l = listCreate(); list *l = listCreate();
robj *o = createObject(REDIS_LIST,l);
listSetFreeMethod(l,decrRefCount); listSetFreeMethod(l,decrRefCount);
return createObject(REDIS_LIST,l); o->encoding = REDIS_ENCODING_LIST;
return o;
}
static robj *createZiplistObject(void) {
unsigned char *zl = ziplistNew();
robj *o = createObject(REDIS_LIST,zl);
o->encoding = REDIS_ENCODING_ZIPLIST;
return o;
} }
static robj *createSetObject(void) { static robj *createSetObject(void) {
...@@ -4031,8 +4039,7 @@ static robj *rdbLoadObject(int type, FILE *fp) { ...@@ -4031,8 +4039,7 @@ static robj *rdbLoadObject(int type, FILE *fp) {
/* Read list value */ /* Read list value */
if ((len = rdbLoadLen(fp,NULL)) == REDIS_RDB_LENERR) return NULL; if ((len = rdbLoadLen(fp,NULL)) == REDIS_RDB_LENERR) return NULL;
o = createObject(REDIS_LIST,ziplistNew()); o = createZiplistObject();
o->encoding = REDIS_ENCODING_ZIPLIST;
/* Load every single element of the list */ /* Load every single element of the list */
while(len--) { while(len--) {
...@@ -5004,8 +5011,7 @@ static void pushGenericCommand(redisClient *c, int where) { ...@@ -5004,8 +5011,7 @@ static void pushGenericCommand(redisClient *c, int where) {
addReply(c,shared.cone); addReply(c,shared.cone);
return; return;
} }
lobj = createObject(REDIS_LIST,ziplistNew()); lobj = createZiplistObject();
lobj->encoding = REDIS_ENCODING_ZIPLIST;
dictAdd(c->db->dict,c->argv[1],lobj); dictAdd(c->db->dict,c->argv[1],lobj);
incrRefCount(c->argv[1]); incrRefCount(c->argv[1]);
} else { } else {
...@@ -5293,8 +5299,7 @@ static void rpoplpushcommand(redisClient *c) { ...@@ -5293,8 +5299,7 @@ static void rpoplpushcommand(redisClient *c) {
if (!handleClientsWaitingListPush(c,c->argv[2],value)) { if (!handleClientsWaitingListPush(c,c->argv[2],value)) {
/* Create the list if the key does not exist */ /* Create the list if the key does not exist */
if (!dobj) { if (!dobj) {
dobj = createObject(REDIS_LIST,ziplistNew()); dobj = createZiplistObject();
dobj->encoding = REDIS_ENCODING_ZIPLIST;
dictAdd(c->db->dict,c->argv[2],dobj); dictAdd(c->db->dict,c->argv[2],dobj);
incrRefCount(c->argv[2]); incrRefCount(c->argv[2]);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment