Skip to content

Commit 02c3494

Browse files
committed
resolve conflicts
2 parents 59e017e + eedb171 commit 02c3494

File tree

5 files changed

+82
-4
lines changed

5 files changed

+82
-4
lines changed

hash_commands.go

Lines changed: 1 addition & 0 deletions
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

search_commands.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,11 @@ type FTSearchOptions struct {
320320
SortByWithCount bool
321321
LimitOffset int
322322
Limit int
323-
Params map[string]interface{}
324-
DialectVersion int
323+
// CountOnly sets LIMIT 0 0 to get the count - number of documents in the result set without actually returning the result set.
324+
// When using this option, the Limit and LimitOffset options are ignored.
325+
CountOnly bool
326+
Params map[string]interface{}
327+
DialectVersion int
325328
}
326329

327330
type FTSynDumpResult struct {
@@ -1954,8 +1957,12 @@ func (c cmdable) FTSearchWithArgs(ctx context.Context, index string, query strin
19541957
args = append(args, "WITHCOUNT")
19551958
}
19561959
}
1957-
if options.LimitOffset >= 0 && options.Limit > 0 {
1958-
args = append(args, "LIMIT", options.LimitOffset, options.Limit)
1960+
if options.CountOnly {
1961+
args = append(args, "LIMIT", 0, 0)
1962+
} else {
1963+
if options.LimitOffset >= 0 && options.Limit > 0 || options.LimitOffset > 0 && options.Limit == 0 {
1964+
args = append(args, "LIMIT", options.LimitOffset, options.Limit)
1965+
}
19591966
}
19601967
if options.Params != nil {
19611968
args = append(args, "PARAMS", len(options.Params)*2)

search_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,7 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
16841684
Expect(resUint8.Docs[0].ID).To(BeEquivalentTo("doc1"))
16851685
})
16861686

1687+
<<<<<<< HEAD
16871688
It("should fail when using a non-zero offset with a zero limit", Label("search", "ftsearch"), func() {
16881689
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
16891690
val, err := client.FTCreate(ctx, "testIdx", &redis.FTCreateOptions{}, &redis.FieldSchema{
@@ -2067,6 +2068,44 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
20672068
Expect(strings.ToLower(err.Error())).To(ContainSubstring("alias"))
20682069
})
20692070

2071+
It("should test ft.search with CountOnly param", Label("search", "ftsearch"), func() {
2072+
val, err := client.FTCreate(ctx, "txtIndex", &redis.FTCreateOptions{},
2073+
&redis.FieldSchema{FieldName: "txt", FieldType: redis.SearchFieldTypeText},
2074+
).Result()
2075+
Expect(err).NotTo(HaveOccurred())
2076+
Expect(val).To(BeEquivalentTo("OK"))
2077+
WaitForIndexing(client, "txtIndex")
2078+
2079+
_, err = client.HSet(ctx, "doc1", "txt", "hello world").Result()
2080+
Expect(err).NotTo(HaveOccurred())
2081+
_, err = client.HSet(ctx, "doc2", "txt", "hello go").Result()
2082+
Expect(err).NotTo(HaveOccurred())
2083+
_, err = client.HSet(ctx, "doc3", "txt", "hello redis").Result()
2084+
Expect(err).NotTo(HaveOccurred())
2085+
2086+
optsCountOnly := &redis.FTSearchOptions{
2087+
CountOnly: true,
2088+
LimitOffset: 0,
2089+
Limit: 2, // even though we limit to 2, with count-only no docs are returned
2090+
DialectVersion: 2,
2091+
}
2092+
resCountOnly, err := client.FTSearchWithArgs(ctx, "txtIndex", "hello", optsCountOnly).Result()
2093+
Expect(err).NotTo(HaveOccurred())
2094+
Expect(resCountOnly.Total).To(BeEquivalentTo(3))
2095+
Expect(len(resCountOnly.Docs)).To(BeEquivalentTo(0))
2096+
2097+
optsLimit := &redis.FTSearchOptions{
2098+
CountOnly: false,
2099+
LimitOffset: 0,
2100+
Limit: 2, // we expect to get 2 documents even though total count is 3
2101+
DialectVersion: 2,
2102+
}
2103+
resLimit, err := client.FTSearchWithArgs(ctx, "txtIndex", "hello", optsLimit).Result()
2104+
Expect(err).NotTo(HaveOccurred())
2105+
Expect(resLimit.Total).To(BeEquivalentTo(3))
2106+
Expect(len(resLimit.Docs)).To(BeEquivalentTo(2))
2107+
})
2108+
20702109
})
20712110

20722111
func _assert_geosearch_result(result *redis.FTSearchResult, expectedDocIDs []string) {

sentinel.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,22 @@ func NewFailoverClusterClient(failoverOpt *FailoverOptions) *ClusterClient {
815815
}
816816

817817
opt := failoverOpt.clusterOptions()
818+
if failoverOpt.DB != 0 {
819+
onConnect := opt.OnConnect
820+
821+
opt.OnConnect = func(ctx context.Context, cn *Conn) error {
822+
if err := cn.Select(ctx, failoverOpt.DB).Err(); err != nil {
823+
return err
824+
}
825+
826+
if onConnect != nil {
827+
return onConnect(ctx, cn)
828+
}
829+
830+
return nil
831+
}
832+
}
833+
818834
opt.ClusterSlots = func(ctx context.Context) ([]ClusterSlot, error) {
819835
masterAddr, err := failover.MasterAddr(ctx)
820836
if err != nil {

sentinel_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ var _ = Describe("NewFailoverClusterClient", func() {
200200
SentinelAddrs: sentinelAddrs,
201201

202202
RouteRandomly: true,
203+
DB: 1,
203204
})
204205
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
205206

@@ -289,6 +290,20 @@ var _ = Describe("NewFailoverClusterClient", func() {
289290
})
290291
})
291292

293+
It("should sentinel cluster client db", func() {
294+
err := client.ForEachShard(ctx, func(ctx context.Context, c *redis.Client) error {
295+
return c.Ping(ctx).Err()
296+
})
297+
Expect(err).NotTo(HaveOccurred())
298+
299+
_ = client.ForEachShard(ctx, func(ctx context.Context, c *redis.Client) error {
300+
clientInfo, err := c.ClientInfo(ctx).Result()
301+
Expect(err).NotTo(HaveOccurred())
302+
Expect(clientInfo.DB).To(Equal(1))
303+
return nil
304+
})
305+
})
306+
292307
It("should sentinel cluster PROTO 3", func() {
293308
_ = client.ForEachShard(ctx, func(ctx context.Context, c *redis.Client) error {
294309
val, err := client.Do(ctx, "HELLO").Result()

0 commit comments

Comments
 (0)