123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace app\common\server;
- use Psr\SimpleCache\InvalidArgumentException;
- /**
- * excel导出
- *
- * @Author wj
- * @DateTime 2022-10-02
- * @Describe
- */
- class Redis
- {
- private $redis;
- public function __construct()
- {
- $this->redis = new \Redis();
- //docker redis1 6379
- $this->redis->connect('127.0.0.1', 6379);
- //$this->redis->auth("qwe110110");
- $this->redis->auth("zhonghui0123");
- $this->redis->select("1"); //选择1号数据库 默认0号
- if (!$this->redis->ping()) {
- $error = "connect error";
- throw new InvalidArgumentException($error);
- //throw new \Exception("链接失败");
- }
- }
- public function get($key, $default = null)
- {
- $value = $this->redis->get($key);
- return $value;
- //throw new InvalidArgumentException($error);
- }
- public function set($key, $value, $ttl = null)
- {
- $this->redis->set($key, $value);
- //throw new InvalidArgumentException($error);
- return true;
- }
- public function delete($key)
- {
- $this->redis->del($key);
- return true;
- //throw new InvalidArgumentException($error);
- }
- public function has($key)
- {
- return $this->redis->exists($key);
- //throw new InvalidArgumentException($error);
- }
- }
|