-
Notifications
You must be signed in to change notification settings - Fork 0
/
funnel.go
30 lines (23 loc) · 936 Bytes
/
funnel.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
package redisson
import (
"context"
"github.com/sandwich-go/funnel"
"time"
)
type funnelScriptBuilder struct{ c Cmdable }
type funnelScript struct{ s Scripter }
func (s funnelScriptBuilder) Build(src string) funnel.RedisScript {
return funnelScript{s: s.c.CreateScript(src)}
}
func (s funnelScript) EvalSha(ctx context.Context, keys []string, args ...any) ([]any, error) {
return s.s.EvalSha(ctx, keys, args...).Slice()
}
func (s funnelScript) Eval(ctx context.Context, keys []string, args ...any) ([]any, error) {
return s.s.Eval(ctx, keys, args...).Slice()
}
func newFunnel(c Cmdable, key string, capacity, operations int64, seconds time.Duration) funnel.Funnel {
return funnel.NewRedisFunnel(funnelScriptBuilder{c}, key, capacity, operations, seconds)
}
func (c *client) NewFunnel(key string, capacity, operations int64, seconds time.Duration) funnel.Funnel {
return newFunnel(c, key, capacity, operations, seconds)
}