代码拉取完成,页面将自动刷新
简单的redis操作客户端包装库
\Redis
的所有命令NOTICE: 依赖php的 'redis' 扩展
编辑 composer.json
, 添加
"inhere/redis": "dev-master",
然后运行: composer update
git clone https://github.com/inhere/php-redis.git // github
git clone https://git.oschina.net/inhere/php-redis.git // git@osc
$config = [
'host' => '127.0.0.1',
'port' => 6379,
'timeout' => 0.0,
'database' => 0,
];
$config = [
'mode' => 2, // 1 singleton 2 master-slave 3 cluster
'master' => [
'host' => '127.0.0.1',
'port' => 6379,
'timeout' => 0.0,
'database' => 0,
],
'slaves' => [
'slave0' => [
'host' => '127.0.0.1',
'port' => 6380,
'timeout' => 0.0,
'database' => 0,
]
],
];
$config = [
'mode' => 3, // 1 singleton 2 master-slave 3 cluster
'name1' => [
'host' => '127.0.0.1',
'port' => '6379',
'database' => '0',
'options' => []
],
'name2' => [
'host' => '127.0.0.2',
'port' => '6379',
'database' => '0',
'options' => []
],
];
根据不同的配置会自动创建对应的客户端实例
创建时不会进行连接,当发生命令操作时,才会进行连接
use inhere\redis\ClientFactory;
$client = ClientFactory::make($config);
支持四个事件 连接时
断开连接时
执行命令之前
执行命令之后
, 方便进行调试和记录操作日志
// ARGS: ($name, $mode, $config)
const CONNECT = 'connect';
// ARGS: ($name, $mode)
const DISCONNECT = 'disconnect';
// ARGS: ($method, array $args, $operate)
const BEFORE_EXECUTE = 'beforeExecute';
// ARGS: ($method, array $data, $operate)
const AFTER_EXECUTE = 'afterExecute';
// 连接时
$client->on(ClientInterface::CONNECT, function($name, $mode, $config) {
printf("CONNECT:connect to the name=%s,mode=%s,config=%s\n", $name, $mode, json_encode($config));
});
// 断开连接时
$client->on(ClientInterface::DISCONNECT, function($name, $mode) {
$names = 'all';
if ($name) {
$names = is_array($name) ? implode(',', $name) : $name;
}
printf("DISCONNECT:close there are %s connections,mode=%s\n", $names, $mode);
});
// 执行命令之前
$client->on('beforeExecute', function ($cmd, array $args, $operate)
{
printf("BEFORE_EXECUTE:will be execute the command=$cmd, operate=$operate, args=%s\n", json_encode($args));
});
// 执行命令之后
$client->on('afterExecute', function ($cmd, array $data, $operate)
{
printf("AFTER_EXECUTE:has been executed the command=$cmd, operate=$operate, data=%s\n", json_encode($data));
});
echo $client->ping(); // +PONG
echo "test set/get value:\n";
$suc = $client->set('key0', 'val0'); // bool(true)
$ret0 = $client->get('key0'); // string(4) "val0"
var_dump($suc, $ret0);
echo "test del key:\n";
$suc = $client->del('key0'); // int(1)
$ret0 = $client->get('key0'); // bool(false)
var_dump($suc, $ret0);
更多请看示例 examples
MIT
inhere/console
github git@osc
功能丰富的命令行应用,命令行工具库
inhere/sroute
github git@osc
轻量且功能丰富快速的路由库
inhere/php-validate
github git@osc
一个简洁小巧且功能完善的php验证库。仅有几个文件,无依赖。
inhere/http
github git@osc
http 工具库(request
请求 response
响应 curl
curl请求库,有简洁、完整和并发请求三个版本的类)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型