YukiRain 2020-06-14
参考我的redis的安装教程
redis_host = "localhost"; $redis_port = "6379"; $redis = new Redis(); $redis->connect($redis_host,$redis_port); echo "成功连接redis"; echo "<br>"; echo "服务器测试:".$redis->ping(); echo "<br>"; $redis->set("test","bruce,common",[‘NX‘,‘EX‘=>60*3]); echo "获取redis值:".$redis->get("test"); $redis->close(); //如果不手动关闭,redis自动会关闭,时间默认值是300s,可在php.ini中更改
session.save_handler = redis //默认是files session.save_path = "tcp://localhost:6389" // 如果有密码:session.save_path = "tcp://localhost:6389?auth=password",端口也可以自己设置
// 设置显示错误气提示 ini_set(‘display_errors‘, true); error_reporting(E_ALL); // 配置session 存储于redis ini_set(‘session.save_handler‘, ‘redis‘); ini_set(‘session.save_path‘, ‘tcp://127.0.0.1:6379?auth=123456789‘);
<?php $redis_host = "localhost"; $redis_port = "6379"; $redis = new Redis(); $redis->connect($redis_host,$redis_port); echo "成功连接redis"; echo "<br>"; echo "服务器测试:".$redis->ping(); echo "<br>"; $arList = $redis->keys(‘PHPREDIS_SESSION*‘); print_r($arList); echo "<br>"; echo "session的key".$arList[0]."<br>session的值".$redis->get($arList[0]); $redis->close();