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 3. Data Structures and Communicating Protocol in Redis

The previous chapter dealt with installation of Redis and running some simple programs. Since Redis is a datastore, so it's important to understand how Redis treats data by providing data structures to handle and store them. Also important is how Redis deals with data while communicating it to a client such as the communication protocol.

Data structures


Data structure, as the word suggests, means a structure for storing data. In the world of computing, data is always organized in a way that makes sense to the program storing it. Data structure can vary from a simple sequential arrangement of characters to a complex map where keys are not arranged sequentially, but on the basis of an algorithm. Data structures are often composite in nature, which means that one data structure can hold other data structure, which is a map holding another map.

The key influencing factors in designing a data structure are performance and memory management of the data structure. Some of the common examples of data structures are lists, sets, maps, graphs and trees, tuples, and so on. As programmers, we have used data structures in our programs time and again. In an object-oriented world, a simple object is also a data structure since it contains data, and logic to access those data. Every data structure is governed by an algorithm which decides...

Data types in Redis


Redis, a data structure server has many in-built data types, which makes it a bit different from other key-value NoSQL datastores in the ecosystem. Unlike other NoSQL, Redis provides the users with many in-built data types which provide a sematic way of arranging their data. Think of it like this; while designing a solution we need domain objects which in a way shape up our data layer. After deciding on the domain objects, we need to design the structure for our data that will be saved in the data store for which we need some predefined data structures. The advantage of this is that it saves time and efforts of the programmers to externally create and manage this data. For example, suppose in our program there is a requirement for a Set like data structure. Using Java, we can easily use an in-built data structure such as Set. If we were to put this data as a key-value, we will have to put the entire set against a key. Now if we were to sort this Set, the normal way would...

Communication protocol – RESP


Redis in principle works on a client-server model. So like in every client-server model, the client and the server need to have a protocol to communicate with. Communication protocol can be understood as a message exchange taking place between client and the server (and vice versa) based on some fixed agreement or rule between them. So every communication protocol has to adhere to some syntax and semantics, which should be followed by both the parties (client and server) for the communication to be successful. There is also another dimension to this communication protocol, which is the network layer interaction, or better known as TCP/IP Model. The TCP/IP Model can be divided into four parts:

  • Application layer

  • Transport layer

  • Internet layer

  • Network interface

Since the communication protocol between two applications is at application layer, so we intend to focus only on the application layer. The following diagram is a representation of what happens in the communication...

Summary


In this chapter, we brushed with various data structures or data types which Redis provides. We also wrote a few programs to see them working and made an attempt to understand how and where these data types can be used. Finally, we understood how Redis communicates with the clients and vice versa.

In the next chapter, we will take our understanding a notch higher and make an attempt to understand Redis Server and the functionality that'll handle it.

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