Introduction to Redis

Redis is an in-memory data structure store which can be used as database, cache or message broker.

Introduction

Redis is in-memory data structure store.

Can be used as:

  • Database
  • Cache
  • Message Broker

Supports:

  • Data structures (strings, hashes, lists, sets, sorted sets with range queries)
  • Bitmaps
  • Hyperloglogs
  • Geospatial indexes with radius queries

Features:

  • Built-in replication
  • Lua scripting
  • LRU eviction
  • Transactions
  • On-disk persistence
  • High availability via Redis Sentinel and automatic partitioning with Redis Cluster

Installation on CentOS 6.9

Install necessary packages

1
sudo yum -y install wget make gcc tcl

Redis installation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
cd /tmp/
wget http://download.redis.io/releases/redis-3.2.6.tar.gz

tar zxvf redis-3.2.6.tar.gz
cd redis-3.2.6

make test
sudo make install

cd utils
# redis executable path - enter this path - /usr/local/bin/redis-server
sudo ./install_server.sh

Verifying installation

1
2
3
4
5
6
# redis info
redis-cli info

# testing
redis-cli ping
PONG

Configuring redis

1
2
3
4
5
sudo vim /etc/sysctl.conf
vm.overcommit_memory=1

# apply changes without restarting server
sudo sysctl vm.overcommit_memory=1

Starting redis on system restart

1
sudo chkconfig --add redis_6379

 

Redis docker instance

Downloading redis image

1
docker pull redis:4.0.2

Running a redis container

1
docker run --name redis-6379 -p 6379:6379 -d redis:4.0.2

Connect to it from an application

1
docker run --name some-app --link some-redis:redis -d application-that-uses-redis