Closed (fixed)
Project:
Memcache API and Integration
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
28 Mar 2008 at 15:21 UTC
Updated:
9 Jul 2010 at 05:40 UTC
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
Comment #1
robertdouglass commentedOooh, that's a cool use. Do you have an API signature suggestion for this? Yes, we need simpletests, too.
Comment #2
robertdouglass commentedI think you have more goodies for us. Please share.
Comment #3
jeremy commentedYou'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.
Comment #4
chx commentedNote that "true locking" needs a lock daemon but yeah, a poor man's implementaiton can be done with add.
Comment #5
jeremy commentedAh, but memcached _is_ our lock daemon.
Comment #6
chx commentedJeremy, 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.
Comment #7
catchThis has been fixed - dmemcache_add() now in dmemcache.inc