您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman-redis-rPush
发布时间:2021-12-29 21:33:55编辑:雪饮阅读()
rPush
将一个或多个值插入到列表的尾部(最右边),并返回插入后的列表的长度。
如果列表不存在,一个空列表会被创建并执行 RPUSH 操作。 当列表存在但不是列表类型时返回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('key1');
$redis->rPush('key1', 'A', function ($r) {
var_dump($r); // 1
});
$redis->rPush('key1', 'B', function ($r) {
var_dump($r); // 2
});
};
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.
int(1)
int(2)
关键字词:workerman,redis,rPush