您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-session管理-配置文件-更換session驅動為redis集群
发布时间:2022-01-29 13:16:30编辑:雪饮阅读()
上篇中我們實現了“webman-session管理-配置文件-redis集群搭建(單宿主機多端口實現)”
那麽接下來我們在webman中就可以配置連接到該集群了。
config/session.php中新增:
'handler' => Webman\RedisClusterSessionHandler::class
修改type為:
'type'=>'redis_cluster',
而redis集群配置如:
'redis_cluster' => [
'host' => ['127.0.0.1:6379', '127.0.0.1:6381', '127.0.0.1:6380'],
'timeout' => 2,
'auth' => '',
'prefix' => 'redis_session_',
]
這裏按理來説配置任何一個節點都是可以的,這裏挑選了幾個master節點,至於如何得知那些是master節點,我這裏是參考了上篇中創建集群時候的日志片段中看出來的
當然也可以從集群節點信息中分析得出:
[root@localhost webman]# redis-cli cluster nodes
52ae6420725e924d72fbf8884d060725f37b953b 192.168.1.10:6381@16381 master - 0 1643427335057 3 connected 10923-16383
441fe63ed37d167cea82ba97ca732d506ab1efe2 192.168.1.10:6384@16384 slave 1a8a78ce01d8cb00828f824693753078683499f8 0 1643427336000 1 connected
c3f903a44966153e1a891610bb68e209d935461a 192.168.1.10:6383@16383 slave 52ae6420725e924d72fbf8884d060725f37b953b 0 1643427337000 3 connected
1a8a78ce01d8cb00828f824693753078683499f8 192.168.1.10:6379@16379 myself,master - 0 1643427331000 1 connected 0-5460
9eda37a8ffe8176460c137cac9fd861998ccccd4 192.168.1.10:6380@16380 master - 0 1643427335000 2 connected 5461-10922
61df0b77e73d9e8693bd5d95f2e11ca976170d1f 192.168.1.10:6382@16382 slave 9eda37a8ffe8176460c137cac9fd861998ccccd4 0 1643427337071 2 connected
那麽完整的config/session.php則如:
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Webman\FileSessionHandler;
use Webman\RedisClusterSessionHandler;
use Webman\RedisSessionHandler;
return [
//'type' => 'file', // or redis or redis_cluster
'type'=>'redis_cluster',
'handler' => Webman\FileSessionHandler::class,
'handler' => Webman\RedisSessionHandler::class,
'handler' => Webman\RedisClusterSessionHandler::class,
'config' => [
'file' => [
'save_path' => runtime_path() . '/sessions',
],
'redis' => [
'host' => '127.0.0.1',
'port' => 6379,
'auth' => '',
'timeout' => 2,
'database' => '',
'prefix' => 'redis_session_',
],
'redis_cluster' => [
'host' => ['127.0.0.1:6379', '127.0.0.1:6381', '127.0.0.1:6380'],
'timeout' => 2,
'auth' => '',
'prefix' => 'redis_session_',
]
],
'session_name' => 'PHPSID',
];
然後webman啓動
[root@localhost webman]# /usr/local/php734/bin/php -c /usr/local/php734/lib/php.ini start.php start
Workerman[start.php] start in DEBUG mode
----------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.26 PHP version:7.3.4
------------------------------------------ WORKERS ------------------------------------------
proto user worker listen processes status
tcp root webman http://0.0.0.0:8787 4 [OK]
tcp root monitor none 1 [OK]
---------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
然後webman被訪問時:
[root@localhost ~]# elinks http://127.0.0.1:8787/blog/index --dump
array ( 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4'
=> 'value4', 'key5' => 'value5', 'key6' => 'value6', )
关键字词:webman,session,管理,配置,文件,更換,驅動,為,redis,集群
相关文章
- webman-session管理-配置文件-redis集群搭建(單宿主機
- webman-session管理-配置文件-更換session驅動為redis
- webman-session管理-助手函数session()-給session賦值
- webman-session管理-助手函数session()-獲取某個值
- webman-session管理-助手函数session()-session實例獲
- webman-session管理-判断对应session数据是否存在
- webman-session管理-删除所有session数据
- webman-session管理-删除session数据
- webman-session管理-存儲session(set與put)
- webman-session管理-獲取session中某個值