12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace app\api\service;
- use think\cache\driver\Redis;
- class CacheService
- {
- /**
- * redis 实例
- *
- * @var think\cache\driver\Redis $redis
- */
- private $redis;
- public function __construct()
- {
- $this->redis = new Redis([ 'select'=> 2]);
- }
- /**
- * User: YunXi
- * Date: 2022-05-21
- * Time: 22:00
- * Notes: 设置自增
- *
- * @param [type] $name
- * @param integer $step
- * @return integer
- */
- public static function incr($name, $step = 1) :int
- {
- return (int) self::$redis->inc($name, $step);
- }
- /**
- * User: YunXi
- * Date: 2022-05-21
- * Time: 22:00
- * Notes: 设置过期时间
- *
- * @param [type] $key
- * @param [type] $ttl
- * @return void
- */
- public static function expire($key,$ttl)
- {
- return self::$redis->expire($key,$ttl);
- }
- /**
- * User: YunXi
- * Date: 2022-05-21
- * Time: 22:03
- * Notes: 删除锁
- *
- * @param string $key
- * @return void
- */
- public static function del($key)
- {
- return self::$redis->del($key);
- }
- }
|