Installing Redis and Phpredis extensions under Linux

Source: Internet
Author: User
Tags download redis delete cache

I. Installation of Redis

1. Download redis-3.2.3.tar.gz

wget http://download.redis.io/releases/redis-3.2.3.tar.gz

2. Unzip the redis-3.2.3.tar.gz

TAR-ZXVF redis-3.2.3.tar.gz

3. After the decompression is complete, install

CD redis-3.2.3

Make && make install

4. Switch to Utils and perform the Redis initialization script install_server.sh

CD Utils

./install_server.sh

At this point, the Redis installation is complete.

Second, install Phpredis extension

1. Download phpredis-2.2.4.tar.gz

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

2. Unzip the phpredis-2.2.4.tar.gz

TAR-ZXVF phpredis-2.2.4.tar.gz

3. Go to the installation directory

CD phpredis-2.2.4

4. Generate configure configuration file with Phpize

/usr/bin/phpize #phpize的目录可能不同, execute command Find/-name phpize Locate the directory where Phpize is located, if no phpize is found, execute command: Yum install Php-devel

5. Configuration

./configure--with-php-config=/usr/bin/php-config

6. Compiling the installation

Make && make install

At this point, Phpredis installation is complete

Third, configure PHP support

Vim/etc/php.ini

Add extension=redis.so

: Wq

Four, Package Redis class
<?PHPclassmyredis{Private Static $handler; Private Static functionhandler () {if(!self::$handler) { self::$handler=NewRedis (); Self::$handlerConnect (' 127.0.0.1 ', ' 6379 '); }        returnSelf::$handler; }    //Get Cache value     Public Static functionGet$key){        $value= Self::handler (), Get ($key); $value _serl= @unserialize($value); if(Is_object($value _serl)||Is_array($value _serl)){            return $value _serl; }        return $value; }   //Setting Cache values     Public Static functionSet$key,$value){        if(Is_object($value)||Is_array($value)){            $value=Serialize($value); }        returnSelf::handler (), Set ($key,$value); }    //Set cache value (with time)     Public Static functionSetex ($key,$time,$value){        if(Is_object($value)||Is_array($value)){            $value=Serialize($value); }        returnSelf::handler (), Setex ($key,$time,$value); }     //Delete Cache     Public Static functionDel$key){        returnSelf::handler (), Del ($key); }}

Installing Redis and Phpredis extensions under Linux

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.