Swoole 安裝支援非同步Redis客戶端---學習筆記(2)
阿新 • • 發佈:2019-01-31
- 編譯安裝hiredis
hiredis下載地址:https://github.com/redis/hiredis/releases
make -j
sudo make install
sudo ldconfig
編譯swoole時,在configure指令中加入–enable-async-redis
swoole目錄重新編譯swoole
./configure --with-php-config=/usr/local/php/bin/php-config --enable-async-redis
make clean
make -j
make install
php-m 檢視swoole或者是通過php –ri swoole檢視有無顯示async redis client
啟動redis服務端測試
<?php
$redisClient = new swoole_redis();
$redisClient->connect('127.0.0.1', 6379, function(swoole_redis $redisClient,$result){
if ($result === false) {
echo "connect to redis server failed.\n";
exit;
}
//非同步設定 key value
$redisClient->set('swoole' , 'success', function (swoole_redis $redisClient, $result) {
var_dump($result,1);
});
//獲取所有key鍵
$redisClient->keys('*', function (swoole_redis $redisClient, $result) {
var_dump($result,2);
});
//非同步獲取 key 值
$redisClient->get('swoole', function (swoole_redis $redisClient, $result) {
var_dump($result,3);
//關閉Redis連線,不接受任何引數
$redisClient->close();
});
});
echo "start ok".PHP_EOL;