Skip to content

Commit

Permalink
add listpack support
Browse files Browse the repository at this point in the history
  • Loading branch information
tezc committed Apr 15, 2024
1 parent ffac5a7 commit 83ba789
Show file tree
Hide file tree
Showing 12 changed files with 1,647 additions and 739 deletions.
2 changes: 1 addition & 1 deletion src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ static int rioWriteHashIteratorCursor(rio *r, hashTypeIterator *hi, int what) {
unsigned int vlen = UINT_MAX;
long long vll = LLONG_MAX;

hashTypeCurrentFromListpack(hi, what, &vstr, &vlen, &vll);
hashTypeCurrentFromListpack(hi, what, &vstr, &vlen, &vll, NULL);
if (vstr)
return rioWriteBulkString(r, (char*)vstr, vlen);
else
Expand Down
52 changes: 45 additions & 7 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ robj *dbRandomKey(redisDb *db) {
valobj = dictGetVal(de);

/* Special care to hash that all its fields got expired */
if (valobj->type == OBJ_HASH && valobj->encoding == OBJ_ENCODING_HT &&
hashTypeIsEmpty(valobj)) {
if (valobj->type == OBJ_HASH && hashTypeIsEmpty(valobj)) {
if (--maxtries) {
expireIfNeeded(db, keyobj, 0, valobj);
decrRefCount(keyobj);
Expand Down Expand Up @@ -1219,9 +1218,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long long cursor) {
}
setTypeReleaseIterator(si);
cursor = 0;
} else if ((o->type == OBJ_HASH || o->type == OBJ_ZSET) &&
o->encoding == OBJ_ENCODING_LISTPACK)
{
} else if (o->type == OBJ_ZSET && o->encoding == OBJ_ENCODING_LISTPACK) {
unsigned char *p = lpFirst(o->ptr);
unsigned char *str;
int64_t len;
Expand All @@ -1246,6 +1243,47 @@ void scanGenericCommand(client *c, robj *o, unsigned long long cursor) {
p = lpNext(o->ptr, p);
}
cursor = 0;
} else if (o->type == OBJ_HASH &&
(o->encoding == OBJ_ENCODING_LISTPACK ||
o->encoding == OBJ_ENCODING_LISTPACK_TTL))
{
int expired;
int64_t len;
long long expireAt;
unsigned char *lp = hashTypeListpackGetLp(o);
unsigned char *p = lpFirst(lp);
unsigned char *str, *val;
unsigned char intbuf[LP_INTBUF_SIZE];

while(p) {
expired = 0;

str = lpGet(p, &len, intbuf);
p = lpNext(lp, p);
val = p; /* Keep pointer to value */

if (o->encoding == OBJ_ENCODING_LISTPACK_TTL) {
p = lpNext(lp, p);
lpGetValue(p, NULL, &expireAt);
expired = hashTypeListpackIsExpired(expireAt);
}

if (expired || (use_pattern && !stringmatchlen(pat, sdslen(pat), (char *)str, len, 0))) {
/* jump to the next key/val pair */
p = lpNext(lp, p);
continue;
}

/* add key object */
listAddNodeTail(keys, sdsnewlen(str, len));
/* add value object */
if (!no_values) {
str = lpGet(val, &len, intbuf);
listAddNodeTail(keys, sdsnewlen(str, len));
}
p = lpNext(lp, p);
}
cursor = 0;
} else {
serverPanic("Not handled encoding in SCAN.");
}
Expand Down Expand Up @@ -1414,7 +1452,7 @@ void renameGenericCommand(client *c, int nx) {
/* If hash with expiration on fields then remove it from global HFE DS and
* keep next expiration time. Otherwise, dbDelete() will remove it from the
* global HFE DS and we will lose the expiration time. */
if (o->type == OBJ_HASH && o->encoding == OBJ_ENCODING_HT)
if (o->type == OBJ_HASH)
minHashExpireTime = hashTypeRemoveFromExpires(&c->db->hexpires, o);

dbDelete(c->db,c->argv[1]);
Expand Down Expand Up @@ -1493,7 +1531,7 @@ void moveCommand(client *c) {
/* If hash with expiration on fields, remove it from global HFE DS and keep
* aside registered expiration time. Must be before deletion of the object.
* hexpires (ebuckets) embed in stored items its structure. */
if (o->type == OBJ_HASH && o->encoding == OBJ_ENCODING_HT)
if (o->type == OBJ_HASH)
hashExpireTime = hashTypeRemoveFromExpires(&src->hexpires, o);

incrRefCount(o);
Expand Down

0 comments on commit 83ba789

Please sign in to comment.