Fix errors in memcached implementation
This commit is contained in:
parent
e0998c27ff
commit
2f67aa9bc4
|
@ -88,7 +88,9 @@ class Memcached extends Cache implements IMemcache {
|
||||||
|
|
||||||
public function remove($key) {
|
public function remove($key) {
|
||||||
$result= self::$cache->delete($this->getNamespace() . $key);
|
$result= self::$cache->delete($this->getNamespace() . $key);
|
||||||
$this->verifyReturnCode();
|
if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) {
|
||||||
|
$this->verifyReturnCode();
|
||||||
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,10 +126,13 @@ class Memcached extends Cache implements IMemcache {
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param int $ttl Time To Live in seconds. Defaults to 60*60*24
|
* @param int $ttl Time To Live in seconds. Defaults to 60*60*24
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function add($key, $value, $ttl = 0) {
|
public function add($key, $value, $ttl = 0) {
|
||||||
$result = self::$cache->add($this->getPrefix() . $key, $value, $ttl);
|
$result = self::$cache->add($this->getPrefix() . $key, $value, $ttl);
|
||||||
$this->verifyReturnCode();
|
if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) {
|
||||||
|
$this->verifyReturnCode();
|
||||||
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +146,11 @@ class Memcached extends Cache implements IMemcache {
|
||||||
public function inc($key, $step = 1) {
|
public function inc($key, $step = 1) {
|
||||||
$this->add($key, 0);
|
$this->add($key, 0);
|
||||||
$result = self::$cache->increment($this->getPrefix() . $key, $step);
|
$result = self::$cache->increment($this->getPrefix() . $key, $step);
|
||||||
$this->verifyReturnCode();
|
|
||||||
|
if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +163,11 @@ class Memcached extends Cache implements IMemcache {
|
||||||
*/
|
*/
|
||||||
public function dec($key, $step = 1) {
|
public function dec($key, $step = 1) {
|
||||||
$result = self::$cache->decrement($this->getPrefix() . $key, $step);
|
$result = self::$cache->decrement($this->getPrefix() . $key, $step);
|
||||||
$this->verifyReturnCode();
|
|
||||||
|
if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,11 @@ abstract class Cache extends \Test_Cache {
|
||||||
$this->assertFalse($this->instance->hasKey('foo'));
|
$this->assertFalse($this->instance->hasKey('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRemoveNonExisting() {
|
||||||
|
$this->instance->remove('foo');
|
||||||
|
$this->assertFalse($this->instance->hasKey('foo'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testArrayAccessSet() {
|
public function testArrayAccessSet() {
|
||||||
$this->instance['foo'] = 'bar';
|
$this->instance['foo'] = 'bar';
|
||||||
$this->assertEquals('bar', $this->instance->get('foo'));
|
$this->assertEquals('bar', $this->instance->get('foo'));
|
||||||
|
@ -72,7 +77,9 @@ abstract class Cache extends \Test_Cache {
|
||||||
$this->assertEquals(1, $this->instance->inc('foo'));
|
$this->assertEquals(1, $this->instance->inc('foo'));
|
||||||
$this->assertEquals(1, $this->instance->get('foo'));
|
$this->assertEquals(1, $this->instance->get('foo'));
|
||||||
$this->assertEquals(2, $this->instance->inc('foo'));
|
$this->assertEquals(2, $this->instance->inc('foo'));
|
||||||
|
$this->assertEquals(2, $this->instance->get('foo'));
|
||||||
$this->assertEquals(12, $this->instance->inc('foo', 10));
|
$this->assertEquals(12, $this->instance->inc('foo', 10));
|
||||||
|
$this->assertEquals(12, $this->instance->get('foo'));
|
||||||
|
|
||||||
$this->instance->set('foo', 'bar');
|
$this->instance->set('foo', 'bar');
|
||||||
$this->assertFalse($this->instance->inc('foo'));
|
$this->assertFalse($this->instance->inc('foo'));
|
||||||
|
@ -80,7 +87,7 @@ abstract class Cache extends \Test_Cache {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDec() {
|
public function testDec() {
|
||||||
$this->assertEquals(false, $this->instance->dec('foo'));
|
$this->assertFalse($this->instance->dec('foo'));
|
||||||
$this->instance->set('foo', 20);
|
$this->instance->set('foo', 20);
|
||||||
$this->assertEquals(19, $this->instance->dec('foo'));
|
$this->assertEquals(19, $this->instance->dec('foo'));
|
||||||
$this->assertEquals(19, $this->instance->get('foo'));
|
$this->assertEquals(19, $this->instance->get('foo'));
|
||||||
|
|
Loading…
Reference in New Issue