Skip to main content

Redis Installation Steps

Redis is an in-memory key-value store known for its flexibility, performance, and wide language support” Inorder to install redis on your machine you need ubuntu 16.4 and a non-root user with sudo privileges to perform the administrative functions required for this process.
Download and Extract the Source Code
  • Create a tmp directory
    cd /tmp
  • Download the latest stable version of Redis
    curl -O
  • untar
    tar xzvf redis-stable.tar.gz
  • Move into the Redis source directory structure that was just extracted
    cd redis-stable

Build and Install Redis

  • Now, we can compile the Redis binaries by typing
  • After the binaries are compiled, run the test suite to make sure everything was built correctly. You can do this by typing:
    make test
  • This will typically take a few minutes to run. Once it is complete, you can install the binaries onto the system by typing:
    sudo make install

Configure Redis

Now that Redis is installed, we can begin to configure it.
  • To start off, we need to create a configuration directory. We will use the conventional ‘/etc/redisdirectory’ which can be created by typing
         sudo mkdir /etc/redis
  • Now, copy over the sample Redis configuration file included in the Redis source archive:
    sudo cp /tmp/redis-stable/redis.conf /etc/redis
  • Next, we can open the file to adjust a few items in the configuration
         sudo nano /etc/redis/redis.conf
  • In the file, find the supervised directive. Currently, this is set to no. Since we are running an operating system that uses the systemd init system, we can change this to systemd
. . .

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
# supervised no - no supervision interaction
# supervised upstart - signal upstart by putting Redis into SIGSTOP mode
# supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
# supervised auto - detect upstart or systemd method based on
# UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
# They do not enable continuous liveness pings back to your supervisor.
supervised systemd

. . .
  • Next, find the dir directory. This option specifies the directory that Redis will use to dump persistent data. We need to pick a location that Redis will have write permission and that isn't viewable by normal users.
  • We will use the /var/lib/redis directory for this, which we will create in a moment:
. . .

# The working directory.
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
# The Append Only File will also be created inside this directory.
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis

. . .
  • Save and close the file when you are finished.

Create a Redis systemd Unit File
  • Next, we can create a systemd unit file so that the init system can manage the Redis process. Create and open the /etc/systemd/system/redis.service file to get started:
    sudo nano /etc/systemd/system/redis.service
  • Inside, we can begin the [Unit] section by adding a description and defining a requirement that networking be available before starting this service
  • In the [Service] section, we need to specify the service's behavior. For security purposes, we should not run our service as root. We should use a dedicated user and group, which we will call redis for simplicity. We will create these momentarily.
  • To start the service, we just need to call the redis-server binary, pointed at our configuration. To stop it, we can use the Redis shutdown command, which can be executed with the redis-cli binary. Also, since we want Redis to recover from failures when possible, we will set the Restart directive to "always"
  • Finally, in the [Install] section, we can define the systemd target that the service should attach to if enabled (configured to start at boot):
Description=Redis In-Memory Data Store

ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown

  • Save and close the file when you are finished.

Create the Redis User, Group and Directories
  • Now, we just have to create the user, group, and directory that we referenced in the previous two files.Begin by creating the redis user and group. This can be done in a single command by typing:
         sudo adduser --system --group --no-create-home redis
  • Now, we can create the /var/lib/redis directory by typing:
         sudo mkdir /var/lib/redis
  • We should give the redis user and group ownership over this directory:
         sudo chown redis:redis /var/lib/redis
  • Adjust the permissions so that regular users cannot access this location:
         sudo chmod 770 /var/lib/redis

Start the Redis Service
  • Start up the systemd service by typing:
    sudo systemctl start redis

  • Check that the service had no errors by running:
    sudo systemctl status redis

Test the Redis Instance Functionality
  • To test that your service is functioning correctly, connect to the Redis server with the command-line client:

  • In the prompt that follows, test connectivity by typing:
    You should see:


Popular posts from this blog

Redis Basic CRUD

We have seen how to setup on your linux machine here , now we will see how to perform basic CRUD operations using Spring Data & Redis server We will be creating a simple application that would persist an employee information into redis database. You will be needing certain JARs like jedis.jar, spring-data-redis.jar etc details of which you can download and view at  First of all we will be creating the Employee entity, plz note that we are using the Serializable interface which automatically mapps the objects against the key. import ; public class Employee implements Serializable { private static final long serialVersionUID = - 8243145429438016231L ; public enum Gender { Male , Female } private String id; private String name; private Gender gender; private int age; public String getId () { return id; } public void setId ( String

CRUD in MongoDB & Spring Data

Now, since we have already been introduced to mongo and its server is setup. We shall now move on to performing basic CRUD operations. Lets take a use case example of ‘Company’ database that stores employee information.  We wish to store employee name, email address, age and multiple addresses. Traditionally in RDBMS we would create an Employee table and Address Table having foreign key reference to ‘employee id ‘ Incase of NoSQL, we will be creating Employee documnet which will have store employee information like name, email, age and an array of employes address. Following is a snippet of the schema defined { "name" : "", "email" : "", "age" : “”, "address" : [ ... ] } Thus to begin with, we will first define the entities. We have employee as an aggregate root entity that stores list of address having 1-M relatioship. Address Entity is represend as @Embeddable as it is embaded in another aggregate root entity. Employee is

Ribbon , Hysterix using Spring Feign

The idea about this post is show some concept of  Load Balancing  & Circuit Breaker  using Spring Cloud Netflix API. Load Balancing Load Balancing automatically distributes incoming application traffic between number of nodes running for given application. Ribbon  : This provide client side load balancing. Its component offers a good set of configuration options such as connection timeouts, retries, retry algorithm  etc. Strategies offered by ribbon are listed below: Simple Round Robin LB Weighted Response Time LB Zone Aware Round Robin LB Random LB Circuit Breaker pattern Netflix’s Hystrix library provides an implementation of the Circuit Breaker pattern: when we apply a circuit breaker to a method, Hystrix watches for failing calls to that method, and if failures build up to a threshold, Hystrix opens the circuit so that subsequent calls automatically fail. While the circuit is open, Hystrix redirects calls to the method, and they’re passed on to our specifi