mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-30 02:37:58 +08:00
Update redis.md
This commit is contained in:
parent
ad1d91c050
commit
415a91f200
@ -17,7 +17,6 @@ composer require hyperf/redis
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
return [
|
||||
'default' => [
|
||||
'host' => env('REDIS_HOST', 'localhost'),
|
||||
@ -39,17 +38,15 @@ return [
|
||||
|
||||
## 使用
|
||||
|
||||
`hyperf/redis` 实现了 `ext-redis` 代理和连接池,用户可以直接使用\Redis客户端。
|
||||
`hyperf/redis` 实现了 `ext-redis` 代理和连接池,用户可以直接通过依赖注入容器注入 `\Redis` 来使用 Redis 客户端,实际获得的是 `Hyperf\Redis\Redis` 的一个代理对象。
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Hyperf\Utils\ApplicationContext;
|
||||
|
||||
$container = ApplicationContext::getContainer();
|
||||
|
||||
$redis = $container->get(\Redis::class);
|
||||
|
||||
$result = $redis->keys('*');
|
||||
```
|
||||
|
||||
@ -100,7 +97,6 @@ return [
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Hyperf\Redis\Redis;
|
||||
|
||||
class FooRedis extends Redis
|
||||
@ -122,12 +118,13 @@ $result = $redis->keys('*');
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Hyperf\Redis\RedisFactory;
|
||||
use Hyperf\Utils\ApplicationContext;
|
||||
|
||||
$container = ApplicationContext::getContainer();
|
||||
|
||||
// 通过 DI 容器获取或直接注入 RedisFactory 类
|
||||
$redis = $this->container->get(RedisFactory::class)->get('foo');
|
||||
|
||||
$redis = $container->get(RedisFactory::class)->get('foo');
|
||||
$result = $redis->keys('*');
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user