Ubuntu14安装redis及phpredis扩展及配置

安装redis

sudo apt-get install redis-server

 

安装phpredis

sudo apt-get install php5-redis

 

配置redis开机自启

http://blog.csdn.net/echo_follow_heart/article/details/51594722

 

配置Auth和远程访问

/etc/redis下的redis.conf文件

修改 # requirepass foobared 为 requirepass youpass

例如

 

注释掉bind 127.0.0.1

保存,重启redis服务

tp上检验代码

 1 namespace Admin\Controller;
 2 use Think\Controller;
 3 class RedisController extends Controller {
 4     
 5     public function index() {
 6         // $redis->connect('127.0.0.1', 6379); //连接Redis
 7         $redis = new \Redis();
 8         $redis->connect('127.0.0.1', 6379);
 9         $redis->auth('123456'); //密码验证
10         echo "Connection to server sucessfully";
11         //设置 redis 字符串数据
12         $redis->set("tutorial-name", "Redis tutorial");
13         // 获取存储的数据并输出
14         echo "Stored string in redis:: " . $redis->get("tutorial-name");
15         $this->display();
16     }
17 }

 

posted on 2017-11-03 19:56  bettyjones  阅读(170)  评论(0编辑  收藏  举报