当前位置:网站首页>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
边栏推荐
- BUG definition of SonarQube
- beforeDestroy与destroyed的使用
- QML的使用
- addressable in Golang
- Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢
- SQL Interview Questions (Key Points)
- How to develop a high-quality test case?
- The application and practice of mid-to-platform brand advertising platform
- [C language] General method of expression evaluation
- Observer pattern
猜你喜欢

什么是系统?

Redis实现分布式锁

Detailed explanation of TCP (1)

Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢

Daily practice of LeetCode - palindrome structure of OR36 linked list

IIR filter and FIR filter

Database implements distributed locks

LeetCode每日一练 —— OR36 链表的回文结构

web容器及IIS --- 中间件渗透方法1

Addition and Subtraction of Scores in LeetCode Medium Questions
随机推荐
Key Technologies of Interface Testing
[C language] General method of expression evaluation
Point Cloud DBSCAN Clustering (MATLAB, not built-in function)
(线段树) 基础线段树常见问题总结
【AUTOSAR-RTE】-4-Port和Interface以及Data Type
TCP详解(一)
Mysql 45 study notes (twenty-four) MYSQL master-slave consistency
MP使用时的几个常见报错
Recursive query single table - single table tree structure - (self-use)
PMP微信群日常习题
7年经验,功能测试工程师该如何一步步提升自己的能力呢?
2022 Nioke Multi-School League Game 4 Solution
Annotation usage meaning
STM32问题合集
beforeDestroy与destroyed的使用
C primer plus学习笔记 —— 8、结构体
5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
C# remote debugging
Redis实现分布式锁
MultipartFile文件上传