hiddenid01 / redis

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

Increment element in a list: LINCRBY command #419

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is a feature request.

A command similar to "HINCRBY key field increment" but for lists.

Suggestion:
LINCRBY key index increment

Original issue reported on code.google.com by gimen...@gmail.com on 27 Dec 2010 at 5:28

GoogleCodeExporter commented 9 years ago
i gues u dont have POS of element u would incr/decr +/- N
so... its a bit difficult? ;)

Original comment by anisourc...@gmail.com on 28 Dec 2010 at 5:22

GoogleCodeExporter commented 9 years ago
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.

Original comment by pcnoordh...@gmail.com on 28 Dec 2010 at 7:18

GoogleCodeExporter commented 9 years ago
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.

Original comment by gimen...@gmail.com on 28 Dec 2010 at 9:07