Company
Date Published
Author
Sandro Pasquali
Word count
1748
Language
English
Hacker News points
None

Summary

In this article, you'll learn how to perform bitwise operations on Redis keys, setting, getting and comparing binary values using well-named SETBIT and GETBIT commands. You can store much larger amounts of binary data by executing bit operations with Redis. By applying bitmasks mapping a range of bits to other binary values, you can make rapid and memory-efficient analytical comparisons. The BITOP-family of commands allow you to perform set and get bits on keys using bitwise operators AND, OR, and XOR. You can store binary data, such as user activity or win/loss records, using Redis and then use bit operations to analyze this data. These techniques are useful for creating a simple recommendation engine. The total number of bytes occupied by a binary value in Redis is calculated by dividing the largest offset by 8. Storing access data for 1,000,000 users on one article requires a maximum of ~125 kB, which gives confidence when planning storage costs and scaling.