In basic terms, Redis is a fast in-memory database and cache, written in C and designed specifically to optimize speed. With a name that is shorthand for “Remote Dictionary Server”. Redis is often referred to as a data structure server, primarily because Redis’ core data types are much like those found in programming languages like dictionaries (or hashes), lists, sets, sorted sets, and strings. It also offers many other data structures and features useful for approximate counting, stream processing, and geolocation.
Among the various NoSQL databases, Redis’ various data structures are most similar to the native data structures programmers usually use inside various common applications and algorithms. This similarity is a huge part of Redis’ appeal for many programmers and app designers and developers because the ease of use makes Redis ideal for efficient development and speedy applications, and because core data structures are easily shared between processes and services.
Beyond these basic advantages, Redis also has a growing variety of use cases that make it an attractive alternative to some of the other more popular NoSQL databases, such as MongoDB. Additionally, Redis has some unique structural and operational benefits that also contribute to its popularity. From ridesharing to gaming apps, rentals to companies looking for optimized data storage, the number of unique use cases and different companies adopting Redis to power their platforms has exploded in recent years and seems poised to continue to expand further in the future. In this guide, we’ll walk through some of the basics of Redis, as well as some of the most popular use cases and ways that Redis can be a big benefit for your next project.
What are some of the best features of Redis?
Streams and Stream Processing
Redis offers an excellent task queue and message broker with its lists and pub/sub messaging. In more recent versions of Redis (after version 5.0), the feature set was expanded to include streams and stream processing. Streams of work are particularly useful for processing “consumer” groups, which evaluate work and acknowledge when work has been completed. If no acknowledgement is received after a preset period of time has expired, then other consumers can pick up this work, assuring that work gets done and increasing productivity.
Publication and Subscription Messaging (Pub/Sub)
Pub/Sub messaging is a useful feature that enables messages to be passed to channels and make those messages visible to all subscribers to that channel. This feature streamlines information distribution and reception throughout an organization or digital infrastructure, all without using up space in the database since messages are only temporary. This is ideal for sending warnings or notifications of load on other pieces of infrastructure or applications, or even for updating gaming scores.
Redis features a scripting facility which allows for custom scripts to be written and executed in the Lua language. Through the form of fast-acting scripts, this allows users to specifically add features to Redis. Because Lua has extremely speedy initialization, this enables scripts to perform various functions and tasks on data without significantly affecting Redis’ speed or increasing downtime.
Redis also offers a series of geospatial index data structures and commands. For example, latitude and longitude coordinates are housed within and users can query distances between objects or filter for objects located within a given radius of a point. More usefully, these commands can return values in a variety of formats (feet, kilometers, etc.), allowing for usefulness in translating data across various systems of measurement.
Because Redis operates so quickly, these data points are updated equally quickly, making Redis an ideal option for something like a ridesharing application, by providing the functionality needed to geolocate users and drivers and offer real-time status updates (such as distance to a destination and estimated time of arrival). From major transportation companies, to ridesharing, to rental apps for things like scooters and bikes in urban areas, Redis is already supporting multiple apps in these market spaces.
The hyperloglog data structure allows for approximate set counting in a much smaller space, preferable to keeping a full unique set of items. For example, a simple counter can double count, and something like a set of user IDs or IPs would usually require a sizable amount of space. A hyperloglog allows a very small amount of memory to hold a good approximation of the unique objects, maximizing your database storage and keeping things running quickly and smoothly since extra space isn’t being eaten up unnecessarily.
Bitmaps enable highly efficient storage of True and False values as 1 or 0 inside Redis strings, which is far more efficient than other NoSQL alternatives. This offers a whole new set of use cases that something like MongoDB might not be able to provide. For example, bitmaps can be employed to efficiently store a user’s progress through some content, like online coding classes or a large file download. This type of data structuring can also provide notifications on a user’s online or offline status.
What are some additional benefits of using Redis?
A streamlined user interface
One of the biggest benefits of using Redis is the platform’s simplification of the use of common fundamental data structures between services and processes, all at topline speed. By using Lua scripts and modules, with all of their unique benefits, Redis can operate as an adaptive domain-specific language (DSL) for your data and be tweaked and edited to improve performance even further. The level of customization and intuitive structure offer a winning combination that most database platforms can’t match.
Ability to serve as a primary database
If the data size and risk profile are well understood and calibrated with Redis’ disk persistence model, then Redis can function as a primary database. This requires some careful consideration about a cluster topology with data replication, your app’s eviction policy settings, employing disk persistence, and incorporating automated backups. Disk persistence can be tailored or defaulted to write to disk on every new write, but this can reduce performance and slow down operating speeds.
All the benefits of being open-sourced
One of the major reasons for the popularity of Redis has been its completely open-sourced nature, operating under a BSD 3-clause license. Aside from avoiding vendor lock-in, open-sourcing offers access to high performance technologies and continued evolutions of the system as a result of solutions discovered by programmers already working with Redis infrastructure. Unlike other competitors, Redis simply offers a significant number of extra features which, coupled with the benefits of open-sourcing, make Redis a winning package for database architects and programmers.
Disk Persistence Flexibility
Redis can be configured to write to disk in two formats, a binary format and an “append only file” (AOF) format. The binary format mirrors what is in memory and is on by default. The AOF file can be turned on in the configuration and is a simple log of all commands which can be replayed to return a node to its previous state. Both can be configured to write to disk more or less frequently.
Warm Restart Capabilities
For critical caching deployments, especially in cases when Redis exists in front of slower infrastructure, these disk persistence options noted above allow for “warm restarts”. Without a warm restart capability, an empty cache that was handling traffic above the capacity of the infrastructure behind it would pass all that traffic through, potentially overwhelming that infrastructure. Warm restart functionality allows you to avoid catastrophic breakdowns in data operations, and ensure applications keep running at peak performance and speed that keeps customers or users happy.
A Growing Community of Loyal Users
The true test of any database or programming technology is a loyal fanbase, and by that metric Redis passes the test. According to the 2020 Stack Overflow developer survey, over 20% of developers were currently working with Redis, and that number is only expected to grow as the positive word-of-mouth continues to spread through developer communities. Redis has consistently received top ratings and consistent usage from a wide variety of developers working within various market verticals, with an equally consistent growth in the number of new use cases that ensure Redis will only continue to rise in popularity.
The loyal Redis fanbase also offers one additional benefit, one that it shares with many of the most popular programming tools and languages -- more developer fans means more people developing updates and tweaks to further maximize the potential of the platform. As more and more developers continue to tinker with and adopt Redis for their projects, expect the feature set to only continue to grow and meet the changing needs of various industries looking for an adaptive and efficient database technology.