summaryrefslogtreecommitdiff
path: root/src/defrag.c
diff options
context:
space:
mode:
authorViktor Söderqvist <viktor.soderqvist@est.tech>2022-11-09 18:50:07 +0100
committerGitHub <noreply@github.com>2022-11-09 19:50:07 +0200
commit4e472a1a7fc0dc2c7da2b48ac7342e9385b4f92a (patch)
tree62715e6a8fb51264449aa6ef0866f92d9d1e00bf /src/defrag.c
parent07d187066a86a9a3124af740373bf5bf49e345ff (diff)
downloadredis-4e472a1a7fc0dc2c7da2b48ac7342e9385b4f92a.tar.gz
Listpack encoding for sets (#11290)
Small sets with not only integer elements are listpack encoded, by default up to 128 elements, max 64 bytes per element, new config `set-max-listpack-entries` and `set-max-listpack-value`. This saves memory for small sets compared to using a hashtable. Sets with only integers, even very small sets, are still intset encoded (up to 1G limit, etc.). Larger sets are hashtable encoded. This PR increments the RDB version, and has an effect on OBJECT ENCODING Possible conversions when elements are added: intset -> listpack listpack -> hashtable intset -> hashtable Note: No conversion happens when elements are deleted. If all elements are deleted and then added again, the set is deleted and recreated, thus implicitly converted to a smaller encoding.
Diffstat (limited to 'src/defrag.c')
-rw-r--r--src/defrag.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/defrag.c b/src/defrag.c
index ced4fd20a..e78c07929 100644
--- a/src/defrag.c
+++ b/src/defrag.c
@@ -874,10 +874,12 @@ long defragKey(redisDb *db, dictEntry *de) {
} else if (ob->type == OBJ_SET) {
if (ob->encoding == OBJ_ENCODING_HT) {
defragged += defragSet(db, de);
- } else if (ob->encoding == OBJ_ENCODING_INTSET) {
- intset *newis, *is = ob->ptr;
- if ((newis = activeDefragAlloc(is)))
- defragged++, ob->ptr = newis;
+ } else if (ob->encoding == OBJ_ENCODING_INTSET ||
+ ob->encoding == OBJ_ENCODING_LISTPACK)
+ {
+ void *newptr, *ptr = ob->ptr;
+ if ((newptr = activeDefragAlloc(ptr)))
+ defragged++, ob->ptr = newptr;
} else {
serverPanic("Unknown set encoding");
}