-
Notifications
You must be signed in to change notification settings - Fork 1
/
getZsetAllTemplet.go
60 lines (50 loc) · 1.69 KB
/
getZsetAllTemplet.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
package src
import (
goredis "github.com/adimax2953/go-redis"
logtool "github.com/adimax2953/log-tool"
)
// GetZsetAll function - keys, args[] string - return int64 , error
func (s *MyScriptor) GetZsetAll(keys, args []string) (*[]RedisResult, error) {
res, err := s.Scriptor.ExecSha(GetZsetAllID, keys, args)
if err != nil {
logtool.LogError("GetZsetAll ExecSha Error", err)
return nil, err
}
reader := goredis.NewRedisArrayReplyReader(res.([]interface{}))
count := len(res.([]interface{}))
result := make([]RedisResult, count)
for i := 0; i < count; i++ {
r := &RedisResult{}
r.Value = reader.ReadString()
// r.Value2 = reader.ReadString()
result[i] = *r
if err != nil {
logtool.LogError("GetZsetAll Value Error", err)
}
}
return &result, nil
}
// GetZsetAll - 寫入一個字串
const (
GetZsetAllID = "GetZsetAll"
GetZsetAllTemplate = `
--[[
Author : Adimax.Tsai
Description : GetZsetAll
EVALSHA <script_sha1> 0 {DBKey} {ProjectKey} {TagKey} {k1}
--]]
local DBKey = tonumber(KEYS[1])
local ProjectKey = KEYS[2]
local TagKey = KEYS[3]
local k1 = ARGV[1]
local k2 = tonumber(ARGV[2])
local k3 = tonumber(ARGV[3])
local sender = "GetZsetAll.lua"
if DBKey and ProjectKey and TagKey and k1 then
local MAIN_KEY = ProjectKey..":"..TagKey..":"..k1
redis.call("select",DBKey)
local tmp = redis.call('zrange',MAIN_KEY , k2, k3)
return tmp
end
`
)