-
Notifications
You must be signed in to change notification settings - Fork 6
/
redis_keys.go
54 lines (42 loc) · 1.24 KB
/
redis_keys.go
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
package redis
import (
"fmt"
"github.com/saiya/dsps/server/domain"
)
type channelKeys struct {
// All keys must be prefixed with {channel-id} due to partioning.
channelID domain.ChannelID
}
func keyOfChannel(channelID domain.ChannelID) channelKeys {
return channelKeys{channelID: channelID}
}
// type of value is channelClock
func (rk channelKeys) Clock() string {
return fmt.Sprintf("c.{%s}.clock", rk.channelID)
}
// type of value is channelClock
func (rk channelKeys) SubscriberCursor(rcv domain.SubscriberID) string {
return fmt.Sprintf("c.{%s}.r.%s", rk.channelID, rcv)
}
// type of value is JSON
func (rk channelKeys) MessageBodyPrefix() string {
return fmt.Sprintf("c.{%s}.m.", rk.channelID)
}
// type of value is JSON
func (rk channelKeys) MessageBody(clock channelClock) string {
// MUST start with MessageBodyPrefix()
return fmt.Sprintf("c.{%s}.m.%d", rk.channelID, clock)
}
// type of value is channelClock
func (rk channelKeys) MessageDedup(id domain.MessageID) string {
return fmt.Sprintf("c.{%s}.mid.%s", rk.channelID, id)
}
type jtiKeys struct {
jti domain.JwtJti
}
func keyOfJti(jti domain.JwtJti) jtiKeys {
return jtiKeys{jti: jti}
}
func (jti jtiKeys) Revocation() string {
return fmt.Sprintf("jwt.{%s}.revoke", jti.jti)
}