Skip to content

Commit 8f5db1a

Browse files
committed
负载均衡中使用Redis实现共享Session
1 parent 91fbd53 commit 8f5db1a

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,19 @@
6161
* [luajit 执行文件默认安装路径](#Nginx_base_knowledge)
6262
* [lua中self_indes详解](/Lua-Script/oop/self__index.md)
6363

64-
#### Redis 教程
65-
66-
###### 基础
64+
#### Redis 教程
6765
* [Redis 安装](/Redis/redis-install.md)
6866
* [Redis 配置详解](/Redis/redis-config.md)
6967
* [Redis 基础知识](#Redis_base_knowledge)
7068
* [Redis 开发与运维](#Redis-DevOps)
7169
* [Redis 执行Lua脚本基本用法](/Redis/redis-lua.md)
7270
* [Redis 漏洞如何防止被黑客攻击](/Redis/redis-safety.md)
71+
* [如何在Ubuntu 16.04上安装和配置Redis](https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-redis-on-ubuntu-16-04)
72+
* [Redis协议规范(译文)](http://www.hchstudio.cn/article/2018/e687/)
73+
* [负载均衡中使用Redis实现共享Session](https://segmentfault.com/a/1190000011558000)
74+
* [Redis 设计与实现](https://github.com/huangz1990/redis-3.0-annotated)
7375

7476
###### PHP 相关
75-
* [PHP脚本运行Redis](#PHP_Run_Redis)
7677
* [PHP 脚本执行一个Redis 订阅功能,用于监听键过期事件,返回一个回调,API接受改事件](/Redis-PHP/Php-Run-Redis-psubscribe/nohupRedisNotify.php)
7778
* [阿里云Redis开发规范](https://yq.aliyun.com/articles/531067)
7879
* [高可用Redis服务架构分析与搭建](https://mp.weixin.qq.com/s/DA4uhPULaXI-KDKwvLzb8Q)

Redis-PHP/Php-Run-Redis-psubscribe/nohupRedisNotify.php

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1-
21
#! /usr/bin/php
32
<?php
43
require_once './RedisInstance.class.php';
5-
require_once './Gateway.class.php';
64
RedisInstance::getInstance()->setOption(\Redis::OPT_READ_TIMEOUT,-1);
75
RedisInstance::getInstance()->psubscribe(array('__keyevent@0__:expired'), 'psCallback');
8-
// 回调函数,这里写处理逻辑
9-
function psCallback($redis, $pattern, $chan, $msg)
10-
{
11-
$messageId = explode(':',$msg);
12-
//print_r($msg);
13-
//echo $messageId[0]."<br/>";
14-
//echo $messageId[1];
15-
//die;
16-
//RedisInstance::getInstance()->set("channelXode",$messageId);
17-
switch($messageId[0]){
18-
case '4001':
19-
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
20-
break;
21-
case '4002':
22-
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
23-
break;
24-
case '4003':
25-
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
26-
break;
27-
default:
28-
curlPost('http://127.0.0.1',array('id'=>$msg));
29-
break;
30-
}
31-
}
6+
RedisInstance::getInstance()->psubscribe(array('__keyevent@0__:expired'),function ($redis, $pattern, $chan, $msg){
7+
// 回调函数,这里写处理逻辑
8+
$messageId = explode(':',$msg);
9+
switch($messageId[0]){
10+
case '4001':
11+
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
12+
break;
13+
case '4002':
14+
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
15+
break;
16+
case '4003':
17+
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
18+
break;
19+
default:
20+
curlPost('http://127.0.0.1',array('id'=>$msg));
21+
break;
22+
}
23+
});
3224

3325
function curlPost($url, $curlPost)
3426
{

0 commit comments

Comments
 (0)