您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman-redis組件-rename
发布时间:2021-12-25 23:05:06编辑:雪饮阅读()
rename
修改 key 的名称,key不存在则返回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');
$worker->onWorkerStart = function() {
};
$worker->onMessage = function(TcpConnection $connection, $data) {
$redis = new Client('redis://127.0.0.1:6379');
$redis->auth("xy220807",function($result){
var_dump("auth:");
var_dump($result);
});
$redis->select(0); // switch to DB 0
$redis->set('x', '42');
$redis->rename('x', 'y', function ($result) {
var_dump("rename:");
var_dump($result); // true
}) ;
};
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.
string(5) "auth:"
bool(true)
string(7) "rename:"
bool(true)
此時的keys *:
127.0.0.1:6379> keys *
1) "key1"
2) "foo"
3) "bar"
4) "y"
5) "key3"
6) "key2"
7) "baz"
8) "key"
关键字词:workerman,redis,rename