Rumah  >  Artikel  >  pembangunan bahagian belakang  >  安装redis和phpredis模块一例

安装redis和phpredis模块一例

WBOY
WBOYasal
2016-07-25 09:07:181099semak imbas
  1. @ubuntu:/$ mkdir /usr/local/redis
  2. @ubuntu:/$ cd /usr/local/redis
  3. @ubuntu:/$ wget http://redis.googlecode.com/files/redis-2.4.2.tar.gz
  4. @ubuntu:/$ tar xzf redis-2.4.2.tar.gz
  5. @ubuntu:/$ cd redis-2.4.2
  6. @ubuntu:/$ make
  7. @ubuntu:/$ src/redis-server
复制代码

redis测试命令:

  1. @ubuntu:/$ src/redis-cli

  2. @ubuntu:/$ redis> set foo bar
  3. @ubuntu:/$ OK
  4. @ubuntu:/$ redis> get foo

  5. @ubuntu:/$ "bar";
复制代码

装了redis的服务器端程序,现在要在项目中使用REDIS了,由于我们的后台是用PHP来写的,所以要用redis的PHP客户端来使用它。PHP的客户端有几种: Predis ★ Repository JoL1hAHN Mature and supported phpredis ★ Repository yowgi This is a client written in C as a PHP module. Rediska Repository Homepage shumkov Redisent Repository justinpoliey iRedis Repository

dhorrigan

在这里我选择phpredis( C开发的扩展包 )这个PHP扩展。

  1. @ubuntu:/$ wget https://download.github.com/owlient-phpredis-2.1.1-1-g90ecd17.tar.gz
  2. @ubuntu:/$ tar zxvf owlient-phpredis-2.1.1-1-g90ecd17.tar.gz
  3. @ubuntu:/$ cd owlient-phpredis-90ecd17/
  4. @ubuntu:/$ /usr/local/php/bin/phpize
  5. @ubuntu:/$ ./configure --with-php-config=/usr/local/php/bin/php-config
  6. @ubuntu:/$ make
  7. @ubuntu:/$ make install
复制代码

注:用C开发PHP扩展的时候如果用动态链接库的方式编译扩展模块,需要用到phpize,这个工具在使用apt-get install php5默认情况也是没安装的,安装phpize:apt-get install php5-dev。

修改配置文件: 修改php.ini文件 在php.ini中添加如下一行: extension=redis.so 重启nginx后生效。 最后开启redis服务:redis-server 或者 redis-server /etc/redis.conf(后台运行), 如果不开服务可能会出现 ”Uncaught exception 'RedisException' with message 'Redis server went away'?“错误 。



Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn