-
Notifications
You must be signed in to change notification settings - Fork 1
/
redis-utils.go
36 lines (26 loc) · 876 Bytes
/
redis-utils.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
package redisOrderedQueue
import (
"github.com/go-redis/redis/v8"
"context"
)
type redisScriptCall func (ctx context.Context, client *redis.Client, args []interface{}, keys []string) (*redis.Cmd);
func newScriptCall (ctx context.Context, client *redis.Client, script string) (redisScriptCall, error) {
var scriptHash, err = client.Do(ctx, "SCRIPT", "LOAD", script).Text()
if (err != nil) {
return nil, err
}
var invoke = func (ctx context.Context, client *redis.Client, args []interface{}, keys []string) (*redis.Cmd) {
var packet []interface{}
packet = append(packet, "EVALSHA")
packet = append(packet, scriptHash)
packet = append(packet, len(keys))
for _, key := range(keys) {
packet = append(packet, key)
}
for _, arg := range(args) {
packet = append(packet, arg)
}
return client.Do(ctx, packet...);
}
return invoke, nil
}