-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: delete inactive users and index
* missing files
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class InactiveUser { | ||
static REDIS_KEY = 'users-inactivated'; | ||
|
||
constructor(redis) { | ||
this.redis = redis; | ||
} | ||
|
||
get(interval) { | ||
const expire = Date.now() - (interval * 1000); | ||
return this.redis.zrangebyscore(InactiveUser.REDIS_KEY, '-inf', expire); | ||
} | ||
|
||
add(userId, createTime, redis = this.redis) { | ||
return redis.zadd(InactiveUser.REDIS_KEY, createTime, userId); | ||
} | ||
|
||
remove(userId, redis = this.redis) { | ||
return redis.zrem(InactiveUser.REDIS_KEY, userId); | ||
} | ||
} | ||
|
||
module.exports = InactiveUser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const DeleteCommand = require('./delete-command'); | ||
|
||
class User { | ||
constructor(redis) { | ||
this.redis = redis; | ||
} | ||
|
||
delete(userId, redis = this.redis) { | ||
const deleteCommand = new DeleteCommand(redis); | ||
return deleteCommand.execute(userId); | ||
} | ||
|
||
async getUserEmail(userIds) { | ||
const ids = Array.isArray(userIds) ? userIds : [userIds]; | ||
const pipeline = this.redis.pipeline(); | ||
|
||
for (const id of ids) { | ||
pipeline.hget(`${id}!data`, 'username'); | ||
} | ||
|
||
const result = await pipeline.exec().map(([, res]) => res); | ||
return Array.isArray(userIds) ? result : result[0]; | ||
} | ||
} | ||
|
||
module.exports = User; |