Uncategorized
Redis short Description and steps to setup on linux system

Redis short Description and steps to setup on linux system

Redis is a “NoSQL” key-value data store, it is moreover called as a data structure server. Redis more over work as Memcached, but with Built-in persistence ( to disk) and more data-types.

Persistence to disk means you can use Redis as a real database, rather than having just data in a volatile cache. data will not be lost when you restart, like with Memcached.


Other than persistence more data types also make it for

Data Types

  • Strings
  • Hashes
  • lists
  • sets
  • sorted sets
  • bitmaps
  • hyperloglogs

And Redis provides atomic operations on above data types like:

  • Appending to a string
  • incrementing the value in a hash
  • pushing an element to a list
  • computing set intersection
  • union
  • difference
  • get the member with the highest rank in sorted set

Commands

  • monitor – Watch current live commands. Use this with care on production
  • keys – keys pattern (Reg expression) which is used to search keys.
  • del – Delete keys.
  • expire – set the expiration time of a key (eg. expire keyname 30 ).
  • exists – Checks it a key exists
  • get – get the key value
  • set – add and update key value
  • setnx – set the key only if key exists
  • mget – batch command of get (like mget <key> <key> …)
  • mset – batch command of set ( like mset <key> <value> <key> <value> ….)

Note there are many more commands which are like lrange,lindex,llen.. for more command please refer to Redis Commands.

Installation

For Ubuntu:

To install redis server and to configure it with PHP run below command

sudo apt-get install redis-server;

sudo apt-get install php5-redis;

## redis configuration file

sudo vi /etc/redis/redis.conf

Steps to configure Php to handle session using Redis

sudo vi /etc/php5/apache2/php.ini
## Find session.save_handler and change it’s value to redis
session.save_handler = redis
## Find session.save_path and change it’s value to IP:6379 (default port)

## after these changes run
sudo /etc/init.d/redis-server restart
sudo /etc/init.d/apache2 restart/reload

For Centos 6.5

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
yum install redis php-pecl-redis
service redis start
chkconfig redis on

sudo vi /etc/php.ini
## Find session.save_handler and change it’s value to redis
session.save_handler = redis
## Find session.save_path and change it’s value to IP:6379 (default port)

session.save_path = “127.0.0.1:6379”

## after these changes run
sudo /etc/init.d/redis restart
sudo /etc/init.d/httpd restart/reload

Leave a Reply

Your email address will not be published.

Enter Captcha Here : *

Reload Image