summaryrefslogtreecommitdiff
path: root/src/t_zset.c
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2011-03-10 17:02:05 +0100
committerPieter Noordhuis <pcnoordhuis@gmail.com>2011-03-10 17:02:05 +0100
commit255eebe22167e00f74e359bc71718225d6bd70c8 (patch)
tree009e5c0aeefcdf43a4317891f8e0c5fafb8cd587 /src/t_zset.c
parentdba3a153a7ac9a1ec81e8f3034714d4900235a00 (diff)
downloadredis-255eebe22167e00f74e359bc71718225d6bd70c8.tar.gz
Convert encoding of result when in limits
Diffstat (limited to 'src/t_zset.c')
-rw-r--r--src/t_zset.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/t_zset.c b/src/t_zset.c
index b77a34245..a2882702b 100644
--- a/src/t_zset.c
+++ b/src/t_zset.c
@@ -1426,6 +1426,7 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
zsetopsrc *src;
zsetopval zval;
robj *tmp;
+ unsigned int maxelelen = 0;
robj *dstobj;
zset *dstzset;
zskiplistNode *znode;
@@ -1539,6 +1540,10 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
incrRefCount(tmp); /* added to skiplist */
dictAdd(dstzset->dict,tmp,&znode->score);
incrRefCount(tmp); /* added to dictionary */
+
+ if (tmp->encoding == REDIS_ENCODING_RAW)
+ if (sdslen(tmp->ptr) > maxelelen)
+ maxelelen = sdslen(tmp->ptr);
}
}
}
@@ -1571,6 +1576,10 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
incrRefCount(zval.ele); /* added to skiplist */
dictAdd(dstzset->dict,tmp,&znode->score);
incrRefCount(zval.ele); /* added to dictionary */
+
+ if (tmp->encoding == REDIS_ENCODING_RAW)
+ if (sdslen(tmp->ptr) > maxelelen)
+ maxelelen = sdslen(tmp->ptr);
}
}
} else {
@@ -1586,13 +1595,18 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
server.dirty++;
}
if (dstzset->zsl->length) {
+ /* Convert to ziplist when in limits. */
+ if (dstzset->zsl->length <= server.zset_max_ziplist_entries &&
+ maxelelen <= server.zset_max_ziplist_value)
+ zsConvert(dstobj,REDIS_ENCODING_ZIPLIST);
+
dbAdd(c->db,dstkey,dstobj);
- addReplyLongLong(c, dstzset->zsl->length);
+ addReplyLongLong(c,zsLength(dstobj));
if (!touched) signalModifiedKey(c->db,dstkey);
server.dirty++;
} else {
decrRefCount(dstobj);
- addReply(c, shared.czero);
+ addReply(c,shared.czero);
}
zfree(src);
}