/
RedisIdToSortedSet.js
84 lines (65 loc) · 2.06 KB
/
RedisIdToSortedSet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const Collection = require('../Collection')
class RedisIdToSortedSet extends Collection {
constructor(context) {
super(context, 1)
}
exists(id) {
return ['redis', 'exists', this.toKey(id)]
}
size(id) {
return ['redis', 'zcard', this.toKey(id)]
}
put(id, score, value) {
return ['redis', 'zadd', this.toKey(id), score, value]
}
inc(id, score, value) {
return ['redis', 'zincrby', this.toKey(id), score, value]
}
remove(id, value) {
return ['redis', 'zrem', this.toKey(id), value]
}
clear(id) {
return ['redis', 'del', this.toKey(id)]
}
getRank(id, value) {
return ['redis', 'zrank', this.toKey(id), value]
}
getScore(id, value) {
return ['redis', 'zscore', this.toKey(id), value]
}
getRange(id, from, count, withScores) {
const cmd = ['redis', 'zrange', this.toKey(id), from, from + count - 1]
if (withScores) cmd.push('withscores')
return cmd
}
getTopOne(id, withScores) {
const cmd=['redis', 'zrevrange', this.toKey(id), 0, 0]
if(withScores) cmd.push('withscores')
return cmd
}
getTop(id, size, withScores) {
const cmd=['redis', 'zrevrange', this.toKey(id), 0, size - 1]
if(withScores) cmd.push('withscores')
return cmd
}
getBottom(id, size, withScores) {
const cmd=['redis', 'zrange', this.toKey(id), 0, size - 1]
if(withScores) cmd.push('withscores')
return cmd
}
getList(id, withScores, minScore='-inf', maxScore='+inf') {
const cmd=['redis', 'zrangebyscore', this.toKey(id), minScore, maxScore]
if(withScores) cmd.push('withscores')
return cmd
}
removeBelow(id, score) {
return ['redis', 'zremrangebyscore', this.toKey(id), '-inf', score]
}
removeBottom(id, newSize) {
return ['redis', 'zremrangebyrank', this.toKey(id), 0, -(newSize+1)]
}
findKeys() {
return ['redis', 'keys' , this.toKey('*')]
}
}
module.exports = RedisIdToSortedSet