hufei01 / redis

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

Cannot create empty set/list without workarounds #230

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. r.exists 'foo' => false
2. r.sadd 'foo', 1 => [1]
3. r.srem 'foo', 1 => []
4. r.exists 'foo' => true

What do you see instead?
1. r.exists 'foo' => false
2. r.stouch 'foo' => []
3. r.exists 'foo' => true

What version of the product are you using? On what operating system?
Redis v1.2.6/Ruby (ezmobius-redis) on Kubuntu 9.04

Please provide any additional information below.
Here's another example:

function get_cached_item_count() {
  if !redis.exists 'foo' {
    // without redis.stouch 'foo' here, the following loop will be
    // executed over and over, if source is empty
    foreach (item in source) redis.sadd 'foo', item.id
  }
  redis.scard 'foo'
}

I really don't see why there can be an empty set cached, but no means to
start with it.

Original issue reported on code.google.com by kruk...@gmail.com on 20 Apr 2010 at 2:47

GoogleCodeExporter commented 9 years ago
In that last example consider "source" an SQL query

Original comment by kruk...@gmail.com on 20 Apr 2010 at 2:49

GoogleCodeExporter commented 9 years ago
Now it's not possible at all to create empty aggregate objects... so it can't 
be done by design :)

Original comment by anti...@gmail.com on 26 Apr 2010 at 6:34

GoogleCodeExporter commented 9 years ago

Original comment by anti...@gmail.com on 27 Aug 2010 at 11:23

GoogleCodeExporter commented 9 years ago
This is obnoxoius. An empty set is *different* from a non-existent one.  
Consider { x | x < 10 and x > 11 } vs the { x | x is an element of the set of 
keys I haven't cached yet }.

Original comment by cpf...@valetude.com on 23 Sep 2014 at 5:14

GoogleCodeExporter commented 9 years ago
How, specifically, is the behaviour of an existing but empty set different from 
a nonexistent set that behaves as though it is empty?

You can of course check key existence if desired, or you could add a dummy 
sentinel value. But I confess to not being very clear on how it is "obnoxious". 
Your example doesn't clarify it, IMO.

Original comment by marc.gravell on 23 Sep 2014 at 5:24

GoogleCodeExporter commented 9 years ago
This google code project is not in use anymore. Please report bugs to 
https://github.com/antirez/redis. 

Also I'm not even sure I get your point with the examples. If you want to 
discuss this further try asking on the mailing list or in the IRC channel.

Original comment by jeredi...@gmail.com on 23 Sep 2014 at 5:25