-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_hyperlog.go
62 lines (54 loc) · 2 KB
/
cmd_hyperlog.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
package redisson
import (
"context"
)
type HyperLogCmdable interface {
HyperLogWriter
HyperLogReader
}
type HyperLogWriter interface {
// PFAdd
// Available since: 2.8.9
// Time complexity: O(1) to add every element.
// ACL categories: @write @hyperloglog @fast
// RESP2 / RESP3 Reply:
// One of the following:
// - Integer reply: 1 if at least one HyperLogLog internal register was altered.
// - Integer reply: 0 if no HyperLogLog internal registers were altered.
PFAdd(ctx context.Context, key string, els ...any) IntCmd
// PFMerge
// Available since: 2.8.9
// Time complexity: O(N) to merge N HyperLogLogs, but with high constant times.
// ACL categories: @write @hyperloglog @slow
// RESP2 / RESP3 Reply:
// - Simple string reply: OK.
PFMerge(ctx context.Context, dest string, keys ...string) StatusCmd
}
type HyperLogReader interface {
// PFCount
// Available since: 2.8.9
// Time complexity: O(1) with a very small average constant time when called with a single key.
// O(N) with N being the number of keys, and much bigger constant times, when called with multiple keys.
// ACL categories: @read @hyperloglog @slow
// RESP2 / RESP3 Reply:
// - Integer reply: the approximated number of unique elements observed via PFADD
PFCount(ctx context.Context, keys ...string) IntCmd
}
func (c *client) PFAdd(ctx context.Context, key string, els ...any) IntCmd {
ctx = c.handler.before(ctx, CommandPFAdd)
r := c.adapter.PFAdd(ctx, key, els...)
c.handler.after(ctx, r.Err())
return r
}
func (c *client) PFCount(ctx context.Context, keys ...string) IntCmd {
ctx = c.handler.beforeWithKeys(ctx, CommandPFCount, func() []string { return keys })
r := c.adapter.PFCount(ctx, keys...)
c.handler.after(ctx, r.Err())
return r
}
func (c *client) PFMerge(ctx context.Context, dest string, keys ...string) StatusCmd {
ctx = c.handler.beforeWithKeys(ctx, CommandPFMerge, func() []string { return appendString(dest, keys...) })
r := c.adapter.PFMerge(ctx, dest, keys...)
c.handler.after(ctx, r.Err())
return r
}