예제 #1
0
 /**
  *
  * @param array $options
  */
 public function __construct(array $options = array())
 {
     if (!self::isAvailable()) {
         throw new RuntimeException('Unable to load Redis driver without PhpRedis extension.');
     }
     // Normalize Server Options
     if (isset($options['servers'])) {
         $servers = is_array($options['servers']) ? $options['servers'] : array($options['servers']);
         unset($options['servers']);
     } else {
         $servers = array(array('server' => '127.0.0.1', 'port' => '6379', 'ttl' => 0.1));
     }
     // Merge in default values.
     $options = array_merge($this->defaultOptions, $options);
     // this will have to be revisited to support multiple servers, using
     // the RedisArray object. That object acts as a proxy object, meaning
     // most of the class will be the same even after the changes.
     if (count($servers) == 1) {
         $server = $servers[0];
         $redis = new Redis();
         if (isset($server['socket']) && $server['socket']) {
             $redis->connect($server['socket']);
         } else {
             $port = isset($server['port']) ? $server['port'] : 6379;
             $ttl = isset($server['ttl']) ? $server['ttl'] : 0.1;
             $redis->connect($server['server'], $port, $ttl);
         }
         // auth - just password
         if (isset($options['password'])) {
             $redis->auth($options['password']);
         }
         $this->redis = $redis;
     } else {
         $serverArray = array();
         foreach ($servers as $server) {
             $serverString = $server['server'];
             if (isset($server['port'])) {
                 $serverString .= ':' . $server['port'];
             }
             $serverArray[] = $serverString;
         }
         $redis = new RedisArray($serverArray);
     }
     // select database
     if (isset($options['database'])) {
         $redis->select($options['database']);
     }
     $this->redis = $redis;
 }
예제 #2
0
파일: Redis.php 프로젝트: Twizanex/GuildWoW
 /**
  * Turns a key array into a key string. This includes running the indexing functions used to manage the Redis
  * hierarchical storage.
  *
  * When requested the actual path, rather than a normalized value, is returned.
  *
  * @param  array  $key
  * @param  bool   $path
  * @return string
  */
 protected function makeKeyString($key, $path = false)
 {
     $key = \Stash\Utilities::normalizeKeys($key);
     $keyString = 'cache:::';
     $pathKey = ':pathdb::';
     foreach ($key as $name) {
         //a. cache:::name
         //b. cache:::name0:::sub
         $keyString .= $name;
         //a. :pathdb::cache:::name
         //b. :pathdb::cache:::name0:::sub
         $pathKey = ':pathdb::' . $keyString;
         $pathKey = md5($pathKey);
         if (isset($this->keyCache[$pathKey])) {
             $index = $this->keyCache[$pathKey];
         } else {
             $index = $this->redis->get($pathKey);
             $this->keyCache[$pathKey] = $index;
         }
         //a. cache:::name0:::
         //b. cache:::name0:::sub1:::
         $keyString .= '_' . $index . ':::';
     }
     return $path ? $pathKey : md5($keyString);
 }
예제 #3
0
 /**
  * @param string $key
  * @return \Redis
  */
 protected function multi($key)
 {
     if ($this->redis instanceof \RedisArray) {
         $host = $this->redis->_target($key);
         return $this->redis->multi($host);
     }
     return $this->redis->multi();
 }
예제 #4
0
 public static function castRedisArray(\RedisArray $c, array $a, Stub $stub, $isNested)
 {
     $prefix = Caster::PREFIX_VIRTUAL;
     return $a + array($prefix . 'hosts' => $c->_hosts(), $prefix . 'function' => $c->_function());
 }