Skip to content

Commit

Permalink
feat: delete inactive users and index
Browse files Browse the repository at this point in the history
* missing files
  • Loading branch information
pajgo committed Oct 23, 2019
1 parent e5091a9 commit 18017ef
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/utils/inactive-user/redis/inactive-user.js
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;
26 changes: 26 additions & 0 deletions src/utils/user/redis/user.js
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;

0 comments on commit 18017ef

Please sign in to comment.