您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman-redis組件 -del
发布时间:2021-12-25 22:15:05编辑:雪饮阅读()
del
用于删除已存在的键,返回结果为数字,代表删除了多少个key(不存在的key不做计数)。爲什麽哥測試返回的是null?
實例:
<?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);
});
// 删除一个key
$num1= $redis->del('key1');
var_dump("num1:");
var_dump($num1);
// 删除多个key
$num2=$redis->del(['key2', 'key3', 'key4']);
var_dump("num2");
var_dump($num2);
};
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) "num1:"
NULL
string(4) "num2"
NULL
string(5) "auth:"
bool(true)
string(5) "num1:"
NULL
string(4) "num2"
NULL
string(5) "auth:"
bool(true)
关键字词:workerman,redis,del