当前位置:网站首页>Bitmap of redis principle
Bitmap of redis principle
2022-07-22 09:26:00 【yangyanping20108】
Data structure model
Modern computers use binary systems ( position ) As the basic unit of information ,1 Bytes are equal to 8 position , for example :big Strings are created by 3 Characters make up , But when stored in the computer, it is represented in binary ,big Respectively corresponding ASCII Here's the picture :
- BitMap It's not a data structure in itself , It's actually a string , But it can operate on the bits of a string .
- BitMap A separate set of commands is provided , So in Redis Use in BitMap and The methods of using strings are different , You can put BitMap Think of it as an array of bits , Each unit of an array can only store 0 and 1, The subscript of the array is in BitMap It's called offset .
command
This section stores whether each individual user has visited the website in BitMap in , Record the user you visited as 1, Do not visit users remember to do 0, Use offset as user's ID.
- Set up value :set key offset value
Set the number of the key offset The value of a bit ( from 0 Count up ) , Suppose now by 20 Users ,userId= 2,6,12,16,20 's users visited the site ( user Id reduce 1 by The array subscript ), Then the current BitMap The initialization result is shown in Figure :
The specific operation process is as follows : unique:users:20210602 representative 2021-06-02 This independent access to the user's BitMap.
offset = userId -1
127.0.0.1:6379> setbit unique:users:20210602 1 1
(integer) 0
127.0.0.1:6379> setbit unique:users:20210602 5 1
(integer) 0
127.0.0.1:6379> setbit unique:users:20210602 11 1
(integer) 0
127.0.0.1:6379> setbit unique:users:20210602 15 1
(integer) 0
127.0.0.1:6379> setbit unique:users:20210602 19 1
(integer) 0
127.0.0.1:6379>
If there is a userId = 30 's users visited the website , that BitMap Structure becomes graph :
2 obtain value :getbit key offset
userId= 2,6,12,16,20 's users visited the site ( user Id reduce 1 by The array subscript )
127.0.0.1:6379> getbit unique:users:20210602 1
(integer) 1
127.0.0.1:6379> getbit unique:users:20210602 5
(integer) 1
127.0.0.1:6379> getbit unique:users:20210602 11
(integer) 1
127.0.0.1:6379> getbit unique:users:20210602 15
(integer) 1
127.0.0.1:6379> getbit unique:users:20210602 19
(integer) 1
127.0.0.1:6379>
边栏推荐
- c语言之指针(四)
- LeetCode83 && LeetCode82: 删除排序链表中的重复元素
- 1978-2021 China Statistical Yearbook, 2003-2019 (provincial and municipal panel data), 1999-2019 (county panel data)
- odoo+测试
- 空转工具推荐 | 10款空间转录组去卷积工具的综合比较
- 数组
- Educational structure and calculated average years of education from 1989 to 2020
- Record of problems encountered
- Leetcode-468: verify IP address
- 异常类
猜你喜欢
Leetcode-12: integer to Roman numeral
核心技术
Failed to push the solo article to the community side
odoo+测试
Municipalités locales - importations, exportations et balance commerciale (2000 - 2020)
1978-2021 China Statistical Yearbook, 2003-2019 (provincial and municipal panel data), 1999-2019 (county panel data)
Thread多线程
GAN目标函数理解
Geospatial matrix by province, city and county: multi index data sets such as prefecture level city space and geographical distance matrix
Leetcode342:4 power
随机推荐
Redis原理之GEO
How to quickly develop a simple and practical MES system?
The request was rejected because the URL contained a potentially malicious String “//“
Mathematical operation
go Redis 管道(pipeline)运用
异常类
对称的res,aes,非对称rsa(jwt)的简单使用及区别
Go zero micro service practical series (III. API definition and table structure design)
Collection集合框架
从103个数中找到出现一次的那三个数
Analysis of copyonwritearraylist
队列(堆栈)
高频leetcode深搜部分:98. 验证二叉搜索树
Tool classes encapsulated based on redistemplate
Luoyang comprehensive bonded zone was officially approved by the State Council to be established
The multi indicator data of 4000+ listed companies' provinces, cities and operations have been updated to 2022.1
Docker系列 六. Docker 安装 Redis
JVM introduction
面试题 01.02. 判定是否互为字符重排
Laravel 关联模型的使用、一对一、一对多、多对多