We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
一些 SaaS 系统基于 Pricing 的考虑,会限制团队人数及同时在线数,如何实现
The text was updated successfully, but these errors were encountered:
一些 SaaS 系统基于定价策略的考虑,会限制团队人数及同时在线数,如何实现?
通过 redis 的 zset 可实现并发用户数。
redis
zset
当一个用户请求任何接口时,实现一个 middleware,处理以下逻辑
// 当一个用户访问任何接口时,对该用户Id,写入 zset await redis.zadd(`Organization:${organizationId}:concurrent`, Date.now(), `User:${userId}`) // 查询当前机构的并发数 // 通过查询一分钟内的活跃用户来确认并发数,如果超过则抛出特定异常 const activeUsers = await redis.zrangebyscore(`Organization:${organizationId}:concurrent`, Date.now() - 1000 * 60, Date.now()) // 查出并发数 const count = activeUsers.length // 删掉过期的用户 await redis.zrembyscore(`Organization:${organizationId}:concurrent`, Date.now() - 1000 * 60, Date.now())
Sorry, something went wrong.
No branches or pull requests
一些 SaaS 系统基于 Pricing 的考虑,会限制团队人数及同时在线数,如何实现
The text was updated successfully, but these errors were encountered: