Redis非关系型数据库—LNMP平台对接redis服务
一、部署lnmp架构
之前做过这边就不多写了
二、redis安装
详情参考前面
三、安装redis扩展
官网:http://redis.io/ 下载包: https://codeload.github.com/phpredis/phpredis/zip/develop http://download.redis.io/releases/redis-3.2.5.tar.gz
解压并编译安装
tar -zxvf redis-4.0.2.tgz cd /opt/redis-4.0.2 //运行 phpize 脚本的用途是动态安装 php 扩展模块 /usr/local/php/bin/phpize //开始编译安装 ./configure --with-php-config=/usr/local/php/bin/php-config --enable-redis make && make install //Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/ ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/ redis.so
例:
修改php配置文件
vim /usr/local/php/lib/php.ini extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/" #736行,指定redis模块目录 extension = "redis.so" #738行,修改参数项名称为extension,指定redis模块名称 systemctl restart php-fpm.service php -m | grep redis
例:
测试连接
cd /usr/local/nginx/html/ vim set.php <?php $redis = new redis(); $redis->connect('127.0.0.1', 6379); $redis->set('gxs',"hello"); echo $redis->get('gxs'); ?> curl http://127.0.0.1/set.php vim get.php <?php $redis = new redis(); $redis->connect('127.0.0.1', 6379); $result = $redis->get('gxs'); var_dump($result); ?> curl http://127.0.0.1/get.php //结果:string(10) "hello"
例: