当前位置:网站首页>Redis does check-in statistics
Redis does check-in statistics
2022-08-01 20:01:00 【Mar, fleeting】
Article table of contents
Foreword
If there are only two states (yes or no) like check-in, binary state statistics can be used.bitmap conforms to binary state statistics (0,1), and takes up little space
Count check-ins in a month
Here takes user id: 1, August as an example, assuming 1, 3, 5, 7, 9 check-in
setbit sign:1:202208 1 1setbit sign:1:202208 3 1setbit sign:1:202208 5 1setbit sign:1:202208 7 1setbit sign:1:202208 9 1Count the number of check-in days in the current month
# get signed in for 5 daysbitcount sign: 1:202208Check if a day in the current month is checked in
# 3rd signed ingetbit sign:202208 3# No check-in on the 4thgetbit sign:202208 4Counting consecutive check-ins
It is not suitable to use user id + month as the key for continuous check-in statistics.
Here, the specific check-in days are used as the key, and the bit position is used as the user id.
Suppose 20220801, users 1, 3, 5, 7, and 9 check in.
setbit sing:20220801 1 1setbit sing:20220801 3 1setbit sing:20220801 5 1setbit sing:20220801 7 1setbit sing:20220801 9 120220802, users 3, 7, 9 check in
setbit sing:20220802 3 1setbit sing:20220802 7 1setbit sing:20220802 9 120220803, user 5, 9 signed in
setbit sing:20220803 5 1setbit sing:20220803 9 1Count the number of users who logged in on August 1, 2, and 3
# Put the bitwise AND results of the three dates into resultbitop and result sing:20220801 sing:20220802 sing:20220803# Statistics of consecutive check-ins# Only one user gets consecutive check-insbitcount result边栏推荐
猜你喜欢

57:第五章:开发admin管理服务:10:开发【从MongoDB的GridFS中,获取文件,接口】;(从GridFS中,获取文件的SOP)(不使用MongoDB的服务,可以排除其自动加载类)

【kali-信息收集】(1.2)SNMP枚举:Snmpwalk、Snmpcheck;SMTP枚举:smtp-user-enum

【多任务优化】DWA、DTP、Gradnorm(CVPR 2019、ECCV 2018、 ICML 2018)

面试突击70:什么是粘包和半包?怎么解决?

内网穿透 lanproxy部署

Wildcard SSL/TLS certificate

Risc-v Process Attack

第60章 ApplicationPart自动集成整体性和独立性插件项

数字孪生北京故宫,元宇宙推进旅游业进程

Acrel-5010重点用能单位能耗在线监测系统在湖南三立集团的应用
随机推荐
Pytorch模型训练实用教程学习笔记:一、数据加载和transforms方法总结
正则表达式
面试突击70:什么是粘包和半包?怎么解决?
9月备考PMP,应该从哪里备考?
17. Load balancing
MySQL开发技巧——存储过程
如何写一个vim插件?
图文详述Eureka的缓存机制/三级缓存
第56章 业务逻辑之物流/配送实体定义
终于有人把AB实验讲明白了
有序双向链表的实现。
密码学的基础:X.690和对应的BER CER DER编码
百度无人驾驶商业化已“上路”
突破边界,华为存储的破壁之旅
MySQL你到底都加了什么锁?
JS数组过滤
MySQL开发技巧——并发控制
泰德制药董事长郑翔玲荣膺“2022卓越影响力企业家奖” 泰德制药荣获“企业社会责任典范奖”
分享一个适用于MCU项目的代码框架
多线程之生产者与消费者