How to install the PHP extension pack for Redis

Source: Internet
Author: User

try Redis Installation, PHP environment connection, test  

Redis Introduction

Redis essentially a key/value database, similar to the memcached NoSQL database, but his data can be persisted on the disk, solve the service restart data is not lost, his value can be string (string), list, Sets (collection) or ordered sets (the sorted collection), all data types have Push/pop, Add/remove, perform service-side aggregation, intersection, two sets sets of differences, and so on, these operations are atomic, Redis also supports a variety of sorting capabilities

Redis 2.0 many new features have been added, such as improved performance, new data types, and less memory (AOF and VMS)

Redis support for most mainstream development languages such as: C, Java, C #, PHP, Perl, Python, Lua, Erlang, Ruby, etc.

official website:http://code.google.com/p/redis/

installation process

Latest stable version, Redis 2.0.4 stable

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

Tar zxf redis-2.0.4.tar.gz

CD redis-2.0.4

Unlike other software, configure is not required.

Make

It's finished.

Create a Directory

Mkdir/usr/local/redis2

CP redis-server Redis-benchmark REDIS-CLI REDIS.CONF/USR/LOCAL/REDIS2

Start:

./redis-server >/dev/null &

Test:

stored value:

./REDIS-CLI Set HX Value

Value:

./REDIS-CLI Get HX

Installing the Phpredis module

Https://github.com/owlient/phpredis

Download Phpredis

Extract

Shell> CD Phpredis

shell>/usr/local/php/bin/phpize This phpize is the installation of the PHP module

Shell>./configure–with-php-config=/usr/local/php/bin/php-config

Shell> make

shell> make Install

next in the php.ini add extension=redis.so first to see if there is no extension_dir=/ ... .

Restart Apache or Nginx

PHP Code Testing

$redis = new Redis ();

$redis->connect (' 127.0.0.1′,6379);

$redis->set (' Test ', ' Hello world! ');

echo $redis->get (' Test ');

?>

Output Hello world!

http://code.google.com/p/php-redis/

Redis master-Slave configuration

REDIS very simple master-slave configuration , some articles in the wordy wrote a large article, in fact, two words:

Open the redis.conf from the machine

Port 6381 ( Note: cannot be the same as the host)

sleverof 10.0.0.149 6383 ( Note: IP is host ip,6383 for host Redis port number)

Restart the console, then restart the slave

Run./redis-server redis.conf

If it appears:

The configuration is successful

--------------------------------------

Php-redis Client Use methods

<?php
Require ' redis.php ';
Require ' redis_pool.php ';
Require ' redis_peer.php ';
Class Note extends Redis_peer {}
$note = new Note ();
# Create Note, primary key is generated automatically
$id = $note->insert (Array (' title ' = ' Hello ', ' body ' = ' world! '));
# Update Note
$id = $note->update ($id, Array (' body ' = ' wwwwworld! '));
# Get Some note by primary key
$note _data = $note->get_by_id ($id);
# Delete Note $note->delete ($id);

How to install the PHP extension pack for Redis

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.