gulaftab / redis

Automatically exported from code.google.com/p/redis
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

can "remove_if_empty" command setingg configurable ? #606

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
As we know ,since Redis 2.2 latter vesions,for a list that must be have at 
least 1 element , as lists that will reach zero elements are automatically 
removed.
but now we meet some issue in case of need an empty list,so i think if a 
possible way slove that,by add some configuration setting support. in my opion 
,if this setting is configurable,that will more smart and convinient for some 
supecial case like what i just mentioned. looking forward your response, any 
good suggestion or solution to this case is wellcome ,we like redis very much 
,a ha.. thanks

Original issue reported on code.google.com by jel...@gmail.com on 19 Jul 2011 at 8:40

GoogleCodeExporter commented 9 years ago
When a key is removed it becomes every type: GET replies with "nil", LLEN 
replies with 0, SCARD replies with 0, etc. The only difference is that EXISTS 
replies with 0, and the key doesn't appear in the result set of KEYS (since it 
doesn't exist...). This will not be made configurable, since it doesn't really 
serve a purpose in my opinion. Your application will have knowledge which keys 
map to which types, and is therefore likely to only call list commands against 
keys that are expected to hold a list. When this key doesn't exist, all 
commands reply with a value as if the list was empty. I think this should cover 
many, if not all use cases.

If you need to know if a key ever *existed* (note the past tense), you can work 
around this by setting another key to 1 or something like that. This can just 
act as a flag that you request every time you call a command against a list. 
When this replies with a 1, the key has existed in the past, otherwise it 
hasn't.

Original comment by pcnoordh...@gmail.com on 19 Jul 2011 at 8:58

GoogleCodeExporter commented 9 years ago
thks for your datail response,  but i thought there still something you might 
misunderstand of what i mentioned. 

we have a scenario like this :

like most applications ,we do a query operation with an empty table from 
database , that means none record come out.
so in this case we want to create an empty list to redis that can avoid access 
database every time but from redis, otherwise we will do the same query 
from database every time,as we know that is not a good solution. but now the 
issue is redis will automatically remove an empty list.    

in a word ,how can i keep a empty list in redis and it will not remove by redis 
but by manual ? hope this can help you known what i really means .

Original comment by jel...@gmail.com on 21 Jul 2011 at 3:06