Reader small image

You're reading from  Learning Redis

Product typeBook
Published inJun 2015
Reading LevelIntermediate
Publisher
ISBN-139781783980123
Edition1st Edition
Languages
Right arrow
Author (1)
Vinoo Das
Vinoo Das
author image
Vinoo Das

Vinoo Das has 16 years of experience in the software industry and has worked in various domains, such as telecom, banking, payment gateways, information management, and so on. He is highly motivated and loves to work on new and upcoming technologies. He is currently architecting a platform for an information technology giant, which will enable the company to position the platform at an enterprise level as well as a cloud solution.
Read more about Vinoo Das

Right arrow

Chapter 2. Getting Started with Redis

Redis is a key-value-based NoSQL datastore developed by Salvatore Sanfilippo, launched in 2009. The name Redis comes from REmote DIctionary Server. Redis is a high-performing single thread server in C.

Redis can be installed on all POSIX-compliant Unix systems. Though there is no production grade release of a Windows system, it can still be installed in a Windows environment for development purposes. In this chapter, we will install Redis in Windows and Mac OS environments, write programs in Java, and play with the in-built client that comes along with the distribution.

Installing Redis on Windows


Microsoft Open Tech group has ported Redis and maintains it for win32/win64 machines. There are two ways in which we can get started with installing Redis on Windows, and these are listed as follows:

  • Working with prebuilt binaries

  • Getting the code and compiling it in the Microsoft environment

For the impatient, downloading the binaries of Redis 2.8 is an easier option. First things first, we need to do the following in order to get started:

  1. Go to https://github.com/MSOpenTech/redis and download the ZIP file under the Clone in Desktop button. For this book, we are going to download the latest version of Redis, that is, the redis-2.8.zip file.

  2. Right-click on the link and save it in a suitable location on your Windows machine. I have saved it at F:\sw2\redis\redis-2.8.zip.

  3. Right-click and unzip the compressed file to a suitable folder. I have named the folder as redis-2.8, and the folder structure after unzipping looks similar to what is shown in the following screenshot...

Installing Redis on Mac OS


Installing Redis is really simple on a Mac OS. Follow these steps and you are good to go:

  1. Download the package from Internet. For this, you can use the following command: wget http://download.redis.io/releases/redis-2.8.3.tar.gz

  2. Untar the compressed tar xzf redis-2.8.3.tar.gz file.

  3. This will create a folder; go to the folder by issuing the cd redis-2.8.3 command.

  4. Compile the file by issuing the make command. This will compile the binaries and create a folder structure, as shown in the following screenshot:

    Folder structure for a Mac distribution

  5. Type the src/redis-server command; this will start the server, as shown in the following screenshot:

    Starting the Redis server in the Apple environment

  6. Your Redis server is running and it is ready to accept the requests in port 6379. Open another terminal and go the same folder form where you installed Redis. Type the command src/redis-client; this will start the client shell, as shown in the following screenshot:

    Redis client...

Hello World in Redis


This section will excite programmers the most. Let's get our hands dirty and punch in some code. But, before that, we have to understand that Redis works on a client-server model and uses the Redis protocol to communicate with the server. For the client to connect to the server, the client has to know the location of the server. For this section, I am going to show samples using the redis-cli and Java clients.

Hello World using redis-cli

Start the Redis client Command Prompt (make sure that the server is running). Type in the following commands, as shown in the following screenshot, and see the outcome:

Trying simple Set and Get commands using the Redis client

There are three parts to the command we wrote. They are explained as follows:

  • Set: This command is used to set a value in the Redis server

  • MSG: This is the key for the message to be stored in the Redis server

  • Hello World: This is the value stored in the server for the MSG key

So, this clears a pattern that we have to...

Summary


Redis is a simple key-value oriented NoSQL, which can be used as a cache server and as a persistence server. This chapter showcased how simple it is to install Redis in multiple environments, including Windows (Redis can also be used in cloud environments, such as Amazon EC2). The installation for Windows should be used for development and sampling purposes only.

Redis has an interesting set of data structures, and it is sometimes called the data structure server. The next chapter will cover data structure in detail.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learning Redis
Published in: Jun 2015Publisher: ISBN-13: 9781783980123
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Vinoo Das

Vinoo Das has 16 years of experience in the software industry and has worked in various domains, such as telecom, banking, payment gateways, information management, and so on. He is highly motivated and loves to work on new and upcoming technologies. He is currently architecting a platform for an information technology giant, which will enable the company to position the platform at an enterprise level as well as a cloud solution.
Read more about Vinoo Das