64 lines
1.4 KiB
PHP
Raw Normal View History

2020-06-30 17:42:07 +08:00
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
2020-06-30 18:06:01 +08:00
namespace catcher\library\rate;
2020-06-30 17:42:07 +08:00
use think\facade\Cache;
2020-06-30 18:06:01 +08:00
trait Redis
2020-06-30 17:42:07 +08:00
{
2020-07-02 17:28:01 +08:00
/**
* @var \Redis
*/
2020-06-30 18:06:01 +08:00
protected $redis = null;
2020-06-30 17:42:07 +08:00
2020-07-02 17:28:01 +08:00
/**
* 返回 redis
*
* @time 2020年07月02日
* @return \Redis
*/
protected function getRedis(): \Redis
2020-06-30 17:42:07 +08:00
{
2020-06-30 18:06:01 +08:00
if (!$this->redis) {
$this->redis = Cache::store('redis')->handler();
2020-06-30 17:42:07 +08:00
}
2020-06-30 18:06:01 +08:00
return $this->redis;
2020-06-30 17:42:07 +08:00
}
2020-06-30 18:06:01 +08:00
/**
* 设置 ttl
*
* @time 2020年06月30日
* @param $ttl
* @return $this
*/
public function ttl($ttl)
{
$this->ttl = $ttl;
2020-06-30 17:42:07 +08:00
2020-06-30 18:06:01 +08:00
return $this;
}
2020-06-30 17:42:07 +08:00
2020-06-30 18:06:01 +08:00
/**
* 设置限制次数
*
* @time 2020年06月30日
* @param $limit
* @return $this
*/
public function limit($limit)
2020-06-30 17:42:07 +08:00
{
2020-06-30 18:06:01 +08:00
$this->limit = $limit;
return $this;
2020-06-30 17:42:07 +08:00
}
}