根据key获取redis实例
这边还是用取模的方式，一致性hash用php实现性能开销过大。取模的方式对只有几台机器的情况足够用了
如果有集群需要，直接使用redis3.0+自带的集群功能就好了。不管是可用性还是性能都比用php自己实现好

@param $key

@return \Redis
519305
private function hash($key)
    {
        $serverNum = count($this->conf['server']);
        $success = sprintf('%u', crc32($key)) % $serverNum;

        if (!isset($this->redis[$success]) || !is_object($this->redis[$success])) {
            $instance = new \Redis();

            $connectToRedisFunction = function ($host, $port, $isPersistentConnect) use ($instance) {
                if ($isPersistentConnect) {
                    return $instance->pconnect($host, $port, 1.5);
                } else {
                    return $instance->connect($host, $port, 1.5);
                }
            };

            $isPersistentConnect = !(isset($this->conf['server'][$success]['pconnect']) && $this->conf['server'][$success]['pconnect'] === false);
            $connectResult = $connectToRedisFunction($this->conf['server'][$success]['host'], $this->conf['server'][$success]['port'], $isPersistentConnect);

            $failOver = null;

            if (!$connectResult && !empty($this->conf['back'])) {
                $failOver = $this->conf['back'];
                $isPersistentConnect = !(isset($failOver['pconnect']) && $failOver['pconnect'] === false);
                $connectResult = $connectToRedisFunction($failOver['host'], $failOver['port'], $isPersistentConnect);
            }

            if (!$connectResult && $serverNum > 1) {
                $failOver = $success + 1;
                $failOver >= $serverNum && $failOver = $success - 1;
                $failOver = $this->conf['server'][$failOver];
                $isPersistentConnect = !(isset($failOver['pconnect']) && $failOver['pconnect'] === false);
                $connectResult = $connectToRedisFunction($failOver['host'], $failOver['port'], $isPersistentConnect);
            }

            if (!$connectResult) {
                Plugin::hook('cml.cache_server_down', [$this->conf['server'][$success]]);

                throw new CacheConnectFailException(Lang::get('_CACHE_CONNECT_FAIL_', 'Redis',
                    $this->conf['server'][$success]['host'] . ':' . $this->conf['server'][$success]['port']
                ));
            }

            $password = false;
            if (is_null($failOver)) {
                if (isset($this->conf['server'][$success]['password']) && !empty($this->conf['server'][$success]['password'])) {
                    $password = $this->conf['server'][$success]['password'];
                }

                if ($password && !$instance->auth($password)) {
                    throw new \RuntimeException('redis password error!');
                }

                isset($this->conf['server'][$success]['db']) && $instance->select($this->conf['server'][$success]['db']);
            } else {
                if (isset($failOver['password']) && !empty($failOver['password'])) {
                    $password = $failOver['password'];
                }

                if ($password && !$instance->auth($password)) {
                    throw new \RuntimeException('redis password error!');
                }

                isset($failOver['db']) && $instance->select($failOver['db']);

                Log::emergency('redis server down', ['downServer' => $this->conf['server'][$success], 'failOverTo' => $failOver]);
                Plugin::hook('cml.redis_server_down_fail_over', ['downServer' => $this->conf['server'][$success], 'failOverTo' => $failOver]);
            }

            $instance->setOption(\Redis::OPT_PREFIX, $this->conf['prefix']);
            $this->redis[$success] = $instance;
        }
        return $this->redis[$success];
    }
348949
public function getRescTypesInUse($key=0)
	{
		$types = Resource::where('resources.show', 0)
		             ->rightJoin('config', 'resources.type', '=', 'config.id')
		             ->groupBy('resources.type')
		             ->distinct()
		             ->select('resources.type', 'config.name as typeName')
		             ->get();

		//$arr = [];
		$key === 1 ? $arr = [] : $arr = ['0'=>'不限类型'];

		if(count($types)){
			foreach ($types as $t) {
				$arr = array_add($arr, $t->type, $t->typeName);
			}
		}
		return $arr;
	}
1124353
public function delete($key)
    {
        $redis = is_object($this->_redis) ? $this->_redis : $this->_getRedis();
        $redis->delete($this->_prefix . $key);

        return $this;
    }
315835
public function do_get($key)
    {
        $redis = is_object($this->_redis) ? $this->_redis : $this->_getRedis();
        return $redis->get($this->_prefix . $key);
    }
694453
public function lget($key, $index)
    {
        try {
            return $this->redis->lget($key, $index);
        } catch (\RedisException $e) {
            die("Error!: " . $e->getMessage() . "<br/>");
        }
    }
1136506
public function get($key)
    {
        $response = $this->dynamo->getItem([
            'TableName' => $this->table,
            'ConsistentRead' => false,
            'Key' => [
                $this->keyAttribute => [
                    'S' => $this->prefix.$key,
                ],
            ],
        ]);

        if (! isset($response['Item'])) {
            return;
        }

        if ($this->isExpired($response['Item'])) {
            return;
        }

        if (isset($response['Item'][$this->valueAttribute])) {
            return $this->unserialize(
                $response['Item'][$this->valueAttribute]['S'] ??
                $response['Item'][$this->valueAttribute]['N'] ??
                null
            );
        }
    }
317406
public function get($key)
    {
        $fileName = $this->getFileName($key);
        if (!is_file($fileName)) {
            if ($this->lock) {
                $this->lock = false;
                $this->set($key, 0);
                return 0;
            }
            return false;
        }
        $fp = fopen($fileName, 'r+');
        if ($this->lock) {//自增自减  上锁
            $this->lock = $fp;
            if (flock($fp, LOCK_EX) === false) return false;
        }
        $data = fread($fp, filesize($fileName));
        $this->lock || fclose($fp);//非自增自减操作时关闭文件
        if ($data === false) {
            return false;
        }
        //缓存过期
        $fileTime = substr($data, 13, 10);
        $pos = strpos($data, ')');
        $cacheTime = substr($data, 24, $pos - 24);
        $data = substr($data, $pos + 1);
        if ($cacheTime == 0) return unserialize($data);

        if (Cml::$nowTime > (intval($fileTime) + intval($cacheTime))) {
            unlink($fileName);
            return false;//缓存过期
        }
        return unserialize($data);
    }
461551
public function ssize($key)
    {
        try {
            return $this->redis->ssize($key);
        } catch (\RedisException $e) {
            die("Error!: " . $e->getMessage() . "<br/>");
        }
    }
877002
public static function unlock($key) {
        /* @var $cache RedisCache */
        $cache = Pool::get(CacheInterface::class);
        try {
            $ok = false;
            if ($cache instanceof RedisCache) {
                $cache->open();
                $redis = $cache->redis;
                $script = "local v = redis.call('get', KEYS[1]) if(v==false) then return 1 end if ( v== 
            ARGV[1]) then 
            return redis.call('del', KEYS[1]) end if(string.find (v, 'lock_')==1) then return 0 end   
            v=tonumber(v)  v=v-1 if(v==0) then return redis.call('del', KEYS[1]) else return redis.call('set',KEYS[1],v) end";
                $ok = $redis->eval($script, ["_RedisLocker_$key", 'lock_' . Context::id()], 1);
                $ok = $ok ? true : false;
            }
            Pool::release($cache);
        } catch (\RuntimeException $e) {
            Pool::release($cache);
            throw $e;
        } catch (\Error $e) {
            Pool::release($cache);
            throw $e;
        }
        return $ok;
    }
371088
private function key_to_hash($key)
    {
        if (null === $key) {
            $hash = 'null';

        } else if (is_int($key)) {
            $hash = $key;

        } else if (is_float($key)) {
            $hash = "f_$key";

        } else if (is_bool($key)) {
            $hash = "b_$key";

        } else if (is_string($key)) {
            $hash = "s_$key";

        } else if (is_object($key) || is_callable($key)) {
            $hash = spl_object_hash($key);

        } else if (is_array($key)) {
            $hash = 'a_' . md5(json_encode($key));

        } else if (is_resource($key)) {
            $hash = "r_$key";

        } else {
            throw new \InvalidArgumentException(sprintf(
                'Unsupported key type "%s"',
                gettype($key)
            ));
        }

        $this->map_hash_to_key[$hash] = $key;
        return $hash;
     }
650942
public function lpop($key)
    {
        try {
            return $this->redis->lpop($key);
        } catch (\RedisException $e) {
            die("Error!: " . $e->getMessage() . "<br/>");
        }
    }
189439
public static function get($key,$config)
    {
        static::initRedis();
        /**
         * 确定key
         */
        static::$key = $key;
        if(is_array($key) && count($key) == 2){
            static::$group = $key[0];
            static::$key = $key[1];
        }
        static::$md5key =  md5(static::$key );
        $returnData = unserialize(static::$Redis->get('cache_'.static::$typeCache.'_'.static::$group.'_'.static::$md5key));
        static::staticEmpty();
        return $returnData;

    }
174535
public function hashKey( $key = null ) {
		$key = $key ? $this->sanitizeKey( $key ) : $this->getKey();
		return md5( $key );
	}
940468
public function get($key)
    {
        $entry = $this->redis->hGet($this->cacheKey, $key);

        if ($entry) {
            $entry = unserialize($entry);

            if ($entry['expire']) {
                // Check expires
                $now = new \DateTime('now', new \DateTimeZone('UTC'));
                if ((int) $now->format('U') > $entry['expire']) {
                    $this->remove($key);

                    return null;
                }
            }

            return $entry['value'];
        }

        return null;
    }
1082956
public function normalizeKey($key)
    {
        $key = strtolower($key);
        $key = str_replace(array('-', '_'), ' ', $key);
        $key = preg_replace('#^http #', '', $key);
        $key = ucwords($key);
        $key = str_replace(' ', '-', $key);

        return $key;
    }
906714
public function get($key)
    {
        $value  = $this->redisServer->getHashClient($key)->get($key);

        if (false !== $value) {
            return is_numeric($value) ? $value : unserialize($value);
        }

        return null;
    }
21708
public function hasConfig(string $key)
    {
        $redis = $this->getDI()->getRedis();
        $hashKey = $this->getNotificationKey(); //'user_notifications_'.$this->user_id;

        return $redis->hGet($hashKey, $key);
    }