Skip to content

Commit

Permalink
负载均衡中使用Redis实现共享Session
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinywan committed Sep 8, 2018
1 parent 91fbd53 commit 8f5db1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,19 @@
* [luajit 执行文件默认安装路径](#Nginx_base_knowledge)
* [lua中self_indes详解](/Lua-Script/oop/self__index.md)

#### Redis 教程

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

###### PHP 相关
* [PHP脚本运行Redis](#PHP_Run_Redis)
* [PHP 脚本执行一个Redis 订阅功能,用于监听键过期事件,返回一个回调,API接受改事件](/Redis-PHP/Php-Run-Redis-psubscribe/nohupRedisNotify.php)
* [阿里云Redis开发规范](https://yq.aliyun.com/articles/531067)
* [高可用Redis服务架构分析与搭建](https://mp.weixin.qq.com/s/DA4uhPULaXI-KDKwvLzb8Q)
Expand Down
44 changes: 18 additions & 26 deletions Redis-PHP/Php-Run-Redis-psubscribe/nohupRedisNotify.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@

#! /usr/bin/php
<?php
require_once './RedisInstance.class.php';
require_once './Gateway.class.php';
RedisInstance::getInstance()->setOption(\Redis::OPT_READ_TIMEOUT,-1);
RedisInstance::getInstance()->psubscribe(array('__keyevent@0__:expired'), 'psCallback');
// 回调函数,这里写处理逻辑
function psCallback($redis, $pattern, $chan, $msg)
{
$messageId = explode(':',$msg);
//print_r($msg);
//echo $messageId[0]."<br/>";
//echo $messageId[1];
//die;
//RedisInstance::getInstance()->set("channelXode",$messageId);
switch($messageId[0]){
case '4001':
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
break;
case '4002':
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
break;
case '4003':
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
break;
default:
curlPost('http://127.0.0.1',array('id'=>$msg));
break;
}
}
RedisInstance::getInstance()->psubscribe(array('__keyevent@0__:expired'),function ($redis, $pattern, $chan, $msg){
// 回调函数,这里写处理逻辑
$messageId = explode(':',$msg);
switch($messageId[0]){
case '4001':
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
break;
case '4002':
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
break;
case '4003':
curlPost('http://127.0.0.1',array('id'=>$messageId[1]));
break;
default:
curlPost('http://127.0.0.1',array('id'=>$msg));
break;
}
});

function curlPost($url, $curlPost)
{
Expand Down

0 comments on commit 8f5db1a

Please sign in to comment.