-
Notifications
You must be signed in to change notification settings - Fork 1
/
scanMatchKeyTemplet.go
57 lines (48 loc) · 1.48 KB
/
scanMatchKeyTemplet.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
package src
import (
goredis "github.com/adimax2953/go-redis"
logtool "github.com/adimax2953/log-tool"
)
// ScanMatchKey function - keys, args[] string - return *[]RedisResult , error
func (s *MyScriptor) ScanMatchKey(keys, args []string) (*[]RedisResult, error) {
res, err := s.Scriptor.ExecSha(ScanMatchKeyID, keys, args)
if err != nil {
logtool.LogError("ScanMatchKey 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.Key = reader.ReadString()
result[i] = *r
if err != nil {
logtool.LogError("ScanMatchKey Value Error", err)
}
}
return &result, nil
}
// ScanMatchKey - 爬key
const (
ScanMatchKeyID = "ScanMatchKey"
ScanMatchKeyTemplate = `
--[[
Author : Adimax.Tsai
Description : ScanMatchKey
EVALSHA <script_sha1> 0 {DBKey} {Key} {Count}
--]]
local DBKey = tonumber(KEYS[1])
local Key = KEYS[2]
local Count = tonumber(KEYS[3])
local sender = "ScanMatchKey.lua"
local values = {}
redis.call('select',DBKey)
local result = redis.call('scan', 0, 'match' , Key.."*" ,'count', Count)
local keys = result[2]
for _, key in ipairs(keys) do
table.insert(values, key)
end
return values
`
)