Skip to content

Commit 18017ef

Browse files
committed
feat: delete inactive users and index
* missing files
1 parent e5091a9 commit 18017ef

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class InactiveUser {
2+
static REDIS_KEY = 'users-inactivated';
3+
4+
constructor(redis) {
5+
this.redis = redis;
6+
}
7+
8+
get(interval) {
9+
const expire = Date.now() - (interval * 1000);
10+
return this.redis.zrangebyscore(InactiveUser.REDIS_KEY, '-inf', expire);
11+
}
12+
13+
add(userId, createTime, redis = this.redis) {
14+
return redis.zadd(InactiveUser.REDIS_KEY, createTime, userId);
15+
}
16+
17+
remove(userId, redis = this.redis) {
18+
return redis.zrem(InactiveUser.REDIS_KEY, userId);
19+
}
20+
}
21+
22+
module.exports = InactiveUser;

src/utils/user/redis/user.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const DeleteCommand = require('./delete-command');
2+
3+
class User {
4+
constructor(redis) {
5+
this.redis = redis;
6+
}
7+
8+
delete(userId, redis = this.redis) {
9+
const deleteCommand = new DeleteCommand(redis);
10+
return deleteCommand.execute(userId);
11+
}
12+
13+
async getUserEmail(userIds) {
14+
const ids = Array.isArray(userIds) ? userIds : [userIds];
15+
const pipeline = this.redis.pipeline();
16+
17+
for (const id of ids) {
18+
pipeline.hget(`${id}!data`, 'username');
19+
}
20+
21+
const result = await pipeline.exec().map(([, res]) => res);
22+
return Array.isArray(userIds) ? result : result[0];
23+
}
24+
}
25+
26+
module.exports = User;

0 commit comments

Comments
 (0)