-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Redis 4.x Cookbook

A bitmap (also known as a bit array, or bit vector) is an array of bits. A Redis bitmap is not a new data type; its actual underlying data type is string. Since a string is inherently a binary blob, it can be viewed as a bitmap. A bitmap saves enormous memory space for storing boolean information under certain circumstances.
In this recipe, we will use a bitmap to store a flag, whether or not a user has ever used a feature in Relp. Suppose that in Relp every user has a unique and incremental id, which can be denoted by the bitmap offset. The flag, which is a boolean attribute, can be denoted by the bit value in the bitmap.
You need to finish the installation of the Redis Server as we described in the Downloading and installing Redis recipe in Chapter 1, Getting Started with Redis.
The steps for using bitmaps are as follows:
redis-
cliSETBIT
to set the bit value in a bitmap at the specified offset.For example...