Break the data matrix. Explore what Redis has to offer.
When we discussed sharding HASHes, I briefly mentioned that if we’re storing short
sharded HASHes as a way of reducing memory use. But let’s say that we wanted to store
a short fixed amount of information for sequential IDs. Can we use even less memory
than sharded HASHes?
In this section, we’ll use sharded Redis STRINGs to store location information for
large numbers of users with sequential IDs, and discuss how to perform aggregate
counts over this stored data. This example shows how we can use sharded Redis
STRINGs to store, for example, location information for users on Twitter.
Before we start storing our data, we need to revisit four commands that’ll let us
efficiently pack and update STRINGs in Redis: GETRANGE, SETRANGE, GETBIT, and SETBIT.
The GETRANGE command lets us read a substring from a stored STRING. SETRANGE
will let us set the data stored at a substring of the larger STRING. Similarly, GETBIT will
fetch the value of a single bit in a STRING, and SETBIT will set an individual bit. With
these four commands, we can use Redis STRINGs to store counters, fixed-length
strings, Booleans, and more in as compact a format as is possible without compression.
With our brief review out of the way, let’s talk about what information we’ll store.
TRY REDIS ENTERPRISE CLOUD FREE
Redis Enterprise Cloud provides complete automation of day-to-day database operations. Start now with 30MB of free storage.
© 2022 Redis. Redis and the cube logo are registered trademarks of Redis Ltd.