Skip to content

Commit 0cadaec

Browse files
committed
copy hash object should also copy the fields ttl
Signed-off-by: Ran Shidlansik <[email protected]>
1 parent 79b7e78 commit 0cadaec

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/rdb.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,6 @@ ssize_t rdbSaveObject(rio *rdb, robj *o, robj *key, int dbid) {
992992
hashtableResetIterator(&iter);
993993
return -1;
994994
}
995-
serverLog(LL_NOTICE, "save key %s with expiry: %lld", field, expiry);
996995
nwritten += n;
997996
}
998997
}
@@ -2195,7 +2194,6 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) {
21952194
long long itemexpiry = -1;
21962195
if (rdbtype == RDB_TYPE_HASH_2) {
21972196
itemexpiry = rdbLoadMillisecondTime(rdb, RDB_VERSION);
2198-
serverLog(LL_NOTICE, "load key %s with expiry: %lld", field, itemexpiry);
21992197
if (itemexpiry == LLONG_MAX && rioGetReadError(rdb)) return NULL;
22002198
}
22012199

src/t_hash.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ int hashTypeGetValue(robj *o, sds field, unsigned char **vstr, unsigned int *vle
653653
int hashTypeGetExpiry(robj *o, sds field, long long *expiry) {
654654
if (o->encoding == OBJ_ENCODING_LISTPACK) {
655655
if (hashTypeExists(o, field)) {
656-
if (expiry) *expiry = -1;
656+
if (expiry) *expiry = EXPIRY_NONE;
657657
return C_OK;
658658
}
659659
} else if (o->encoding == OBJ_ENCODING_HASHTABLE) {
@@ -1177,20 +1177,22 @@ robj *hashTypeDup(robj *o) {
11771177
} else if (o->encoding == OBJ_ENCODING_HASHTABLE) {
11781178
hashtable *ht = hashtableCreate(&hashHashtableType);
11791179
hashtableExpand(ht, hashtableSize((const hashtable *)o->ptr));
1180+
hobj = createObject(OBJ_HASH, ht);
1181+
hobj->encoding = OBJ_ENCODING_HASHTABLE;
11801182

11811183
hashTypeInitIterator(o, &hi);
11821184
while (hashTypeNext(&hi) != C_ERR) {
11831185
/* Extract a field-value pair from an original hash object.*/
11841186
sds field = hashTypeCurrentFromHashTable(&hi, OBJ_HASH_FIELD);
11851187
sds value = hashTypeCurrentFromHashTable(&hi, OBJ_HASH_VALUE);
1186-
1188+
long long expiry = hashTypeEntryGetExpiry(hi.next);
11871189
/* Add a field-value pair to a new hash object. */
1188-
hashTypeEntry *entry = hashTypeCreateEntry(field, sdsdup(value), EXPIRY_NONE);
1190+
hashTypeEntry *entry = hashTypeCreateEntry(field, sdsdup(value), expiry);
11891191
hashtableAdd(ht, entry);
1192+
if (expiry != EXPIRY_NONE)
1193+
hashTypeTrackEntry(hobj, entry);
11901194
}
11911195
hashTypeResetIterator(&hi);
1192-
hobj = createObject(OBJ_HASH, ht);
1193-
hobj->encoding = OBJ_ENCODING_HASHTABLE;
11941196
} else {
11951197
serverPanic("Unknown hash encoding");
11961198
}

0 commit comments

Comments
 (0)