当前位置:网站首页>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
边栏推荐
猜你喜欢

endian mode

What is a system?

A brief introduction to the CheckBox component of the basic components of Flutter

大小端模式

TCP详解(一)
![[C language] Preprocessing operation](/img/69/0aef065ae4061edaf0d96b89846bf2.png)
[C language] Preprocessing operation

TCP详解(二)

TCP和UDP详解

The application and practice of mid-to-platform brand advertising platform

Know the showTimePicker method of the basic components of Flutter
随机推荐
Pytest电商项目实战(上)
Distributed locks and three implementation methods
web容器及IIS --- 中间件渗透方法1
观察者模式
[C language] General method of expression evaluation
CloudCompare&PCL 计算两个点云之间的重叠度
【AUTOSAR-RTE】-4-Port和Interface以及Data Type
$attrs/$listeners
3.5 】 【 Cocos Creator slow operating system to stop all animations
The els block moves the boundary to the right, and accelerates downward.
What is SQALE
安全20220715
[Swift]自定义点击APP图标弹出的快捷方式
LocalDate加减操作及比较大小
C primer plus学习笔记 —— 8、结构体
Problems that need to be solved in distributed system architecture
A brief introduction to the CheckBox component of the basic components of Flutter
日志级别 和 打印log注意
beforeDestroy与destroyed的使用
MultipartFile file upload