当前位置:网站首页>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 5
Set 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 6
The 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 A
The 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 B
The 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 8
Statistics 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 B
Defects
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
边栏推荐
猜你喜欢
7年经验,功能测试工程师该如何一步步提升自己的能力呢?
Mysql 45讲学习笔记(二十五)MYSQL保证高可用
LeetCode简单题之两个数组间的距离值
【Exception】The field file exceeds its maximum permitted size of 1048576 bytes.
IDEA 注释报红解决
MultipartFile file upload
Just debuted "Fight to Fame", safety and comfort are not lost
Ambiguous method call.both
[C language] Three-pointed chess (classic solution + list diagram)
LeetCode每日一练 —— 138. 复制带随机指针的链表
随机推荐
Annotation usage meaning
STM32 problem collection
Key Technologies of Interface Testing
立足本土,链接全球 | 施耐德电气“工业SI同盟”携手伙伴共赴未来工业
分布式锁以及实现方式三种
浅识Flutter 基本组件之CheckboxListTile组件
The application and practice of mid-to-platform brand advertising platform
大小端模式
CloudCompare & PCL calculate the degree of overlap between two point clouds
5. How does the SAP ABAP OData service support the $filter operation
Map.Entry理解和应用
Mysql 45 study notes (twenty-four) MYSQL master-slave consistency
Detailed explanation of TCP (1)
How to develop a high-quality test case?
安全20220709
遗留系统的自动化策略
识Flutter 基本组件之showTimePicker 方法
PMP微信群日常习题
【Exception】The field file exceeds its maximum permitted size of 1048576 bytes.
【编译原理】递归下降语法分析设计原理与实现