We are using add for semaphores. Very useful. Even if we don't, then here is something which tests your memcache install for correctness:

 $memcache = dmemcache_object('default'); 
echo "first add, should be TRUE"; 
var_dump($memcache->add('testlock', 1, 0, 5)); 
echo "second add, should be FALSE";
var_dump($memcache->add('testlock', 1, 0, 5)); 
sleep(6); 
echo "third add, should be TRUE"; 
var_dump($memcache->add('testlock', 1, 0, 5));

this needs to be changed to a simpletest later

Comments

robertdouglass’s picture

Oooh, that's a cool use. Do you have an API signature suggestion for this? Yes, we need simpletests, too.

robertdouglass’s picture

I think you have more goodies for us. Please share.

jeremy’s picture

Status: Needs review » Active

You're referring to adding dmemcache_add() to dmemcache.inc, correct? I'd like to see this too -- it is essential for true locking support. Not sure why this issue is marked as having a patch though. Moving it back to active. Patches welcome.

chx’s picture

Note that "true locking" needs a lock daemon but yeah, a poor man's implementaiton can be done with add.

jeremy’s picture

Ah, but memcached _is_ our lock daemon.

chx’s picture

Jeremy, while for example the stampede protection used add as a lock daemon, there is no protection in memcached against your cached object which happens to serve as a lock simply evicted -- of course, the lock objects are small, short lived and the LRU strategy employed by memcached makes this unlikely. However, that this can happen makes memcached unacceptable as a generic locking daemon.

catch’s picture

Status: Active » Fixed

This has been fixed - dmemcache_add() now in dmemcache.inc

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.