hyperf-chat/app/Cache/Repository/RedisTrait.php

64 lines
1003 B
PHP
Raw Normal View History

2021-05-20 16:53:34 +08:00
<?php
namespace App\Cache\Repository;
use Hyperf\Redis\Redis;
trait RedisTrait
{
private static $instance;
/**
* 获取单例
*
* @return static
*/
static public function getInstance()
{
if (!(self::$instance instanceof static)) {
self::$instance = new static();
}
return self::$instance;
}
/**
* 获取 Redis 连接
*
* @return Redis|mixed
*/
protected function redis()
{
return redis();
}
/**
* 获取缓存 KEY
*
* @param string $key
* @return string
*/
private function getCacheKey(string $key)
{
return sprintf('%s:%s', trim($this->prefix, ':'), trim($key, ':'));
}
/**
* 获取缓存 KEY
*
* @return string
*/
2021-05-20 22:23:48 +08:00
protected function getKeyName()
2021-05-20 16:53:34 +08:00
{
return $this->getCacheKey($this->name);
}
/**
* 加载数据到缓存
*/
public function reload()
{
}
}