Skip to content

Commit 5402c42

Browse files
committed
added noeviction policy to redis maxmemory. ZSCORE removed from the list of commands that can't be called when we are low on memory, this command was added in the past for a stupid error.
1 parent 240f8db commit 5402c42

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

redis.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ slave-serve-stale-data yes
191191
# volatile-random -> remove a random key with an expire set
192192
# allkeys->random -> remove a random key, any key
193193
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
194+
# noeviction -> don't expire at all, just return an error on write operations
195+
#
196+
# Note: with all the kind of policies, Redis will return an error on write
197+
# operations, when there are not suitable keys for eviction.
198+
#
199+
# At the date of writing this commands are: set setnx setex append
200+
# incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
201+
# sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
202+
# zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
203+
# getset mset msetnx exec sort
204+
#
205+
# The default is:
194206
#
195207
# maxmemory-policy volatile-lru
196208

src/config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ void loadServerConfig(char *filename) {
136136
server.maxmemory_policy = REDIS_MAXMEMORY_ALLKEYS_LRU;
137137
} else if (!strcasecmp(argv[1],"allkeys-random")) {
138138
server.maxmemory_policy = REDIS_MAXMEMORY_ALLKEYS_RANDOM;
139+
} else if (!strcasecmp(argv[1],"noeviction")) {
140+
server.maxmemory_policy = REDIS_MAXMEMORY_NO_EVICTION;
139141
} else {
140142
err = "Invalid maxmemory policy";
141143
goto loaderr;
@@ -307,6 +309,8 @@ void configSetCommand(redisClient *c) {
307309
server.maxmemory_policy = REDIS_MAXMEMORY_ALLKEYS_LRU;
308310
} else if (!strcasecmp(o->ptr,"allkeys-random")) {
309311
server.maxmemory_policy = REDIS_MAXMEMORY_ALLKEYS_RANDOM;
312+
} else if (!strcasecmp(o->ptr,"noeviction")) {
313+
server.maxmemory_policy = REDIS_MAXMEMORY_NO_EVICTION;
310314
} else {
311315
goto badfmt;
312316
}
@@ -440,6 +444,7 @@ void configGetCommand(redisClient *c) {
440444
case REDIS_MAXMEMORY_VOLATILE_RANDOM: s = "volatile-random"; break;
441445
case REDIS_MAXMEMORY_ALLKEYS_LRU: s = "allkeys-lru"; break;
442446
case REDIS_MAXMEMORY_ALLKEYS_RANDOM: s = "allkeys-random"; break;
447+
case REDIS_MAXMEMORY_NO_EVICTION: s = "noeviction"; break;
443448
default: s = "unknown"; break; /* too harmless to panic */
444449
}
445450
addReplyBulkCString(c,"maxmemory-policy");

src/redis.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct redisCommand readonlyCommandTable[] = {
124124
{"zcount",zcountCommand,4,0,NULL,1,1,1},
125125
{"zrevrange",zrevrangeCommand,-4,0,NULL,1,1,1},
126126
{"zcard",zcardCommand,2,0,NULL,1,1,1},
127-
{"zscore",zscoreCommand,3,REDIS_CMD_DENYOOM,NULL,1,1,1},
127+
{"zscore",zscoreCommand,3,0,NULL,1,1,1},
128128
{"zrank",zrankCommand,3,0,NULL,1,1,1},
129129
{"zrevrank",zrevrankCommand,3,0,NULL,1,1,1},
130130
{"hset",hsetCommand,4,REDIS_CMD_DENYOOM,NULL,1,1,1},
@@ -1332,6 +1332,8 @@ void monitorCommand(redisClient *c) {
13321332
void freeMemoryIfNeeded(void) {
13331333
/* Remove keys accordingly to the active policy as long as we are
13341334
* over the memory limit. */
1335+
if (server.maxmemory_policy == REDIS_MAXMEMORY_NO_EVICTION) return;
1336+
13351337
while (server.maxmemory && zmalloc_used_memory() > server.maxmemory) {
13361338
int j, k, freed = 0;
13371339

src/redis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
#define REDIS_MAXMEMORY_VOLATILE_RANDOM 2
210210
#define REDIS_MAXMEMORY_ALLKEYS_LRU 3
211211
#define REDIS_MAXMEMORY_ALLKEYS_RANDOM 4
212+
#define REDIS_MAXMEMORY_NO_EVICTION 5
212213

213214
/* We can print the stacktrace, so our assert is defined this way: */
214215
#define redisAssert(_e) ((_e)?(void)0 : (_redisAssert(#_e,__FILE__,__LINE__),_exit(1)))

0 commit comments

Comments
 (0)