PHP连接redis
正常PHP连接redis
public function getRedis() { $redis = new \Redis(); $redis->connect(env("REDIS_MASTER",'127.0.0.1'),6379); $redis->auth(env('REDIS_AUTH','123456')); return $redis; } 复制代码
设置一个只读用户,只用来读,不可写入,则是一下代码
public function getRedis() { $redis = new \Redis(); $redis->connect(env("REDIS_MASTER",'127.0.0.1'),6379); $auth = env('REDIS_ONLY_READ_USER').":".env('REDIS_ONLY_READ_PWD'); $redis->auth($auth); return $redis; } 复制代码
简单使用redis
$this->getRedis()->set('name','WXiangQian'); $name = $this->getRedis()->get('name'); echo $name; // WXiangQian 复制代码
redis篇集合
http://www.developcls.com/qa/30f1158dc4014694b8bfb505396520d6.html