Redis, developed in 2009, is a flexible, open-source, key value data store. Following in the footsteps of other NoSQL databases, such as Cassandra, CouchDB, and MongoDB, Redis allows the user to store vast amounts of data without the limits of a relational database.
Additionally, it has also been compared to memcache and can be used, with its basic elements as a cache with persistence.
Website :- http://redis.io/download
Redis Installation by “apt” Repository –
Write the following code in it.
Step1 :- sudo nano /etc/apt/sources.list
deb http://packages.dotdeb.org squeeze all
deb-src http://packages.dotdeb.org squeeze all
Step2 :- wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | sudo apt-key add -
Step3 :- sudo add-apt-repository ppa:chris-lea/redis-server
Step4 :- sudo apt-get update
Step5 :- sudo apt-get install redis-server
Redis Installation using Source
Download, extract and compile Redis with:Step6 :- wget http://download.redis.io/redis-stable.tar.gz
OR wget http://download.redis.io/releases/redis-5.0.5.tar.gz
Step7 :- tar xzf redis-5.0.5.tar.gz OR tar xvzf redis-stable.tar.gz
Step8 :- cd redis-5.0.5 OR cd redis-stable
Step9 :- make
Step9 :- sudo apt-get install tcl8.5
Step10 :- make test
Step11 :- sudo make install
To access the script move into the utils directory
Step12 :- cd utils
Install script
Step13 :- sudo ./install_server.sh
You can start and stop redis with these commands
Step14 :- sudo service redis_6379 start
sudo service redis_6379 stop
The binaries that are now compiled are available in the src directory:
Step15 :- src/redis-server
Check if Redis is working
Step16 :- redis-cli OR redis-cli ping OR src/redis-cli
Step17 :- set foo bar
Step18 :- get foo
Output :- redis 127.0.0.1:6379>
To set Redis to automatically start at boot, run
Step19 :- sudo update-rc.d redis_6379 defaults
Install Redis as PHP Extension
You can start and stop redis with these commandsStep20 :- sudo apt-get -y install php5-redis
Install Redis extension of PHP using Source
Step21 :- sudo apt-get -y install php5-dev
Download phpredis from git repository
Step22 :- sudo apt-get -y install git
Step23 :- git clone git://github.com/nicolasff/phpredis.git
Compile and install phpRedis by running
Step24 :- cd phpredis
Step25 :- phpize
Step26 :- ./configure
Step27 :- make
Step28 :- sudo -s make install
Next we need to add extension with php configuration so that php can enable this
Step29 :- sudo -s
Step30 :- echo "extension=redis.so">/etc/php5/conf.d/redis.ini
To check Redis is working with php
Step31 :- vi phpredis.php
Write the following code in the phpredis.php
<?php
redis=new Redis() or die("Can not load Redis.");
$redis->connect('127.0.0.1');
$redis->set('Redis test_key', 1);
Run the phpredis.php file either using your browser or command line
Step32 :- php phpredis.php
Redis Operations
Step8 :- SET users:CloudNetwork "job: CEO, born:1988, dislikes: cherry trees“
Step8 :- GET users:CloudNetwork
Ranges:
Step8 :- LRANGE ROYGBV 0 3
1) "red"
2) "orange"
3) "yellow"
4) "green“
Expiration:
Step8 :- SET classified:information "Secret Stuff“
EXPIRE classified:information 45
TTL classified:information
GET classified:information
Removing Redis 5.0.5
Step33 :- sudo apt-get remove redis-serverOR
Step34 :- sudo apt-get purge--auto-remove redis-server