/
redis_const.go
74 lines (69 loc) · 1.38 KB
/
redis_const.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
69
70
71
72
73
74
package redis
const (
ScriptLock = `
local res=redis.call('GET', KEYS[1])
if res then
return 0
else
redis.call('SET',KEYS[1],ARGV[1]);
redis.call('EXPIRE',KEYS[1],ARGV[2])
return 1
end
`
ScriptExpire = `
local res=redis.call('GET', KEYS[1])
if not res then
return 0
end
if res==ARGV[1] then
redis.call('EXPIRE', KEYS[1], ARGV[2])
return 1
else
return 0
end
`
ScriptDecrby = `
local res=redis.call('GET', KEYS[1])
if not res then
return 0
end
if tonumber(res)>=tonumber(ARGV[1]) then
redis.call('DECRBY', KEYS[1], ARGV[1])
return 1
else
return 0
end
`
ScriptIncrby = `
local res=redis.call('GET', KEYS[1])
if not res then
return 0
end
if tonumber(res) >= 0 then
redis.call('INCRBY', KEYS[1], ARGV[1])
return 1
else
return 0
end
`
ScriptDelete = `
local res=redis.call('GET', KEYS[1])
if not res then
return 0
end
if res==ARGV[1] then
redis.call('DEL', KEYS[1])
return 1
else
return 0
end
`
)
const (
tcpConnect = "tcp"
redisDefault = "default"
retryCount = 2
redisPreFixDefault = "default"
redisSleepTime = 10
redisCharacterMarkDefault = "-"
)