-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.go
68 lines (62 loc) · 1.93 KB
/
cache.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package constants
import (
"fmt"
"time"
)
const (
RedisClientTypeReplica = 1
RedisClientTypeCluster = 2
)
const (
RedisLuaAssetChangeResCodeSuccess = 0
RedisLuaAssetChangeResCodeNoDone = -3
RedisLuaAssetChangeResCodeNoExists = -1
RedisLuaAssetChangeResCodeNoEnough = -2
)
const (
RedisKeyPrefixUserAssetInfo = "I.asset."
RedisKeyPrefixGiftInfo = "I.gift."
RedisKeyPrefixUserInfo = "I.user."
RedisKeyPrefixRoomInfo = "I.room."
RedisKeyPrefixUserAssetInfoLock = "L.asset."
RedisKeyPrefixAssetEventMsg = "M.asset."
)
const (
RedisKeyExpireUserAssetInfo = 86400 * time.Second
RedisKeyExpireGiftInfo = 7 * 86400 * time.Second
RedisKeyExpireUserInfo = 86400 * time.Second
RedisKeyExpireRoomInfo = 86400 * time.Second
RedisKeyExpireUserAssetInfoLock = 60 * time.Second
RedisKeyExpireAssetEventMsg = 86400 * time.Second
)
const (
DisLockerBlockRetryCn = 100
// MaxRetries Redis transactions use optimistic locking.
MaxRetries = 1000
)
const (
TimeOutSetAssetFromCB = 1 * time.Second
)
func GetUserAssetInfoKey(userId int64, assetType string) string {
return fmt.Sprintf("%s{%d}.{%s}", RedisKeyPrefixUserAssetInfo, userId, assetType)
}
func GetGiftInfoKey(giftId int64) string {
return fmt.Sprintf("%s{%d}", RedisKeyPrefixGiftInfo, giftId)
}
func GetUserInfoKey(userId int64) string {
return fmt.Sprintf("%s{%d}", RedisKeyPrefixUserInfo, userId)
}
func GetRoomInfoKey(roomId int64) string {
return fmt.Sprintf("%s{%d}", RedisKeyPrefixRoomInfo, roomId)
}
func GetUserAssetInfoLockKey(userId int64, tag string) string {
return fmt.Sprintf("%s{%d}.%s", RedisKeyPrefixUserAssetInfoLock, userId, tag)
}
func GetUserAssetEventMsgKey(userId int64, eventId string) string {
return fmt.Sprintf("%s{%d}.%s", RedisKeyPrefixAssetEventMsg, userId, eventId)
}
const (
UserAssetTxMethodCas = "cas"
UserAssetTxMethodLua = "lua"
UserAssetTxMethodFunctionLua = "function-lua"
)