ubuntu 16.04 环境中安装 php7.0 redis扩展

安装配置步骤如下:

1.root@ubuntu:/tmp# git clone -b php7 https://github.com/phpredis/phpredis.git

2.root@ubuntu:/tmp# mv phpredis/ /etc/

3.root@ubuntu:/tmp#  cd /etc/phpredis

4.root@ubuntu://etc/phpredisphpize

5.root@ubuntu://etc/phpredis# ./configure

6. root@ubuntu://etc/phpredis#make && make install

7.root@ubuntu://etc/phpredis#vi /etc/php/7.0/fpm/conf.d/redis.ini  中 写入(extension=/etc/phpredis/modules/redis.so)退出保存

8.root@ubuntu://etc/phpredis#vi /etc/php/7.0/apache2/php.ini 中写入 (extension=/etc/phpredis/modules/redis.so

9. 重启apache2 /etc/init.d/apache2 restart 

./redis-serverredis.conf开启redis后台服务。
如果你修改redis.conf中的任何配置,需要关闭redis-server进程后,再./redis-serverredis.conf重新开启redis后台服务。

 在phpinfo 查查看是否成功

ubuntu 16.04 环境中安装 php7.0 redis扩展_第1张图片

代码测试

connect('localhost','6379'); //$redis->auth('admin123');//如果设置了密码,添加此行
//查看服务是否运行
$redis->ping();

//选择数据库
$redis->select(5);

//设置数据
$redis->set('school','WuRuan');
//设置多个数据
$redis->mset(array('name'=>'jack','age'=>24,'height'=>'1.78'));

//存储数据到列表中
$redis->lpush("tutorial-list", "Redis");
$redis->lpush("tutorial-list", "Mongodb");
$redis->lpush("tutorial-list", "Mysql");

//获取存储数据并输出
echo $redis->get('school');

echo '
'; $gets=$redis->mget(array('name','age','height')); print_r($gets); $tl=$redis->lrange("tutorial-list", 0 ,5); print_r($tl); ?>

php 操作redis相关文章

PHP操作Redis LIST ,SET, HASH 的相关命令 (一)
PHP操作Redis KEY,String 的相关命令 (二)
PHP操作Redis 有序集(Sorted Set) 的相关命令 (三)

参考文章:http://www.cnblogs.com/GaZeon/p/5422078.html
 

你可能感兴趣的:(服务器,PHP)