Introduction to Redis

October 1, 2017    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

sudo yum -y install wget make gcc tcl

Redis installation

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

# redis info
redis-cli info

# testing
redis-cli ping
PONG

Configuring redis

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

sudo chkconfig --add redis_6379

 

Redis docker instance

Downloading redis image

docker pull redis:4.0.2

Running a redis container

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

Connect to it from an application

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