Lachim / redis

Automatically exported from code.google.com/p/redis
2 stars 0 forks source link

Counting semaphores! #172

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
New commands:

LNPUSH key n value
RNPUSH key n value
to add n times value in key

LNPOP key n
RNPOP key n
to remove and return n values in key

BLNPOP key1 key2 ... keyN n timeout
BRNPOP key1 key2 ... keyN n timeout
blocking equivs

Counting semaphores:
* S, the semaphore value:
  LLEN key
* V (to provide # resources):
  LNPUSH key # myref
* P (to consume # resources):
  BRNPOP key #

If anyone knows how to do counting semaphores with the existing codebase, 
or has a better idea on how to implement them, I'd love to be corrected!

For non-counting semaphores, a trivial solution:
* S:
  LLEN key
* V:
  LPUSH key myref
* P:
  BRPOP key

Original issue reported on code.google.com by geoffroy...@gmail.com on 1 Mar 2010 at 1:53

GoogleCodeExporter commented 8 years ago
A cheaper alternative in term of memory usage:

M(INCR|DECR)(BY|) equivalents to (INCR|DECR)(BY|) by monitored by operators 
such as 
the following.

BCDECR key (Blocking Conditional DECRease)
decreases $key by 1 and returns as soon as M(INCR|DECR)(BY|) is called on the 
key and
$key > 0

BCDECRBY key value
decreases $key by $value and returns as soon as M(INCR|DECR)(BY|) is called on 
the 
key and $key >= $value

Original comment by geoffroy...@gmail.com on 1 Mar 2010 at 2:01

GoogleCodeExporter commented 8 years ago
perhaps the new MULTI/EXEC/WATCH semantics is able to implement this client 
side without race conditions?

Cheers,
Salvatore

Original comment by anti...@gmail.com on 24 Aug 2010 at 2:18