swoole php不能用cache,cache(redis)

#### cache缓存

cache缓存是基于predis组件实现的,要使用cache,如果没有安装,必须安装predis组件

~~~

composer require predis/predis

~~~

* 配置

~~~

components => [

// 第一种配置方式

'redis' =>[

'class' => 'Swoolefy\Core\Cache\Redis',

'constructor'=> [

[

'scheme' => 'tcp',

'host' => '192.168.99.102',

'port' => 6379,

'password' => '123456'

],

]

],

// 第二种动态原生创建,更加灵活,推荐

'redis'=>function($com_name) {

$parameters = [

'scheme' => 'tcp',

'host' => '192.168.99.102',

'port' => 6379,

'password' => '123456'

],

$optinons = [];

$redis = new Swoolefy\Core\Cache\Redis($parameters, $options);

return $redis;

}

]

~~~

constructor:这个选项的配置值其实与predis创建client的实例要设置的配置值是一致的,具体的参考[https://github.com/nrk/predis](https://github.com/nrk/predis)

~~~

$client = new Predis\Client(

[

'scheme' => 'tcp',

'host' => '10.0.0.1',

'port' => 6379,

'password' => '123456'

]

);

~~~

#### 二、swoole的异步redis支持

1、依赖于hiredis(swoole 4.2.16+不需要安装,以内置)

https://github.com/redis/hiredis/tree/v0.13.3

~~~

make -j

sudo make install

sudo ldconfig

~~~

2、直接安装swoole的./configure --enable-async-redis,一般会报错说找不到hiredis.h,那么我们进去hiredis文件需要将编译好的把libhiredis.so放到/usr/local/lib/中,把hiredis.h放到/usr/local/inlcude/hiredis/中的。

3、重新执行

~~~

./configure --enable-async-redis

make clean

make

make install

~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值