您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman-redis組件 -hGetAll
发布时间:2021-12-27 22:59:47编辑:雪饮阅读()
hGetAll
以关联数组的形式返回哈希表中所有的字段和值。
如果key不存在,则返回空数组。如果key不是hash类型,则返回false。
實例:
<?php
use Workerman\Worker;
use Workerman\Redis\Client;
use Workerman\Connection\TcpConnection;
use Workerman\Timer;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('http://0.0.0.0:6161');
global $offset;
$worker->onWorkerStart = function() {
global $offset;
$offset=0;
};
$worker->onMessage = function(TcpConnection $connection, $data) {
$redis = new Client('redis://127.0.0.1:6379');
$redis->del('h');
$redis->hSet('h', 'a', 'x');
$redis->hSet('h', 'b', 'y');
$redis->hSet('h', 'c', 'z');
$redis->hSet('h', 'd', 't');
$redis->hGetAll('h', function ($result) {
var_export($result);
});
};
Worker::runAll();
實例運行并有http訪問如:
[root@localhost www.fpm.com]# /usr/local/php734/bin/php channelServer.php start
Workerman[channelServer.php] start in DEBUG mode
----------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.22 PHP version:7.3.4
------------------------------------------ WORKERS ------------------------------------------
proto user worker listen processes status
tcp root none http://0.0.0.0:6161 1 [OK]
---------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
array (
'a' => 'x',
'b' => 'y',
'c' => 'z',
'd' => 't',
)
redis驗證:
127.0.0.1:6379> hgetall h
1) "a"
2) "x"
3) "b"
4) "y"
5) "c"
6) "z"
7) "d"
8) "t"
关键字词:workerman,redis,hGetAll