forked from shadowspore/t38c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjset_query_builder.go
57 lines (48 loc) · 1.12 KB
/
jset_query_builder.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 t38c
import "context"
// JSetQueryBuilder struct
type JSetQueryBuilder struct {
client tile38Client
key string
objectID string
path string
value string
str bool
raw bool
}
func newJSetQueryBuilder(client tile38Client, key, objectID, path, value string) JSetQueryBuilder {
return JSetQueryBuilder{
client: client,
key: key,
objectID: objectID,
path: path,
value: value,
}
}
func (query JSetQueryBuilder) toCmd() cmd {
args := []string{
query.key, query.objectID, query.path, query.value,
}
if query.str {
args = append(args, "STR")
}
if query.raw {
args = append(args, "RAW")
}
return newCmd("JSET", args...)
}
// Do cmd
func (query JSetQueryBuilder) Do(ctx context.Context) error {
cmd := query.toCmd()
return query.client.jExecute(ctx, nil, cmd.Name, cmd.Args...)
}
// Str allows value to be interpreted as a string
func (query JSetQueryBuilder) Str() JSetQueryBuilder {
query.str = true
return query
}
// Raw allows value to be interpreted as a serialized JSON object
func (query JSetQueryBuilder) Raw() JSetQueryBuilder {
query.raw = true
return query
}