chnaghong1990 / redis

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

automatic removal of the hash value after the assignment 0 #634

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Imagine that we have a list of sites that are referenced:
> hincrby links google.com 1
(integer) 1
> hincrby links facebook.com 1
(integer) 1
> hgetall links
1) "google.com"
2) "1"
3) "facebook.com"
4) "1"
> hincrby links google.com -1
(integer) 0

But we have removed the page with a link to google.com and we need to have the 
actual list of references.
Now we get usless list becouse we don't have links to google.com

> hgetall links
1) "google.com"
2) "0"
3) "facebook.com"
4) "1"

And after each hincrby command we have 3 steps for delete obsolete data

1) > hget links google.com
"0"
2) check answer and then
3) > hdel links google.com
(integer) 1

But if redis itself removed the zero values it would be fine and it seems to me 
a very logical.

Original issue reported on code.google.com by DimaBoch...@gmail.com on 17 Aug 2011 at 8:16

GoogleCodeExporter commented 8 years ago
Sorry i don't no how to change Type of issue

Original comment by DimaBoch...@gmail.com on 17 Aug 2011 at 8:19

GoogleCodeExporter commented 8 years ago
Zero is a valid value in a hash or as a plain key in Redis.

If you want a one round-trip method of handling those kinds of things, you can 
use a zset, calling "zremrangebyscore links -inf 0" to remove links with scores 
<= 0.

Original comment by josiah.c...@gmail.com on 17 Aug 2011 at 5:37

GoogleCodeExporter commented 8 years ago
oh, thanks for this, i apologies for this issue.

Original comment by DimaBoch...@gmail.com on 17 Aug 2011 at 5:42

GoogleCodeExporter commented 8 years ago

Original comment by pcnoordh...@gmail.com on 18 Aug 2011 at 8:42