Skip to content

Commit 53bd68c

Browse files
committed
Add tests for unified config in Redis 8
1 parent 1139bc3 commit 53bd68c

File tree

5 files changed

+120
-19
lines changed

5 files changed

+120
-19
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ testdata/*
44
.DS_Store
55
*.tar.gz
66
*.dic
7+
redis8tests.sh

commands_test.go

+75
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,23 @@ var _ = Describe("Commands", func() {
344344
Expect(val).NotTo(BeEmpty())
345345
})
346346

347+
It("should ConfigGet Modules", func() {
348+
SkipBeforeRedisMajor(8, "Config doesn't include modules before Redis 8")
349+
expected := map[string]string{
350+
"search-*": "search-min-prefix",
351+
"ts-*": "ts-retention-policy",
352+
"bf-*": "bf-error-rate",
353+
"cf-*": "cf-initial-size",
354+
}
355+
356+
for prefix, lookup := range expected {
357+
val, err := client.ConfigGet(ctx, prefix).Result()
358+
Expect(err).NotTo(HaveOccurred())
359+
Expect(val).NotTo(BeEmpty())
360+
Expect(val[lookup]).NotTo(BeEmpty())
361+
}
362+
})
363+
347364
It("should ConfigResetStat", Label("NonRedisEnterprise"), func() {
348365
r := client.ConfigResetStat(ctx)
349366
Expect(r.Err()).NotTo(HaveOccurred())
@@ -362,6 +379,64 @@ var _ = Describe("Commands", func() {
362379
Expect(configSet.Val()).To(Equal("OK"))
363380
})
364381

382+
It("should ConfigSet Modules", func() {
383+
SkipBeforeRedisMajor(8, "Config doesn't include modules before Redis 8")
384+
defaults := map[string]string{}
385+
expected := map[string]string{
386+
"search-min-prefix": "32",
387+
"ts-retention-policy": "2",
388+
"bf-error-rate": "0.13",
389+
"cf-initial-size": "64",
390+
}
391+
392+
// read the defaults to set them back later
393+
for setting, _ := range expected {
394+
val, err := client.ConfigGet(ctx, setting).Result()
395+
Expect(err).NotTo(HaveOccurred())
396+
defaults[setting] = val[setting]
397+
}
398+
399+
// check if new values can be set
400+
for setting, value := range expected {
401+
val, err := client.ConfigSet(ctx, setting, value).Result()
402+
Expect(err).NotTo(HaveOccurred())
403+
Expect(val).NotTo(BeEmpty())
404+
Expect(val).To(Equal("OK"))
405+
}
406+
407+
for setting, value := range expected {
408+
val, err := client.ConfigGet(ctx, setting).Result()
409+
Expect(err).NotTo(HaveOccurred())
410+
Expect(val).NotTo(BeEmpty())
411+
Expect(val[setting]).To(Equal(value))
412+
}
413+
414+
// set back to the defaults
415+
for setting, value := range defaults {
416+
val, err := client.ConfigSet(ctx, setting, value).Result()
417+
Expect(err).NotTo(HaveOccurred())
418+
Expect(val).NotTo(BeEmpty())
419+
Expect(val).To(Equal("OK"))
420+
}
421+
})
422+
423+
It("should Fail ConfigSet Modules", func() {
424+
SkipBeforeRedisMajor(8, "Config doesn't include modules before Redis 8")
425+
expected := map[string]string{
426+
"search-min-prefix": "-32",
427+
"ts-retention-policy": "-10",
428+
"bf-error-rate": "1.5",
429+
"cf-initial-size": "-10",
430+
}
431+
432+
for setting, value := range expected {
433+
val, err := client.ConfigSet(ctx, setting, value).Result()
434+
Expect(err).To(HaveOccurred())
435+
Expect(err).To(MatchError(ContainSubstring(setting)))
436+
Expect(val).To(BeEmpty())
437+
}
438+
})
439+
365440
It("should ConfigRewrite", Label("NonRedisEnterprise"), func() {
366441
configRewrite := client.ConfigRewrite(ctx)
367442
Expect(configRewrite.Err()).NotTo(HaveOccurred())

main_test.go

+23-7
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,19 @@ var RCEDocker = false
7373
// Notes the major version of redis we are executing tests.
7474
// This can be used before we change the bsm fork of ginkgo for one,
7575
// which have support for label sets, so we can filter tests per redis major version.
76-
var REDIS_MAJOR_VERSION = 7
76+
var RedisMajorVersion = 7
77+
78+
func SkipBeforeRedisMajor(version int, msg string) {
79+
if RedisMajorVersion < version {
80+
Skip(fmt.Sprintf("(redis major version < %d) %s", version, msg))
81+
}
82+
}
83+
84+
func SkipAfterRedisMajor(version int, msg string) {
85+
if RedisMajorVersion > version {
86+
Skip(fmt.Sprintf("(redis major version > %d) %s", version, msg))
87+
}
88+
}
7789

7890
func registerProcess(port string, p *redisProcess) {
7991
if processes == nil {
@@ -92,16 +104,20 @@ var _ = BeforeSuite(func() {
92104
RECluster, _ = strconv.ParseBool(os.Getenv("RE_CLUSTER"))
93105
RCEDocker, _ = strconv.ParseBool(os.Getenv("RCE_DOCKER"))
94106

95-
REDIS_MAJOR_VERSION, _ = strconv.Atoi(os.Getenv("REDIS_MAJOR_VERSION"))
96-
if REDIS_MAJOR_VERSION == 0 {
97-
REDIS_MAJOR_VERSION = 7
107+
RedisMajorVersion, _ = strconv.Atoi(os.Getenv("REDIS_MAJOR_VERSION"))
108+
109+
if RedisMajorVersion == 0 {
110+
RedisMajorVersion = 7
98111
}
99-
Expect(REDIS_MAJOR_VERSION).To(BeNumerically(">=", 6))
100-
Expect(REDIS_MAJOR_VERSION).To(BeNumerically("<=", 8))
101112

102113
fmt.Printf("RECluster: %v\n", RECluster)
103114
fmt.Printf("RCEDocker: %v\n", RCEDocker)
104-
fmt.Printf("REDIS_MAJOR_VERSION: %v\n", REDIS_MAJOR_VERSION)
115+
fmt.Printf("REDIS_MAJOR_VERSION: %v\n", RedisMajorVersion)
116+
117+
if RedisMajorVersion < 6 || RedisMajorVersion > 8 {
118+
panic("incorrect or not supported redis major version")
119+
}
120+
105121
if !RECluster && !RCEDocker {
106122

107123
redisMain, err = startRedis(redisPort)

search_commands.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -831,20 +831,32 @@ func (c cmdable) FTAlter(ctx context.Context, index string, skipInitialScan bool
831831
return cmd
832832
}
833833

834-
// FTConfigGet - Retrieves the value of a RediSearch configuration parameter.
834+
// Deprecated: FTConfigGet is deprecated in Redis 8.
835+
// All configuration will be done with the CONFIG GET command.
836+
// For more information check [Client.ConfigGet] and [CONFIG GET Documentation]
837+
//
838+
// Retrieves the value of a RediSearch configuration parameter.
835839
// The 'option' parameter specifies the configuration parameter to retrieve.
836-
// For more information, please refer to the Redis documentation:
837-
// [FT.CONFIG GET]: (https://redis.io/commands/ft.config-get/)
840+
// For more information, please refer to the Redis [FT.CONFIG GET] documentation.
841+
//
842+
// [CONFIG GET Documentation]: https://redis.io/commands/config-get/
843+
// [FT.CONFIG GET]: https://redis.io/commands/ft.config-get/
838844
func (c cmdable) FTConfigGet(ctx context.Context, option string) *MapMapStringInterfaceCmd {
839845
cmd := NewMapMapStringInterfaceCmd(ctx, "FT.CONFIG", "GET", option)
840846
_ = c(ctx, cmd)
841847
return cmd
842848
}
843849

844-
// FTConfigSet - Sets the value of a RediSearch configuration parameter.
850+
// Deprecated: FTConfigSet is deprecated in Redis 8.
851+
// All configuration will be done with the CONFIG SET command.
852+
// For more information check [Client.ConfigSet] and [CONFIG SET Documentation]
853+
//
854+
// Sets the value of a RediSearch configuration parameter.
845855
// The 'option' parameter specifies the configuration parameter to set, and the 'value' parameter specifies the new value.
846-
// For more information, please refer to the Redis documentation:
847-
// [FT.CONFIG SET]: (https://redis.io/commands/ft.config-set/)
856+
// For more information, please refer to the Redis [FT.CONFIG SET] documentation.
857+
//
858+
// [CONFIG SET Documentation]: https://redis.io/commands/config-set/
859+
// [FT.CONFIG SET]: https://redis.io/commands/ft.config-set/
848860
func (c cmdable) FTConfigSet(ctx context.Context, option string, value interface{}) *StatusCmd {
849861
cmd := NewStatusCmd(ctx, "FT.CONFIG", "SET", option, value)
850862
_ = c(ctx, cmd)

search_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,8 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
374374
// up until redis 8 the default scorer was TFIDF, in redis 8 it is BM25
375375
// this test expect redis major version >= 8
376376
It("should FTSearch WithScores", Label("search", "ftsearch"), func() {
377-
if REDIS_MAJOR_VERSION < 8 {
378-
Skip("(redis major version < 8) default scorer is not BM25")
379-
}
377+
SkipBeforeRedisMajor(8, "default scorer is not BM25")
378+
380379
text1 := &redis.FieldSchema{FieldName: "description", FieldType: redis.SearchFieldTypeText}
381380
val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, text1).Result()
382381
Expect(err).NotTo(HaveOccurred())
@@ -418,9 +417,7 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
418417
// up until redis 8 the default scorer was TFIDF, in redis 8 it is BM25
419418
// this test expect redis major version <=7
420419
It("should FTSearch WithScores", Label("search", "ftsearch"), func() {
421-
if REDIS_MAJOR_VERSION > 7 {
422-
Skip("(redis major version > 7) default scorer is not TFIDF")
423-
}
420+
SkipAfterRedisMajor(7, "default scorer is not TFIDF")
424421
text1 := &redis.FieldSchema{FieldName: "description", FieldType: redis.SearchFieldTypeText}
425422
val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, text1).Result()
426423
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)