首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
使用swoole编写脚本redis的zrange操作使用连接池与不使用连接池结果不同
### 使用swoole编写脚本redis的zrange操作使用连接池与不使用连接池结果不同 ### Swoole版本,PHP版本,以及操作系统版本信息 php7.2;redis6.0;centos7.4 swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.5.9 Built => Jan 20 2021 17:15:38 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.1.1d 10 Sep 2019 pcre => enabled zlib => 1.2.7 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ### 相关代码 use Swoole\Coroutine; use Swoole\Runtime; use Swoole\Coroutine\Socket; use Swoole\Database\RedisConfig; use Swoole\Database\RedisPool; use function Swoole\Coroutine\run; $pool = new RedisPool((new RedisConfig) ->withHost('127.0.0.1') ->withPort(6379) ->withAuth('') ->withDbIndex(0) ->withTimeout(1) ); Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL); $timeid = 1; Swoole\Timer::tick(100,function($timeid,$pool){ $redis = $pool->get(); $setKeyBuy = 'mykey'; $data = $redis->zrange($setKeyBuy,0,-1,'withscores'); print_r($data); },$pool); 请将代码粘贴至此处(请勿用截图) 不使用连接池 use Swoole\Coroutine; use Swoole\Runtime; use Swoole\Coroutine\Socket; use function Swoole\Coroutine\run; Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL); $timeid = 1; Swoole\Timer::tick(100,function($timeid,$redis){ $setKeyBuy = 'mykey'; $data = $redis->zrange($setKeyBuy,0,-1,'withscores'); print_r($data); },$redis); ### 你期待的结果是什么?实际看到的错误信息又是什么? Array ( [0] => str1 [1] => str2 [2] => str3 [3] => str4 [4] => str5 [5] => str6 [6] => str7 ) 不使用连接池结果: Array ( [str1] => 10001 [str2] => 10002 [str3] => 10003 [str4] => 10004 [str5] => 10004 [str6] => 10004 [str7] => 10005 )
发布于5年前 · 2 次浏览 · 来自
提问
xljknm
### 使用swoole编写脚本redis的zrange操作使用连接池与不使用连接池结果不同 ### Swoole版本,PHP版本,以及操作系统版本信息 php7.2;redis6.0;centos7.4 swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.5.9 Built => Jan 20 2021 17:15:38 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.1.1d 10 Sep 2019 pcre => enabled zlib => 1.2.7 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ### 相关代码 use Swoole\Coroutine; use Swoole\Runtime; use Swoole\Coroutine\Socket; use Swoole\Database\RedisConfig; use Swoole\Database\RedisPool; use function Swoole\Coroutine\run; $pool = new RedisPool((new RedisConfig) ->withHost('127.0.0.1') ->withPort(6379) ->withAuth('') ->withDbIndex(0) ->withTimeout(1) ); Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL); $timeid = 1; Swoole\Timer::tick(100,function($timeid,$pool){ $redis = $pool->get(); $setKeyBuy = 'mykey'; $data = $redis->zrange($setKeyBuy,0,-1,'withscores'); print_r($data); },$pool); 请将代码粘贴至此处(请勿用截图) 不使用连接池 use Swoole\Coroutine; use Swoole\Runtime; use Swoole\Coroutine\Socket; use function Swoole\Coroutine\run; Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL); $timeid = 1; Swoole\Timer::tick(100,function($timeid,$redis){ $setKeyBuy = 'mykey'; $data = $redis->zrange($setKeyBuy,0,-1,'withscores'); print_r($data); },$redis); ### 你期待的结果是什么?实际看到的错误信息又是什么? Array ( [0] => str1 [1] => str2 [2] => str3 [3] => str4 [4] => str5 [5] => str6 [6] => str7 ) 不使用连接池结果: Array ( [str1] => 10001 [str2] => 10002 [str3] => 10003 [str4] => 10004 [str5] => 10004 [str6] => 10004 [str7] => 10005 )
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2021-03-09
鲁飞
我这里测试结果一致,两者原理一样,同是通过hook实现的
赞
0
回复
2021-03-09
xljknm
回复
鲁飞
我使用的是predis;方便的话我可以把测试代码发你邮箱。感谢你的回复,我会使用另一台服务器一下。
赞
0
回复
2021-03-09
鲁飞
回复
xljknm
predis 和 ext-redis 的行为肯定不一样,这个与 hook 无关
赞
0
回复