当前位置:网站首页>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边栏推荐
猜你喜欢
随机推荐
1个小时!从零制作一个! AI图片识别WEB应用!
9月备考PMP,应该从哪里备考?
【ES】ES2021 我学不动了,这次只学 3 个。
洛谷 P2440 木材加工
【kali-信息收集】(1.5)系统指纹识别:Nmap、p0f
不恰当Equatable协议==方法的实现对SwiftUI中@State修饰属性的影响
第58章 结构、纪录与类
网络不通?服务丢包?这篇 TCP 连接状态详解及故障排查,收好了~
ThreadLocal讲义
如何记录分析你的炼丹流程—可视化神器Wandb使用笔记【1】
Gradle系列——Gradle文件操作,Gradle依赖(基于Gradle文档7.5)day3-1
智能硬件开发怎么做?机智云全套自助式开发工具助力高效开发
Risc-v Process Attack
Pytorch模型训练实用教程学习笔记:二、模型的构建
Wildcard SSL/TLS certificate
LabVIEW 使用VISA Close真的关闭COM口了吗
【无标题】
【torch】张量乘法:matmul,einsum
WhatsApp群发实战分享——WhatsApp Business API账号
Arthas 常用命令









