File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments