I have a caching solution set up where I would like to set the eviction policy of a particular hash to be "noeviction" at certain times in case the source of data for that hash goes down. Is this possible in redis?

Essentially my question is if I can protect all the entries belonging to a specific hash from being evicted, at certain times on demand.

Comment From: sundb

hi @Rahul-98a , redis dose not support this right now, but you can run a cron task to execute config set maxmemory-policy noeviction, which will disable eviction.

Comment From: anandrahul604

hi @Rahul-98a , redis dose not support this right now, but you can run a cron task to execute config set maxmemory-policy noeviction, which will disable eviction.

@sundb But doing this would result in the noneviction policy being applied to the entire cache (i.e. all my hashes) correct? I'm looking to apply the noeviction policy to a specific hash, such that all the key-value pairs under that hash are not available for eviction.

Comment From: sundb

@Rahul-98a It is not possible to specify db for eviction or disable eviction.

Comment From: iakkus

Does a volatile eviction policy pick entries according to their TTLs left? For example, entries to expire soon will be more likely to be evicted.

Comment From: iakkus

Actually, regardless of how the volatile eviction policies work, you could try doing the following:

1) use a volatile eviction policy 2) set a default ttl for your keys 3) if the source of a key goes down, disable its ttl 4) when the source of a key comes back up, set the ttl again

Comment From: sundb

@iakkus This is theoretically possible, but it is too cumbersome and prone to problems. For example, when there is amount of keys, we need to traverse all the keys to set the ttl.

Comment From: anandrahul604

@iakkus This is theoretically possible, but it is too cumbersome and prone to problems. For example, when there is amount of keys, we need to traverse all the keys to set the ttl.

@sundb @iakkus We can set the TTL at just the top level hash correct, then it will apply to all keys under that hash?

Comment From: sundb

@iakkus This is theoretically possible, but it is too cumbersome and prone to problems. For example, when there is amount of keys, we need to traverse all the keys to set the ttl.

@sundb @iakkus We can set the TTL at just the top level hash correct, then it will apply to all keys under that hash?

Yes, The hash keys are not ttl.

Comment From: iakkus

@Rahul-98a yes, the TTL works at the level of the key, so the TTL will apply to the entire hash (in fact, you cannot set a TTL to individual fields in a hash).

@sundb I guess you are referring to the eviction policy selection probability? I agree; that would be too cumbersome to do every time keys need to be expired.