当前位置:网站首页>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 1
Count the number of check-in days in the current month
# get signed in for 5 daysbitcount sign: 1:202208
Check if a day in the current month is checked in
# 3rd signed ingetbit sign:202208 3# No check-in on the 4thgetbit sign:202208 4
Counting 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 1
20220802, users 3, 7, 9 check in
setbit sing:20220802 3 1setbit sing:20220802 7 1setbit sing:20220802 9 1
20220803, user 5, 9 signed in
setbit sing:20220803 5 1setbit sing:20220803 9 1
Count 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
边栏推荐
猜你喜欢
随机推荐
安装win32gui失败,解决问题
二维、三维、四维矩阵每个维度含义解释
内网穿透 lanproxy部署
ThreadLocal讲义
Greenplum数据库源码分析——Standby Master操作工具分析
洛谷 P2440 木材加工
密码学的基础:X.690和对应的BER CER DER编码
LTE时域、频域资源
【节能学院】安科瑞餐饮油烟监测云平台助力大气污染攻坚战
如何记录分析你的炼丹流程—可视化神器Wandb使用笔记【1】
Addition, Subtraction, Multiplication of Large Integers, Multiplication and Division of Large Integers and Ordinary Integers
9月备考PMP,应该从哪里备考?
把 Oracle 数据库从 RAC 集群迁移到单机环境
面试突击70:什么是粘包和半包?怎么解决?
漏刻有时文档系统之XE培训系统二次开发配置手册
第58章 结构、纪录与类
【七夕特别篇】七夕已至,让爱闪耀
【无标题】
根据Uniprot ID/PDB ID批处理获取蛋白质.pdb文件
MongoDB快速上手