| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop100%开源免费商用商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | 商业版本务必购买商业授权,以免引起法律纠纷
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshopTeam
- // +----------------------------------------------------------------------
- namespace app\common\cache;
- use think\facade\Cache;
- /**
- * 聊天缓存
- * Class ChatTokenCache
- * @package app\common\cache
- */
- class ChatCache
- {
- private $redis;
- public function __construct()
- {
- $this->redis = Cache::store('redis')->handler();
- }
- /**
- * @notes 设置缓存
- * @param $key
- * @param $val
- * @param null $time
- * @return false
- * @author 段誉
- * @date 2021/12/20 12:13
- */
- public function set($key, $val, $time = null)
- {
- if (empty($key)) {
- return false;
- }
- return $this->redis->set($key, $val, $time);
- }
- /**
- * @notes 获取缓存
- * @param $key
- * @return false
- * @author 段誉
- * @date 2021/12/20 12:14
- */
- public function get($key)
- {
- if (empty($key)) {
- return false;
- }
- return $this->redis->get($key);
- }
- /**
- * @notes 删除指定
- * @param $key
- * @return mixed
- * @author 段誉
- * @date 2021/12/20 12:02
- */
- public function del($key)
- {
- return $this->redis->del($key);
- }
- /**
- * @notes 清空
- * @return mixed
- * @author 段誉
- * @date 2021/12/20 12:02
- */
- public function flashAll()
- {
- return $this->redis->flushAll();
- }
- /**
- * @notes 获取集合
- * @param $key
- * @return mixed
- * @author 段誉
- * @date 2021/12/20 12:11
- */
- public function sMembers($key)
- {
- return $this->redis->sMembers($key);
- }
- /**
- * @notes 设置缓存时间
- * @param $key
- * @param $ttl
- * @return mixed
- * @author 段誉
- * @date 2021/12/20 12:02
- */
- public function expire($key, $ttl)
- {
- return $this->redis->expire($key, $ttl);
- }
- /**
- * @notes 向集合添加成员
- * @param $key
- * @param $val
- * @return mixed
- * @author 段誉
- * @date 2021/12/20 12:04
- */
- public function sadd($key, $val)
- {
- return $this->redis->sAdd($key, $val);
- }
- /**
- * @notes 移除集合成员
- * @param $key
- * @param $val
- * @return mixed
- * @author 段誉
- * @date 2021/12/20 12:04
- */
- public function srem($key, $val)
- {
- return $this->redis->sRem($key, $val);
- }
- /**
- * @notes 对象转数组
- * @param $key
- * @return array|false
- * @author 段誉
- * @date 2021/12/20 12:03
- */
- public function getSmembersArray($key)
- {
- $res = $this->sMembers($key);
- if (is_object($res)) {
- return (array)$res;
- }
- return $res;
- }
- /**
- * @notes 相似keys
- * @param $prefix
- * @return mixed
- * @author 段誉
- * @date 2021/12/20 12:02
- */
- public function keys($prefix)
- {
- return $this->redis->keys($prefix.'*');
- }
- }
|