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