First of all: thank you, you are doing a great job with redis!
Now, my questiong. I'm developing a webpage using redis. I need to
store fixed-length arrays (I need to store an integer value for each
day in a month). And I just need to increment the values from time to
time. I'm thinking about which is the best way to implement this in
redis. My thoughts are:
- Using a string with a specific format. For example a basic example
would be: "1,2,3,4,...". This is the option I have already
implemented. The problem is that I need to do a few steps: read,
parse, write. This option could be improved using different ways to
encode the integers.
- Using a list.
- Using a key-value for each integer value. I don't like it: too many
keys. But is good because I could use incrby.
I think using a list would be the best option, but it would be great
to be able to:
- incr an element in the list, so there is not need to read it from
the code. Maybe a "lincrby" command?
- create a list with a number of elements all having the same value.
For example I would create a list of 30 elements having "0" as value.
Well, I can just call rpush several times.
In the other hand I don't know if using a list adds too much overhead
than using a simple encoded string value.
Any suggestion? Thank you very much.
---
Alberto Gimeno Brieba
http://www.google.com/profiles/gimenete
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.
If you're using 2.2, then you can use WATCH together with GETRANGE and
SETRANGE to store everything in a single key:
WATCH foo
value = GETRANGE foo, 0, 0
value = value + increment
MULTI
SETRANGE foo, 0, value
EXEC
An implementation in Ruby: https://gist.github.com/756126
Nevertheless having a command like HINCRBY, I wonder if it is possible
to have a similar command for lists in a future release of redis. I
think this would be the best approach in this case.
Thanks again!
---
Alberto Gimeno Brieba
http://www.google.com/profiles/gimenete