当前位置:网站首页>Redis counts new and retained users
Redis counts new and retained users
2022-07-31 03:32:00 【Mar, fleeting years】
Article table of contents
Foreword
set (unordered, unique) sets provide methods like intersection, union, and difference.
You can use the set collection to count new users and retain users.
Statistics added
Assume that the system initially has five users, ID: 1,2,3,4,5
Set A to record users (cumulative users, that is, the users currently owned by the system)
sadd A 1sadd A 2sadd A 3sadd A 4sadd A 5Set B to record users (users who have logged in that day).
On the first day here, suppose 3 and 5 are logged in, and 6 is newly registered. When the system is successfully registered, it will log in to the system by default, so it will also be written in B.
sadd B 3sadd B 5sadd B 6The new user on the first day is the difference between B and A
By the way, make a new user record and use sdiffstore
# 6sdiff B A# Save B A difference to user_new:2022-07-28sdiffstore user_new: 2022-07-28 B AThe newly added user above is 6.In the end, 6 needs to be added to the cumulative user, set provides a method to obtain and save the union
# The first A stands for save there# Save A B set union overwrite to A# A has 1, 2, 3, 4, 5, 6 in itsunionstore A A BThe next day, let's say 3, 6 are logged in and 7, 8 are registered.This record is written to C, and B is kept as a historical record (B, C generally have names in the project similar to user: 2022-08-01).It can be processed according to the method of the first day (adding users: C,A difference, save C,A union to A)
sadd C 3sadd C 6sadd C 7sadd C 8Statistics of retained users
Statistics of users who logged in on the first day and logged in on the second day
Seek the intersection of C and B, and save it to user:keep
# Save the intersection of C and B to user:keepsinterstore user:keep C BDefects
Because the intersection, union and difference are more complicated.When the amount of data is relatively large, it will be very time-consuming.Since redis is a single process, it will cause the instance to block.
Solution 1: In master-slave mode, you can choose a slave library to execute.Due to read only from the library.As a result, sdiffstore, sinterstore, and sunionstore cannot be used.But you can use (sdiff,sinter,sunion) to get the result first, and then save it to the main library.
Solution 2: read it out, hand it over to the client program to disjoin, differ, and union
边栏推荐
- $parent/$children 与 ref
- SIP Protocol Standard and Implementation Mechanism
- 识Flutter 基本组件之showTimePicker 方法
- 选好冒烟测试用例,为进入QA的制品包把好第一道关
- Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢
- Mysql 45 study notes (twenty-four) MYSQL master-slave consistency
- SonarQube的BUG定义
- Redis 使用LIST做最新评论缓存
- Getting Started with CefSharp - winform
- 日志级别 和 打印log注意
猜你喜欢

Detailed explanation of TCP (3)

$attrs/$listeners

浅识Flutter 基本组件之CheckBox组件

STM32 problem collection

【动态规划】连续子数组的最大和

Recursive query single table - single table tree structure - (self-use)

Addition and Subtraction of Scores in LeetCode Medium Questions

安全20220712

Mysql 45 study notes (twenty-four) MYSQL master-slave consistency

刚出道“一战成名”,安全、舒适一个不落
随机推荐
安全20220712
Mysql 45 study notes (23) How does MYSQL ensure that data is not lost
Is interprofessional examination difficult?Low success rate of "going ashore"?Please accept this practical guide!
els block to the right
Pytest电商项目实战(上)
解析小结—自用
Redis implements distributed locks
LeetCode simple problem to find the subsequence of length K with the largest sum
False positives and false negatives in testing are equally worthy of repeated corrections
从滴滴罚款后数据治理思考
WebSocket Session is null
Web container and IIS --- Middleware penetration method 1
What skills do I need to learn to move from manual testing to automated testing?
TCP和UDP详解
MultipartFile文件上传
观察者模式
安全20220715
TCP详解(一)
LeetCode每日一练 —— OR36 链表的回文结构
C# remote debugging