Permalink
Browse files

allow dispatching of unknown methods to redis connection object

  • Loading branch information...
d1rk committed Sep 24, 2012
1 parent 73a07d8 commit 5ffd4da8734619e9fc566a7d422dea482eb84648
Showing with 33 additions and 0 deletions.
  1. +21 −0 storage/cache/adapter/Redis.php
  2. +12 −0 tests/cases/storage/cache/adapter/RedisTest.php
@@ -99,6 +99,27 @@ protected function _init() {
$this->connection->{$method}($ip, $port);
}
+ /**
+ * Dispatches a not-found method to the Redis connection object.
+ *
+ * That way, one can easily use a custom method on that redis adapter like that:
+ *
+ * {{{Cache::adapter('named-of-redis-config')->methodName($argument);}}}
+ *
+ * If you want to know, what methods are available, have a look at the readme of phprdis.
+ * One use-case might be to query possible keys, e.g.
+ *
+ * {{{Cache::adapter('redis')->keys('*');}}}
+ *
+ * @link https://github.com/nicolasff/phpredis GitHub: PhpRedis Extension
+ * @param string $method Name of the method to call
+ * @param array $params Parameter list to use when calling $method
+ * @return mixed Returns the result of the method call
+ */
+ public function __call($method, $params = array()) {
+ return call_user_func_array(array(&$this->connection, $method), $params);
+ }
+
/**
* Sets expiration time for cache keys
*
@@ -390,6 +390,18 @@ public function testIncrementNonIntegerValue() {
$result = $this->_redis->delete($key);
$this->assertTrue($result);
}
+
+ public function testMethodDispatch() {
+
+ $this->_redis->flushdb();
+ $this->_redis->set('some_key', 'somevalue');
+
+ $result = $this->redis->keys('*');
+ $this->assertEqual($result, array('some_key'), 'redis method dispatch failed');
+
+ $result = $this->redis->info();
+ $this->assertTrue(is_array($result), 'redis method dispatch failed');
+ }
}
?>

0 comments on commit 5ffd4da

Please sign in to comment.