Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow dispatching of unknown methods to redis connection object

  • Loading branch information...
commit 7e1e6be96aca88496640696c383df5eb51990d5a 1 parent 73a07d8
@d1rk authored
Showing with 36 additions and 0 deletions.
  1. +36 −0 storage/cache/adapter/Redis.php
View
36 storage/cache/adapter/Redis.php
@@ -100,6 +100,42 @@ protected function _init() {
}
/**
+ * 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()) {
+ switch (count($params)) {
+ case 0:
+ return $this->connection->{$method}();
+ case 1:
+ return $this->connection->{$method}($params[0]);
+ case 2:
+ return $this->connection->{$method}($params[0], $params[1]);
+ case 3:
+ return $this->connection->{$method}($params[0], $params[1], $params[2]);
+ case 4:
+ return $this->connection->{$method}($params[0], $params[1], $params[2], $params[3]);
+ case 5:
+ return $this->connection->{$method}($params[0], $params[1], $params[2], $params[3], $params[4]);
+ default:
+ return call_user_func_array(array(&$this->connection, $method), $params);
+ }
+ }
+
+ /**
* Sets expiration time for cache keys
*
* @param string $key The key to uniquely identify the cached item
Please sign in to comment.
Something went wrong with that request. Please try again.