From ab5f20d19ce44a1279f94ccaf44c3c1c95cf2e94 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 18 Jul 2014 10:09:51 +0200 Subject: [PATCH] tryObjectEncoding(): use shared objects with maxmemory and non-LRU policy. In order to make sure every object has its own private LRU counter, when maxmemory is enabled tryObjectEncoding() does not use the pool of shared integers. However when the policy is not LRU-based, it does not make sense to do so, and it is much better to save memory using shared integers. --- src/object.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/object.c b/src/object.c index 96747fa1..56528690 100644 --- a/src/object.c +++ b/src/object.c @@ -325,7 +325,11 @@ robj *tryObjectEncoding(robj *o) { * Note that we also avoid using shared integers when maxmemory is used * because every object needs to have a private LRU field for the LRU * algorithm to work well. */ - if (server.maxmemory == 0 && value >= 0 && value < REDIS_SHARED_INTEGERS) { + if ((server.maxmemory == 0 || + (server.maxmemory_policy != REDIS_MAXMEMORY_VOLATILE_LRU && + server.maxmemory_policy != REDIS_MAXMEMORY_ALLKEYS_LRU)) && + value >= 0 && value < REDIS_SHARED_INTEGERS) + { decrRefCount(o); incrRefCount(shared.integers[value]); return shared.integers[value]; -- GitLab