From abc3cad8368a15fb65381f8e7594bd06febc685d Mon Sep 17 00:00:00 2001 From: sunxyw <31698606+sunxyw@users.noreply.github.com> Date: Tue, 17 Jan 2023 17:26:43 +0800 Subject: [PATCH] add redis docs (#262) * add redis docs * add redis docs link --- docs/.vuepress/config.js | 1 + docs/components/common/global-defines.md | 2 +- docs/components/store/redis.md | 43 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 docs/components/store/redis.md diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index fb403de1..1eab185b 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -100,6 +100,7 @@ module.exports = { children: [ 'store/file-system', 'store/cache', + 'store/redis', ] } ], diff --git a/docs/components/common/global-defines.md b/docs/components/common/global-defines.md index 3a576cb6..375e85ed 100644 --- a/docs/components/common/global-defines.md +++ b/docs/components/common/global-defines.md @@ -263,7 +263,7 @@ $result = sql_builder('mydb')->select('*')->from('users')->where('username = :us ### redis() -获取 Redis 操作类。有关 Redis 的更多详情和配置,见 [组件 - Redis(TODO)]()。 +获取 Redis 操作类。有关 Redis 的更多详情和配置,见 [Redis 数据库组件](/components/store/redis)。 - 定义:`redis(string $name = 'default')` - 返回:`ZM\Store\KV\Redis\RedisWrapper` diff --git a/docs/components/store/redis.md b/docs/components/store/redis.md new file mode 100644 index 00000000..08f241a6 --- /dev/null +++ b/docs/components/store/redis.md @@ -0,0 +1,43 @@ +# Redis 数据库 + +Redis 是一个开源的可基于内存亦可持久化的高性能键值对数据库。 + +## 配置 + +你可以通过 `global.php` 中的 `redis` 配置项来配置 Redis 数据库。 + +```php +/* Redis 连接配置,框架将自动生成连接池,支持多个连接池 */ +$config['redis'] = [ + 'default' => [ + 'enable' => false, + 'host' => '127.0.0.1', + 'port' => 6379, + 'index' => 0, + 'auth' => '', + 'pool_size' => 10, + ], +]; +``` + +你可以在配置中定义多个 Redis 连接,每个连接都有一个唯一的名称,例如 `default`,`cache`,`session` 等。 + +## 使用 + +你可以使用 `redis` 函数来获取 Redis 连接,例如: + +```php +$redis = redis('default'); +$redis->set('key', 'value'); +``` + +`redis` 函数接收一个参数,即 Redis 连接的名称,如果不传递参数,则默认使用 `default` 连接。其会返回一个 `RedisWrapper` +对象,该对象是对 Redis 连接池的封装。 + +你可以通过 `RedisWrapper` 中的各种方法来操作 Redis 数据库,例如 `set`,`get`,`del` 等。 + +详情请参考 [redis 全局函数](/components/common/global-defines.html#redis)。 + +## 连接池 + +框架会自动为每个 Redis 连接创建一个连接池,你可以通过 `pool_size` 配置项来设置连接池的大小。