Skip to content

Commit 0f05272

Browse files
authored
Merge branch 'master' into patch-1
2 parents 7ab8412 + b26758a commit 0f05272

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

doctests/home_json_example_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,32 @@ func ExampleClient_search_json() {
152152
// >>> Tel Aviv
153153
// STEP_END
154154

155+
// STEP_START query2count_only
156+
citiesResult2, err := rdb.FTSearchWithArgs(
157+
ctx,
158+
"idx:users",
159+
"Paul",
160+
&redis.FTSearchOptions{
161+
Return: []redis.FTSearchReturn{
162+
{
163+
FieldName: "$.city",
164+
As: "city",
165+
},
166+
},
167+
CountOnly: true,
168+
},
169+
).Result()
170+
171+
if err != nil {
172+
panic(err)
173+
}
174+
175+
// The `Total` field has the correct number of docs found
176+
// by the query but the `Docs` slice is empty.
177+
fmt.Println(len(citiesResult2.Docs)) // >>> 0
178+
fmt.Println(citiesResult2.Total) // >>> 2
179+
// STEP_END
180+
155181
// STEP_START query3
156182
aggOptions := redis.FTAggregateOptions{
157183
GroupBy: []redis.FTAggregateGroupBy{
@@ -196,6 +222,8 @@ func ExampleClient_search_json() {
196222
// {1 [{user:3 <nil> <nil> <nil> map[$:{"age":35,"city":"Tel Aviv","email":"paul.zamir@example.com","name":"Paul Zamir"}]}]}
197223
// London
198224
// Tel Aviv
225+
// 0
226+
// 2
199227
// London - 1
200228
// Tel Aviv - 2
201229
}

hash_commands.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type HashCmdable interface {
1313
HGetDel(ctx context.Context, key string, fields ...string) *StringSliceCmd
1414
HGetEX(ctx context.Context, key string, fields ...string) *StringSliceCmd
1515
HGetEXWithArgs(ctx context.Context, key string, options *HGetEXOptions, fields ...string) *StringSliceCmd
16+
HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd
1617
HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd
1718
HKeys(ctx context.Context, key string) *StringSliceCmd
1819
HLen(ctx context.Context, key string) *IntCmd

sentinel.go

+16
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,22 @@ func NewFailoverClusterClient(failoverOpt *FailoverOptions) *ClusterClient {
846846
}
847847

848848
opt := failoverOpt.clusterOptions()
849+
if failoverOpt.DB != 0 {
850+
onConnect := opt.OnConnect
851+
852+
opt.OnConnect = func(ctx context.Context, cn *Conn) error {
853+
if err := cn.Select(ctx, failoverOpt.DB).Err(); err != nil {
854+
return err
855+
}
856+
857+
if onConnect != nil {
858+
return onConnect(ctx, cn)
859+
}
860+
861+
return nil
862+
}
863+
}
864+
849865
opt.ClusterSlots = func(ctx context.Context) ([]ClusterSlot, error) {
850866
masterAddr, err := failover.MasterAddr(ctx)
851867
if err != nil {

sentinel_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ var _ = Describe("NewFailoverClusterClient", func() {
219219
SentinelAddrs: sentinelAddrs,
220220

221221
RouteRandomly: true,
222+
DB: 1,
222223
})
223224
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
224225

@@ -308,6 +309,20 @@ var _ = Describe("NewFailoverClusterClient", func() {
308309
})
309310
})
310311

312+
It("should sentinel cluster client db", func() {
313+
err := client.ForEachShard(ctx, func(ctx context.Context, c *redis.Client) error {
314+
return c.Ping(ctx).Err()
315+
})
316+
Expect(err).NotTo(HaveOccurred())
317+
318+
_ = client.ForEachShard(ctx, func(ctx context.Context, c *redis.Client) error {
319+
clientInfo, err := c.ClientInfo(ctx).Result()
320+
Expect(err).NotTo(HaveOccurred())
321+
Expect(clientInfo.DB).To(Equal(1))
322+
return nil
323+
})
324+
})
325+
311326
It("should sentinel cluster PROTO 3", func() {
312327
_ = client.ForEachShard(ctx, func(ctx context.Context, c *redis.Client) error {
313328
val, err := client.Do(ctx, "HELLO").Result()

0 commit comments

Comments
 (0)