Redis has quickly become one of my favorite NOSQL databases. It's much more than a key-value store. It's self-described as a data structures server. It stores several types of structures, lists, sets, sorted sets, hashes and more. Learn more about Redis and data types here.

These are some of my favorite features of Redis. Notice most include the word easy. I like easy. These are just a few.

  • It's easy to install and setup.
  • It's easy to manage.
  • It's easy to insert/retrieve data.
  • It's easy to create relationships across data structures.
  • It has a very small footprint (prior to adding data and even with data since it's so efficient).
  • It's easy to leverage with Perl, Python and other scripting tools.
  • It's fast.

I often pull data from numerous sources to build relationships for reporting purposes. Redis makes the perfect repository for this type of activity. I'll talk more about this is future post, but for now we'll focus on bringing up a Redis database and some basic commands.

So doing this in ten minutes or less does require some upfront preparation. I'm going to start with a core Turnkey Linux image, install some necessary software and create a redis user and group. If you prefer, use a different user/group for your setup. I'm using Oracle's VirtualBox to run my Linux VM and Putty for SSH connectivity.



# Get the basic TurnkeyLinux core image (turnkey-core-14.1-jessie-amd64.ova), Import the OVA into Vbox.
Start the VM. Do initial setup on screens as prompted.

Putty to new VM as root (password was set during initial setup)

####Create redis user/group and set a password
# groupadd redis
# useradd -d /home/redis -g redis -s /bin/bash -m redis

#### Set redis password
# passwd redis
 
####Install additional Linux software
# apt-get update
# apt-get install make
# apt-get install gcc
# apt-get install libc6-dev
# apt-get install sudo

####Edit /etc/sudoers and add redis user. Adjust as you need.
redis   ALL=(ALL:ALL) ALL

Now that we have a base install ready to go, we can start the clock. We'll download Redis, run a make and move the executables to a suitable directory. Finally we'll fire it up and do some testing.


####redis server installation start (v3.0.7)
################################
# cd /tmp
# wget http://download.redis.io/releases/redis-3.0.7.tar.gz
# tar xzf redis-3.0.7.tar.gz
# cd redis-3.0.7
# make

####Copy executables to destination directory of your choice.####
#  mkdir /usr/local/redis
# cd src
# find . -type f -executable -exec cp {} /usr/local/redis \;

# cd /usr/local
# chown -R redis:redis redis
# sudo su - redis
$ cd /usr/local/redis

#####Run the redis server
$ ./redis-server

####Open up another ssh connection as redis user and test the server.
$ /usr/local/redis/redis-cli
127.0.0.1:6379> set foo bar
OK

127.0.0.1:6379> get foo
"bar"

127.0.0.1:6379> del foo
(integer) 1

127.0.0.1:6379> get foo
(nil)

127.0.0.1:6379> quit

####The redis server is up and running!

Stop the clock. That's it! You have a very basic, but functional server running. If you want to make it more suitable for practical use, the next section will cover some of those items. Customize as you need.


####Extra steps
# Do some additional configuration to make the installation a more functional server
###As user redis
$ cd /usr/local/redis
$ mkdir etc run database scripts logs

####Create a redis.conf file
#https://raw.githubusercontent.com/antirez/redis/3.0/redis.conf
$ cd etc
$ vi redis.conf

###Edit these lines
daemonize yes
pidfile /usr/local/redis/run/redis.pid
logfile "/usr/local/redis/logs/redis.log"
dbfilename redis.rdb
dir /usr/local/redis/database/
maxclients 32
appendfilename "redis.aof"

####Run the redis server with this configuration
# /usr/local/redis/redis-server /usr/local/redis/etc/redis.conf

Use the scripts sub directory to holds any custom scripts you need such as start, stop, status, cleanup, etc.

If you want to leverage Perl, install the Redis module. It supports most of the Redis commands you'll likely want to use.


###Perl and the Redis module
# cpan
cpan[1]> install Redis
cpan[1]> quit

We'll take a look at some practical use cases with perl in a future post.

Comments

There are no comments on this post.

Recent Posts

Archives


Contact Cecil