当前位置: 首页 > 后端技术 > PHP

Swoole学习之异步redis(八)

时间:2023-03-29 16:09:57 PHP

一、异步redis服务安装Swoole官方文档入门指南->快速入门->异步Redis客户端1、swoole使用异步redis前置条件redis服务hiredis库(X)编译swoole你需要添加--enable-async-redis(X)注:如果你的swoole版本在4.3以上,只需要安装redis服务,不需要做hiredis库和重新编译swoole,因为版本在上面4.3已经内置。2.从源码安装redis从Redis官网下载最新版本到本地,然后解压。下载、提取和编译Redis:$wgethttp://download.redis.io/releases/redis-5.0.5.tar.gz$tarxzfredis-5.0.5.tar.gz$cdredis-5.0.5$make现在编译的二进制文件在src目录中可用。使用以下命令运行Redis:redis解压缩目录:./redis-5.0.5/src/redis-server$src/redis-server您可以使用内置客户端与Redis交互:$src/redis-cliredis>setfoobarOKredis>getfoo"bar"3.Hiredis安装(swoole4.3及以上不需要安装)hiredis库最后编译成so文件,然后使用。hiredis下载地址:https://github.com/redis/hire...使用命令下载到本地,然后解压:$wgethttps://github.com/redis/hiredis/archive/v0。14.0.tar。gz$mvv0.14.0.tar.gzhiredis-v0.14.0.tar.gz$tarxzfhiredis-v0.14.0.tar.gz$cdhiredis-0.14.0编译安装:$make-j$sudomakeinstall$sudoldconfig4,重新编译swoole(swoole4.3以上不需要重新编译),进入swoole安装包目录:$cd/work/study/softpackage/swoole查看configure参数命令:$./configure--helpdisplay:...OptionalFeaturesandPackages:--disable-option-checkingignoreunrecognized--enable/--withoptions--disable-FEATUREdonotincludeFEATURE(同--enable-FEATURE=no)--enable-FEATURE[=ARG]includeFEATURE[ARG=yes]--with-PACKAGE[=ARG]使用PACKAGE[ARG=yes]--without-PACKAGE不使用PACKAGE(与--with-PACKAGE=no相同)--with-libdir=NAME在.../NAME而不是.../lib中查找库--with-php-config=PATHphp-configphp-config的路径--enable-debug-log启用swoole调试日志--enable-trace-log启用swooletracelog--enable-sockets你有套接字扩展吗?--enable-openssl使用openssl?--enable-http2使用http2.0?--enable-swoole启用swoole支持--enable-mysqlnd你有mysqlnd吗?--with-openssl-dir=DIR包括OpenSSL支持(需要OpenSSL>=0.9.6)--with-jemalloc-dir=DIR包括jemalloc支持--enable-asan启用asan--enable-gcov启用gcov--enable-调试,使用调试符号编译--enable-shared=PKGS构建共享库默认=yes--enable-static=PKGS构建静态库默认=yes--enable-fast-install=PKGS优化快速安装默认=yes--with-gnu-ld假设C编译器使用GNUlddefault=no--disable-libtool-lock避免锁定(可能会破坏并行构建)--with-pic尝试仅使用PIC/非PIC对象default=同时使用--with-tags=T为什么在AGSIncludeadditionalconfigurationsautomatichere中找不到--enable-async-redis参数?我查看了swoole官方文档。原来使用hireidis从swoole4.3版本开始不需要重新编译。wiki/...2.开启redis服务的代码实现:$src/redis-serverreids.phpconnect(REDIS_SERVER_HOST,REDIS_SERVER_PORT);$redis->setDefer();$redis->set('key1','value');$redis2=newSwoole\Coroutine\Redis();$redis2->connect(REDIS_SERVER_HOST,REDIS_SERVER_PORT);$redis2->setDefer();$redis2->get('key1');$result1=$redis->recv();$result2=$redis2->recv();var_dump($result1,$result2);});执行打印:$phpredis.phpbool(true)string(5)"value"