警告
本文最后更新于 2022-01-11,文中内容可能已过时。
1
2
3
4
5
6
7
8
9
10
11
|
func main() {
rdb := redis.NewClient(&redis.Options{
Network: "",
Addr: "192.168.0.100:6379",
DB: 8,
Password: "b62uHm3eFEUZkF4z",
})
defer rdb.Close()
rdb.Ping(ctx)
}
|
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
|
func main() {
rdb := redis.NewClient(&redis.Options{
Network: "",
Addr: "192.168.0.100:6379",
DB: 8,
Password: "b62uHm3eFEUZkF4z",
})
defer rdb.Close()
rdb.HSet(ctx, "hash:kira", "a", 1)
rdb.HSet(ctx, "hash:kira", "b", 1)
rdb.HSet(ctx, "hash:kira", "c", 1)
pipeline := rdb.Pipeline()
defer pipeline.Close()
pipeline.HIncrBy(ctx, "hash:kira", "a", 1)
pipeline.HIncrBy(ctx, "hash:kira", "b", 1)
pipeline.HIncrBy(ctx, "hash:kira", "c", 1)
cmd, err := pipeline.Exec(ctx)
if err != nil {
log.Fatalln(err)
}
for _, v := range cmd {
log.Println(v.String())
}
}
|
TCP Stream
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
63
64
65
66
67
68
69
70
71
72
|
*2
$4
auth
$16
b62uHm3eFEUZkF4z
*2
$6
select
$1
8
+OK
+OK
*4
$4
hset
$9
hash:kira
$1
a
$1
1
:0
*4
$4
hset
$9
hash:kira
$1
b
$1
1
:0
*4
$4
hset
$9
hash:kira
$1
c
$1
1
:0
*4
$7
hincrby
$9
hash:kira
$1
a
$1
1
*4
$7
hincrby
$9
hash:kira
$1
b
$1
1
*4
$7
hincrby
$9
hash:kira
$1
c
$1
1
:2
:2
:2
|
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
|
func main() {
rdb := redis.NewClient(&redis.Options{
Network: "",
Addr: "192.168.0.100:6379",
DB: 8,
Password: "b62uHm3eFEUZkF4z",
})
defer rdb.Close()
rdb.HSet(ctx, "hash:kira", "a", 1)
rdb.HSet(ctx, "hash:kira", "b", 1)
rdb.HSet(ctx, "hash:kira", "c", 1)
pipeline := rdb.TxPipeline()
defer pipeline.Close()
pipeline.HIncrBy(ctx, "hash:kira", "a", 1)
pipeline.HIncrBy(ctx, "hash:kira", "b", 1)
pipeline.HIncrBy(ctx, "hash:kira", "c", 1)
cmd, err := pipeline.Exec(ctx)
if err != nil {
log.Fatalln(err)
}
for _, v := range cmd {
log.Println(v.String())
}
}
|
与pipeline的tcpstream对比,多了以上内容。pipelne在客户端缓存多个命令,再通过multi发送到服务端。
Redis使用手册