New issue 419 by gimenete: Increment element in a list: LINCRBY command
http://code.google.com/p/redis/issues/detail?id=419
This is a feature request.
A command similar to "HINCRBY key field increment" but for lists.
Suggestion:
LINCRBY key index increment
i gues u dont have POS of element u would incr/decr +/- N
so... its a bit difficult? ;)
Comment #2 on issue 419 by pcnoordhuis: Increment element in a list:
LINCRBY command
http://code.google.com/p/redis/issues/detail?id=419
This would only make sense for static lists, which is an uncommon use case
for Redis lists. Lists are more often used for rapidly changing contents.
You need to know in advance which element the INCR is done on, which is
hard to tell without first pulling a few values from the list when the
contents changes. Doing exactly this is already possible in Redis using
optimistic locking with WATCH:
WATCH list
value = LINDEX list 9 # Returns 10th element
if value == what_you_expect
MULTI
LSET list 9 value+1
EXEC
else
UNWATCH
end
If the indices of a list are static and you know in advance how many
elements you store inside that list, you can also choose to use the hash
type for storing this "list". Because you know it is static, the element
indices are the implicit ordering, so you can use an unordered type to
simulate a (static) list:
HSET hash 0 value1 # Index 0
HSET hash 1 value2 # Index 1
HINCRBY hash 0 1 # Increment element at key "0" (which in this case is
your index)
Because there already are ways in Redis to solve this, I'm closing this
feature request.
Hi,
I think the use of static lists can be very common. For example I need to
handle calendars. A calendar is a fixed-length number of days. Almost
anything in the application I'm building are calendars, because what I need
is to track statistics in time.
Thanks anyway. You are doing a great work.