Skip to content
Hoa Nguyen edited this page Aug 29, 2016 · 3 revisions

#Introduction

Redis is an open source, BSD licensed, advanced key-value cache and store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs. Deployment on a cluster involves modifying the redis.config file. Redis uses a sharded strategy with replication.

Each node:port can be the master or the replica of a shard. Since the default number of masters is minimum of 3, having a single replica would mean that we would need at least 6 nodes to run Redis distributed. Theoretically, you can have a node take care of two shards, by having both shards go to different ports.

#Setup Redis Redis will be installed on a single node.

Run the following by SSH-ing into the node:

node$ sudo apt-get update
node$ sudo apt-get install make gcc

Install Redis

node$ wget http://download.redis.io/redis-stable.tar.gz  -P ~/Downloads
node$ sudo tar zxvf ~/Downloads/redis-* -C /usr/local
node$ sudo mv /usr/local/redis-* /usr/local/redis

Set the REDIS_HOME environment variable and add to PATH in .profile

node$ nano ~/.profile

# Add the following
export REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/src

node$ source ~/.profile

Compile the Redis source files

node$ cd $REDIS_HOME
node$ sudo make distclean
node$ sudo make

Start Redis server

node$ sudo $REDIS_HOME/src/redis-server $REDIS_HOME/redis.conf &

#Python Redis Client

You can interact with Redis through a Python client by installing the following package

node$ sudo apt-get install python-pip
node$ sudo pip install redis

We can test out the installation and connection to the Redis server with the following:

node$ python
>>> import redis
>>> r = redis.StrictRedis(host='localhost', port=6379, db=0)
>>> r.set('foo', 'bar')
>>> r.get('foo')
'bar'
Clone this wiki locally