您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman-redis組件-setRange
发布时间:2021-12-25 23:39:37编辑:雪饮阅读()
setRange
用指定的字符串覆盖给定 key 所储存的字符串值,覆盖的位置从偏移量 offset 开始。如果key不存在,则将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->set('key', 'Hello world');
$redis->setRange('key', 6, "redis", function ($result) {
var_dump("setRange:");
var_dump($result); // 11
}) ;
$redis->get('key', function ($result) {
var_dump("get:");
var_dump($result); // 'Hello redis'
}) ;
};
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(9) "setRange:"
int(11)
string(4) "get:"
string(11) "Hello redis"
string(5) "auth:"
bool(true)
string(9) "setRange:"
int(11)
string(4) "get:"
string(11) "Hello redis"
关键字词:workerman,redis,setRange