Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Redis Essentials
Redis Essentials

Redis Essentials: Harness the power of Redis to integrate and manage your projects efficiently

Arrow left icon
Profile Icon Maxwell Dayvson da Silva
Arrow right icon
AU$24.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6 (18 Ratings)
Paperback Sep 2015 230 pages 1st Edition
eBook
AU$33.99 AU$48.99
Paperback
AU$60.99
Subscription
Free Trial
Renews at AU$24.99p/m
Arrow left icon
Profile Icon Maxwell Dayvson da Silva
Arrow right icon
AU$24.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6 (18 Ratings)
Paperback Sep 2015 230 pages 1st Edition
eBook
AU$33.99 AU$48.99
Paperback
AU$60.99
Subscription
Free Trial
Renews at AU$24.99p/m
eBook
AU$33.99 AU$48.99
Paperback
AU$60.99
Subscription
Free Trial
Renews at AU$24.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $24.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Redis Essentials

Chapter 2. Advanced Data Types (Earning a Black Belt)

This chapter introduces the Set, Sorted Set, Bitmap, and HyperLogLog data types. It is a continuation from the previous chapter, and it also introduces new commands through redis-cli and Node.js, along with some details of the internals of each data type.

Sets

A Set in Redis is an unordered collection of distinct Strings—it's not possible to add repeated elements to a Set. Internally, a Set is implemented as a hash table, which is the reason that some operations are optimized: member addition, removal, and lookup run in O(1), constant time.

The Set memory footprint will be reduced if all the members are integers, and the total number of elements can be as high as the value of the set-max-intset-entries configuration. Chapter 4, Commands (Where the Wild Things Are), provides more details about this configuration.

The maximum number of elements that a Set can hold is 232-1, which means that there can be more than 4 billion elements per Set.

Some use cases for Sets are:

  • Data filtering: For example, filtering all flights that depart from a given city and arrive in another
  • Data grouping: Grouping all users who viewed similar products (for example, recommendations on Amazon.com)
  • Membership checking: Checking whether a user is on a blacklist...

Sorted Sets

A Sorted Set is very similar to a Set, but each element of a Sorted Set has an associated score. In other words, a Sorted Set is a collection of nonrepeating Strings sorted by score. It is possible to have elements with repeated scores. In this case, the repeated elements are ordered lexicographically (in alphabetical order).

Sorted Set operations are fast, but not as fast as Set operations, because the scores need to be compared. Adding, removing, and updating an item in a Sorted Set runs in logarithmic time, O(log(N)), where N is the number of elements in a Sorted Set. Internally, Sorted Sets are implemented as two separate data structures:

  • A skip list with a hash table. A skip list is a data structure that allows fast search within an ordered sequence of elements.
  • A ziplist, based on the zset-max-ziplist-entries and zset-max-ziplist-value configurations.

    Note

    Chapter 4, Commands (Where the Wild Things Are), provides more details about these configurations.

Sorted Sets could be...

Bitmaps

A Bitmap is not a real data type in Redis. Under the hood, a Bitmap is a String. We can also say that a Bitmap is a set of bit operations on a String. However, we are going to consider them as data types because Redis provides commands to manipulate Strings as Bitmaps. Bitmaps are also known as bit arrays or bitsets.

A Bitmap is a sequence of bits where each bit can store 0 or 1. You can think of a Bitmap as an array of ones and zeroes. The Redis documentation refers to Bitmap indices as offsets. The application domain dictates what each Bitmap index means.

Bitmaps are memory efficient, support fast data lookups, and can store up to 232 bits (more than 4 billion bits).

See this example of a Bitmap with three bits turned on and two turned off:

Bitmaps

A Bitmap with one Set on offsets 0, 3, and 4 and zero Set on offsets 1 and 2

In order to see how a Bitmap can be memory efficient, we are going to compare a Bitmap to a Set. The comparison scenario is an application that needs to store all user...

HyperLogLogs

A HyperLogLog is not actually a real data type in Redis. Conceptually, a HyperLogLog is an algorithm that uses randomization in order to provide a very good approximation of the number of unique elements that exist in a Set. It is fascinating because it only runs in O(1), constant time, and uses a very small amount of memory—up to 12 kB of memory per key. Although technically a HyperLogLog is not a real data type, we are going to consider it as one because Redis provides specific commands to manipulate Strings in order to calculate the cardinality of a set using the HyperLogLog algorithm.

The HyperLogLog algorithm is probabilistic, which means that it does not ensure 100 percent accuracy. The Redis implementation of the HyperLogLog has a standard error of 0.81 percent. In theory, there is no practical limit for the cardinality of the sets that can be counted.

The HyperLogLog algorithm was described originally in the paper HyperLogLog: The analysis of a near-optimal cardinality...

Summary

This chapter presented advanced data types: Sets, Sorted Sets, Bitmaps, and HyperLogLogs. These were presented along with real use cases and examples using redis-cli and Node.js.

The next chapter is going to explain how to build a feature-complete Time Series system with Redis in Node.js using Strings, Hashes, and HyperLogLogs. It will support querying multiple granularities, data consolidation, and automatic data expiration.

Left arrow icon Right arrow icon

Description

Redis is the most popular in-memory key-value data store. It's very lightweight and its data types give it an edge over the other competitors. If you need an in-memory database or a high-performance cache system that is simple to use and highly scalable, Redis is what you need. Redis Essentials is a fast-paced guide that teaches the fundamentals on data types, explains how to manage data through commands, and shares experiences from big players in the industry. We start off by explaining the basics of Redis followed by the various data types such as Strings, hashes, lists, and more. Next, Common pitfalls for various scenarios are described, followed by solutions to ensure you do not fall into common traps. After this, major differences between client implementations in PHP, Python, and Ruby are presented. Next, you will learn how to extend Redis with Lua, get to know security techniques such as basic authorization, firewall rules, and SSL encryption, and discover how to use Twemproxy, Redis Sentinel, and Redis Cluster to scale infrastructures horizontally. At the end of this book, you will be able to utilize all the essential features of Redis to optimize your project's performance.

Who is this book for?

If you are a competent developer with experience of working with data structure servers and want to boost your project's performance by learning about features of Redis, then this book is for you.

What you will learn

  • Build analytics applications using Bitmaps and Hyperloglogs
  • Enhance scalability with Twemproxy, Redis Sentinel, and Redis Cluster
  • Build a Time Series implementation in Node.js and Redis
  • Create your own Redis commands by extending Redis with Lua
  • Get to know security techniques to protect your data (SSL encryption, firewall rules, basic authorization)
  • Persist data to disk and learn the trade-offs of AOF and RDB
  • Understand how to use Node.js, PHP, Python, and Ruby clients for Redis
  • Avoid common pitfalls when designing your next solution

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 08, 2015
Length: 230 pages
Edition : 1st
Language : English
ISBN-13 : 9781784392451
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $24.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Sep 08, 2015
Length: 230 pages
Edition : 1st
Language : English
ISBN-13 : 9781784392451
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
AU$24.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
AU$249.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts
AU$349.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total AU$ 212.97
Redis Essentials
AU$60.99
Mastering Redis
AU$83.99
Learning Redis
AU$67.99
Total AU$ 212.97 Stars icon
Banner background image

Table of Contents

10 Chapters
1. Getting Started (The Baby Steps) Chevron down icon Chevron up icon
2. Advanced Data Types (Earning a Black Belt) Chevron down icon Chevron up icon
3. Time Series (A Collection of Observations) Chevron down icon Chevron up icon
4. Commands (Where the Wild Things Are) Chevron down icon Chevron up icon
5. Clients for Your Favorite Language (Become a Redis Polyglot) Chevron down icon Chevron up icon
6. Common Pitfalls (Avoiding Traps) Chevron down icon Chevron up icon
7. Security Techniques (Guard Your Data) Chevron down icon Chevron up icon
8. Scaling Redis (Beyond a Single Instance) Chevron down icon Chevron up icon
9. Redis Cluster and Redis Sentinel (Collective Intelligence) Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6
(18 Ratings)
5 star 72.2%
4 star 22.2%
3 star 0%
2 star 0%
1 star 5.6%
Filter icon Filter
Top Reviews

Filter reviews by




Francisco Oct 29, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a really good Redis book. I do have a good experience working with Redis, and was still able to profit from this book. The book goes from the very basic (installing Redis and running the first command with redis-cli) to more advanced features and techniques (using Redis as a time-series database or the inner workings of Redis Cluster and Sentinel), always with a good coverage of real-world examples.I also liked the way the authors presented the problems related to replication and sharding and then presented the official tools for that, giving a good notion on how the actual history happened, as Redis wasn't designed in the first place with replication and sharding in mind. The authors do show to have large experience in the topic, and the book is also very well written. Definitely a good book to have in the collection.
Amazon Verified review Amazon
Jim Fathman Oct 25, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is the Redis book I have been waiting for. It introduces fundamental operations using the Redis command line interface, and then shows useful examples of the same operations using Node.js. The combination of Node.js and Redis is a popular mix, so the approach in this book should appeal to a large audience of server side developers.The writing quality and editing is uncommonly good in this book. I am a fan of PACKT books which are frequently first to market for new technologies, but they are sometimes rushed and written by amateurs. Not so here. The authors and reviewers are legit, have solid technical chops, and it shows.I buy a lot of technical books from Amazon, read them, and sell them back to clear shelf space. I keep a few of the better books. This book is a keeper. I hope the authors will return with more excellent writing about other parts of the Node.js ecosystem.
Amazon Verified review Amazon
Amazon Customer Jun 07, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Lots of basic and not-so-obvious info.
Amazon Verified review Amazon
Steve L. Jan 05, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Fast delivery, would use again.
Amazon Verified review Amazon
wei lu Mar 19, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I like the content, although the book cover design needs a bit work; I've been using redis for a while, it was a great read, learn bunch tricks that I didn't know, and really like couple of interesting real world examples! Thumbs up!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.