In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "the use of bitmap in Redis". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Ingenious use of bitmap in Redis
We often use commands such as set,get in Redis. Have you noticed that there are several similar commands called setbit,getbit? what are they used for?
What is BitMap?
A bit bit is used to represent the corresponding value or state of an element, where the key is the corresponding element itself. We know that eight bit can make up a Byte, so the bitmap itself will greatly save storage space.
BitMap in Redis
Several bitmap-related commands such as setbit,getbit,bitcount have been added to Redis since version 2.2.0. Although it is a new command, no new data types have been added, because commands such as setbit are just extensions on set.
Introduction to setbit command
Instruction SETBIT key offset value
Complexity O (1)
Sets or clears the bit value of key's value (string) at offset (only 0 or 1).
Space occupancy and the time required to allocate space for the first time
On a 2010MacBook Pro, offset for 2 ^ 32-1 (assign 512MB) requires ~ 300ms offset for 2 ^ 30-1 (assign 128MB) requires ~ 80ms offset for 2 ^ 28-1 (assign 32MB) requires 8ms for ~ 30ms offset of 2 ^ 26-1 (assign 8MB).
The approximate formula for calculating the space occupation is: ($offset/8/1024/1024) MB
Use scenario 1: user check-in
Many websites provide check-in (data landing is not considered here), and need to show the check-in in the last month, what can we do if we use bitmap? Not a word, bright code!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.