Redis Cache Tutorial – Setup

Download and Install Redis
Install Redis from the Ubuntu repositories:

$ sudo apt-get install redis-server
Redis Configuration

All Redis configuration options can be specified in the redis.conf file located
 at /etc/redis/redis.conf. You may wish to make a copy of this file before editing
 it, to retain default values in case of a problem
 down the line:

$ sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.default
Consider the following configuration:
daemonize yes
pidfile /var/run/redis.pid
logfile /var/log/redis.log

port 6379
bind 127.0.0.1
timeout 300

loglevel notice

## Default configuration options
databases 16

save 900 1
save 300 10
save 60 10000

rdbcompression yes
dbfilename dump.rdb

appendonly no

The values in this configuration mirror the default Redis configuration Ubuntu
provides. However, this configuration configures Redis to run ina daemon mode
bound only to the local network interface.
You may want to change these values depending on the needs of your application.

Check if Redis is working
External programs talk to Redis using a TCP socket and a Redis specific protocol.
This protocol is implemented in the Redis client libraries for the different
programming languages. However to make hacking with Redis simpler Redis provides
a command line utility that can be used to send commands to Redis. This program
is called redis-cli.
The first thing to do in order to check if Redis is working properly is sending a
PING command using
redis-cli:

$ redis-cli ping
PONG

Running redis-cli followed by a command name and its arguments will send this command
to the Redis instance running on localhost at port 6379. You can change the host and
port used by redis-cli, just try the --help option to check the usage information.
Another interesting way to run redis-cli is without arguments: the program will start
into an interactive mode where you can type different commands:

$ redis-cli                                                                
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379> set mykey somevalue
OK
redis 127.0.0.1:6379> get mykey
"somevalue"

References URL :

1. http://redis.io/topics/quickstart
2. http://library.linode.com/databases/redis/ubuntu-12.04-precise-pangolin
3. http://redis.io/clients

Add a Comment

Your email address will not be published. Required fields are marked *