您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman-redis组件-hIncrByFloat
发布时间:2021-12-28 21:28:26编辑:雪饮阅读()
hIncrByFloat
类似与hIncrBy,只不过增量是浮点型。
实例:
<?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->hIncrByFloat('h', 'x', 3.5, function ($result) {
//执行成功返回本次增量值之后的最终值
var_dump($result);
});
};
Worker::runAll();
实例运行并有http客户端请求时:
[root@localhost workerman]# php index.php start
Workerman[index.php] start in DEBUG mode
----------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.26 PHP version:7.3.31
------------------------------------------ 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.
string(3) "3.5"
关键字词:workerman,redis,hIncrByFloat