当前位置:网站首页>Redis 做签到统计
Redis 做签到统计
2022-08-01 19:49:00 【Mar丶流年】
前言
像签到这种只有两种状态(是或否)的,可以使用二值状态统计。bitmap 符合二值状态统计(0,1),且占用空间小
统计某个月份内的签到情况
这里以用户id:1,8月份为例,假设1,3,5,7,9 签到
setbit sign:1:202208 1 1
setbit sign:1:202208 3 1
setbit sign:1:202208 5 1
setbit sign:1:202208 7 1
setbit sign:1:202208 9 1
统计当前月份签到天数
# 得到签到5天
bitcount sign:1:202208
查看当前月份某天是否签到
# 3号已签到
getbit sign:202208 3
# 4号未签到
getbit sign:202208 4
统计连续签到
统计连续签到就不太适合以用户id + 月份作为key了。
这里以具体签到天数作为key,以bit位置作为用户id。
假设20220801,用户1,3,5,7,9 签到。
setbit sing:20220801 1 1
setbit sing:20220801 3 1
setbit sing:20220801 5 1
setbit sing:20220801 7 1
setbit sing:20220801 9 1
20220802,用户3,7,9 签到
setbit sing:20220802 3 1
setbit sing:20220802 7 1
setbit sing:20220802 9 1
20220803,用户5,9 签到
setbit sing:20220803 5 1
setbit sing:20220803 9 1
统计 8月1,2,3 号都登录了的用户数量
# 将三个日期的bit 按位与结果 放入 result中
bitop and result sing:20220801 sing:20220802 sing:20220803
# 统计连续签到情况
# 得到连续签到的只有一个用户
bitcount result
边栏推荐
猜你喜欢
随机推荐
我的驾照考试笔记(3)
Creo5.0 rough hexagon is how to draw
nacos installation and configuration
In the background of the GBase 8c database, what command is used to perform the master-slave switchover operation for the gtm and dn nodes?
17. Load balancing
AcWing 797. 差分
【kali-信息收集】(1.5)系统指纹识别:Nmap、p0f
30天刷题计划(五)
XSS靶场中级绕过
JS数组过滤
Tencent Cloud Hosting Security x Lightweight Application Server | Powerful Joint Hosting Security Pratt & Whitney Version Released
升哲科技携全域数字化方案亮相2022全球数字经济大会
【kali-信息收集】(1.3)探测网络范围:DMitry(域名查询工具)、Scapy(跟踪路由工具)
openresty 动态黑白名单
Win11校园网无法连接怎么办?Win11连接不到校园网的解决方法
57:第五章:开发admin管理服务:10:开发【从MongoDB的GridFS中,获取文件,接口】;(从GridFS中,获取文件的SOP)(不使用MongoDB的服务,可以排除其自动加载类)
不要再使用MySQL online DDL了
{ValueError}Number of classes, 1, does not match size of target_names, 2. Tr
【webrtc】sigslot : 继承has_slot 及相关流程和逻辑
nacos安装与配置