From 54ebabc65fea561d2c07f80d2dbc00fd6ac6ccc0 Mon Sep 17 00:00:00 2001
From: Hmm <919556520@qq.com>
Date: Wed, 15 Apr 2020 16:01:09 +0800
Subject: [PATCH 1/2] Signed-off-by: Hmm <919556520@qq.com>
---
.idea/workspace.xml | 90 ++++++++++++++++++++++++++++++++++++++
lyapi/cache/Cache.php | 56 ++++++++++++++++++++++++
lyapi/cache/FileCache.php | 41 ++++++++++++++++-
lyapi/cache/RedisCache.php | 66 ++++++++++++++++++++++++++--
4 files changed, 249 insertions(+), 4 deletions(-)
create mode 100644 .idea/workspace.xml
create mode 100644 lyapi/cache/Cache.php
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..7718861
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $PROJECT_DIR$/composer.json
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1586933408279
+
+
+ 1586933408279
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lyapi/cache/Cache.php b/lyapi/cache/Cache.php
new file mode 100644
index 0000000..3f933ad
--- /dev/null
+++ b/lyapi/cache/Cache.php
@@ -0,0 +1,56 @@
+dir = $dir;
}
+ /**
+ * 设置一个缓存值.
+ *
+ * @param string $key 键名
+ * @param string $data 数据
+ * @param string $expire 过期时间
+ *
+ * @return boolean
+ */
public function set($key, $data, $expire = 0)
{
$filename = $this->dir . '/' . md5($key) . '.lyc';
@@ -43,6 +56,13 @@ class FileCache
}
}
+ /**
+ * 获取一个缓存值.
+ *
+ * @param string $key 键名
+ *
+ * @return string
+ */
public function get($key)
{
$filename = $this->dir . '/' . md5($key) . '.lyc';
@@ -63,6 +83,13 @@ class FileCache
}
}
+ /**
+ * 判断一个缓存键是否存在.
+ *
+ * @param string $key 键名
+ *
+ * @return boolean
+ */
public function has($key)
{
if ($this->get($key) == '') {
@@ -72,12 +99,24 @@ class FileCache
}
}
+
+ /**
+ * 删除一个缓存键.
+ *
+ * @param string $key 键名
+ *
+ * @return boolean
+ */
public function delete($key)
{
$filename = $this->dir . '/' . md5($key) . '.lyc';
return @unlink($filename);
}
+
+ /**
+ * 清空所有缓存.
+ */
public function clean()
{
$dirs = scandir($this->dir);
diff --git a/lyapi/cache/RedisCache.php b/lyapi/cache/RedisCache.php
index 3d1c466..76b28c9 100644
--- a/lyapi/cache/RedisCache.php
+++ b/lyapi/cache/RedisCache.php
@@ -2,9 +2,69 @@
namespace LyApi\cache;
-use Predis\Client;
+use Predis;
-class RedisCache extends Client
+class RedisCache implements Cache
{
- // 待编写 ....
+ private $client;
+
+ private $group;
+
+ public function __construct($group = null)
+ {
+ Predis\Autoloader::register();
+
+ $this->client = new Predis\Client('tcp://127.0.0.1:6379');
+
+ $this->group = 'cache'.$group;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function set($key, $data, $expire = 0)
+ {
+ if($expire == 0)
+ return $this->client->set($this->group.$key,$data);
+ else
+ return $this->client->setex($this->group.$key,$expire,$data);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function get($key)
+ {
+ return $this->client->get($this->group.$key);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function has($key)
+ {
+ return $this->client->exists($this->group.$key);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function delete($key)
+ {
+ return $this->client->del($this->group.$key);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function clean()
+ {
+ $keys = $this->client->keys($this->group . '*');
+
+ foreach ($keys as $key) {
+ $this->delete($key);
+ }
+
+ return true;
+ }
}
--
Gitee
From 1873871d0beafffe2a3f9092937d2da1963248b1 Mon Sep 17 00:00:00 2001
From: Hmm <919556520@qq.com>
Date: Wed, 15 Apr 2020 17:42:48 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20.ide?=
=?UTF-8?q?a?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/workspace.xml | 90 ---------------------------------------------
1 file changed, 90 deletions(-)
delete mode 100644 .idea/workspace.xml
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
deleted file mode 100644
index 7718861..0000000
--- a/.idea/workspace.xml
+++ /dev/null
@@ -1,90 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $PROJECT_DIR$/composer.json
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1586933408279
-
-
- 1586933408279
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
--
Gitee