Redis Extended Data Types: Stream, Geospatial, Bitmap, Bitfield, and HyperLogLog
This article introduces Redis's five extended data types—Stream, Geospatial, Bitmap, Bitfield, and HyperLogLog—explaining their concepts, common commands, and practical code examples, and highlights how they address specific internet‑scale scenarios more efficiently than traditional relational solutions.
In the previous article we introduced Redis's five basic data types; this article covers the five extended data types that are useful for specific scenarios.
1. Stream – an append‑only log structure used for message queues, event logging, and notifications. Each entry gets a unique, time‑ordered ID. Common commands include XADD , XREAD , XRANGE , and XLEN . Example:
127.0.0.1:6379> XADD mystream * name Tom age 23 height 178
"1709386483610-0"
127.0.0.1:6379> XREAD COUNT 1 STREAMS mystream 0
...
127.0.0.1:6379> XLEN mystream
(integer) 12. Geospatial – stores longitude/latitude pairs and enables radius queries. The main command is GEOADD key longitude latitude member .
3. Bitmap – bit‑level operations on string values, useful for counting, flags, and activity tracking. Commands include SETBIT , GETBIT , and BITCOUNT . Example:
# record login days
127.0.0.1:6379> SETBIT user-login 1 1
(integer) 0
127.0.0.1:6379> SETBIT user-login 3 1
(integer) 0
127.0.0.1:6379> BITCOUNT user-login
(integer) 24. Bitfield – treats a string as an array of bits, allowing arbitrary‑width integer reads, writes, and increments. It is ideal for counters and compact numeric storage.
5. HyperLogLog – provides approximate cardinality estimation with low memory usage. Commands include PFADD , PFCOUNT , and PFMERGE . Example:
127.0.0.1:6379> PFADD web-view "Tom" "John" "Tony"
(integer) 1
127.0.0.1:6379> PFCOUNT web-view
(integer) 3These extended types can simplify implementation of common internet‑scale use cases compared with relational databases. A mind‑map image summarizing all ten Redis data types is provided for quick reference.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.