当前位置:网站首页>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
边栏推荐
- 浅识Flutter 基本组件之CheckBox组件
- STM32 problem collection
- Atomic operation CAS
- addressable in Golang
- False positives and false negatives in testing are equally worthy of repeated corrections
- TCP详解(二)
- With 7 years of experience, how can functional test engineers improve their abilities step by step?
- Daily practice of LeetCode - 138. Copy a linked list with random pointers
- LeetCode每日一练 —— 138. 复制带随机指针的链表
- Map.Entry理解和应用
猜你喜欢
What is a system?
【C语言】预处理操作
TCP和UDP详解
《DeepJIT: An End-To-End Deep Learning Framework for Just-In-Time Defect Prediction》论文笔记
STM32 problem collection
[C language] Three-pointed chess (classic solution + list diagram)
Just debuted "Fight to Fame", safety and comfort are not lost
Zotero如何删除自动生成的标签
一份高质量的测试用例如何养成?
Recursive query single table - single table tree structure - (self-use)
随机推荐
Know the showTimePicker method of the basic components of Flutter
Select the smoke test case, and make the first pass for the product package entering QA
Good place to download jar packages
some of my own thoughts
LeetCode每日一练 —— OR36 链表的回文结构
2022 Nioke Multi-School League Game 4 Solution
LeetCode simple problem to find the subsequence of length K with the largest sum
安全20220712
How to develop a high-quality test case?
「 每日一练,快乐水题 」1331. 数组序号转换
安全20220722
[C language] Preprocessing operation
自己的一些思考
(线段树) 基础线段树常见问题总结
Redis 使用 sorted set 做最新评论缓存
A brief introduction to the CheckboxListTile component of the basic components of Flutter
els 方块向左移动条件判断
Atomic operation CAS
Day32 LeetCode
[C language] Three-pointed chess (classic solution + list diagram)