Using the Redis installation tutorial

Source: Internet
Author: User
Tags download redis phpinfo

One: Installing Redis

1. Download Redis and install

$wget http://redis.googlecode.com/files/redis-2.2.10.tar.gz

$tar ZVXF redis-2.2.10.tar.gz

$CD redis-2.2.10

$make

$sudo CP redis.conf/etc/

$sudo CP Redis-benchmark REDIS-CLI redis-server/usr/bin/

2. Running a Redis server

$/usr/bin/redis-server/etc/redis.conf

You can use the following command to detect if Redis is started

$ps-X | grep Redis

1411 pts/0 s+ 0:00/usr/bin/redis-server/etc/redis.conf

Description already started

3. After running the client program, you can enable

$redis-CLI

If you want to use Redis in PHP, you also need to install the Phpredis extension

Two: Install Phpredis

1, installation Phpredis

Download: https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz

Upload phpredis-2.2.4.tar.gz to/usr/local/src directory

$rz

CD/USR/LOCAL/SRC #进入软件包存放目录

Tar zxvf phpredis-2.2.4.tar.gz #解压

CD phpredis-2.2.4 #进入安装目录

/usr/local/php/bin/phpize #用phpize生成configure配置文件 (if you are prompted to find phpize may not be installed Phpize, see Appendix 1)

./configure--with-php-config=/usr/local/php/bin/php-config #配置

Make #编译

Make install #安装

After the installation is complete, the following installation path appears

/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

2. Configure PHP.ini Support

Vim/usr/local/php/etc/php.ini #编辑配置文件, add the following on the last line

extension= "Redis.so"

: wq! #保存退出

3 Restarting the server

sudo service httpd restart

(Nginx:sudo service Nginx restart)

Redis in 4.phpinfo indicates that the Phpredis extension has been successfully installed

three. Calling Redis in PHP1. When you see the above in Phpinfo, we can write a few small programs to try the Redis function:1.php<?php$redis = new Redis ();$redis->connect ("127.0.0.1", 6379);$weibo = Array (' uid ' = 1,' content ' and ' I've got your big uncle ',' timestamp ' = time ()        );$redis->lpush (' Weibo ', $weibo);$redis->close ();?>2.php<?php$redis = new Redis ();$redis->connect ("127.0.0.1", 6379);$data = $redis->get ("Weibo");Var_dump ($data);$redis->close ();?>2. Publish a microblog using Redis Message Queuing, asynchronous publishing1.php<?php$redis = new Redis ();$redis->connect ("127.0.0.1", 6379);$weibo = Array (' uid ' = 1,' content ' and ' I've got your big uncle ',' timestamp ' = time ()        );$redis->lpush (' Weibo ', Json_encode ($weibo));$redis->close ();?>2.php<?php$redis = new Redis ();$redis->connect ("127.0.0.1", 6379); While (TURE) {if ($redis->lsize (' Weibo ') > 0) {$info = $redis->rpop (' Weibo ');$info = Json_decode ($info, ture);mysql_query (); Inserting information into the database, where no detail code is written} elsesleep (1);}?>  Appendix 1: Installation of PhpizePHP has a lot of extensions, and we didn't install some extensions when we first installed them, and they might be used in the process. PHP provides phpize as a tool for installing the extensions we need. Most of the machines are not installed Phpize, we can install through Yum instal php-devel (Ubuntu is apt-get install php-devel).     

Using the Redis installation tutorial

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.