Skip to content

Commit c0188dd

Browse files
committed
[fix] getRediSearchVersion is now only used for testing.
1 parent d334849 commit c0188dd

File tree

5 files changed

+43
-50
lines changed

5 files changed

+43
-50
lines changed

.circleci/config.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- run:
1818
name: Generate a root CA and a server certificate using redis helpers
1919
command: |
20-
git clone git://github.com/antirez/redis.git --branch 6.0.5
20+
git clone git://github.com/antirez/redis.git --branch 6.0.6
2121
cd redis
2222
./utils/gen-test-certs.sh
2323
cd ..
@@ -53,6 +53,8 @@ jobs:
5353
- checkout
5454
- run: make get
5555
- run: make checkfmt
56+
- run: make test
57+
- run: make godoc_examples
5658
- run: make coverage
5759
- run: bash <(curl -s https://codecov.io/bash) -t ${CODECOV_TOKEN}
5860

@@ -64,7 +66,6 @@ jobs:
6466
working_directory: /go/src/github.com/RediSearch/redisearch-go
6567
steps:
6668
- checkout
67-
- run: make get
6869
- run: make test
6970

7071
build-v16:
@@ -75,7 +76,6 @@ jobs:
7576
working_directory: /go/src/github.com/RediSearch/redisearch-go
7677
steps:
7778
- checkout
78-
- run: make get
7979
- run: make test
8080

8181
build-v14:
@@ -86,7 +86,6 @@ jobs:
8686
working_directory: /go/src/github.com/RediSearch/redisearch-go
8787
steps:
8888
- checkout
89-
- run: make get
9089
- run: make test
9190

9291
build_nightly: # test nightly with redisearch:edge
@@ -97,7 +96,6 @@ jobs:
9796
working_directory: /go/src/github.com/RediSearch/redisearch-go
9897
steps:
9998
- checkout
100-
- run: make get
10199
- run: make test
102100

103101
workflows:

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ examples: get
4444
fmt:
4545
$(GOFMT) ./...
4646

47+
godoc_examples: get fmt
48+
$(GOTEST) -race -covermode=atomic -v ./redisearch
49+
4750
test: get fmt
48-
$(GOTEST) -race -covermode=atomic ./...
51+
$(GOTEST) -race -covermode=atomic -run "Test" -v ./redisearch
4952

50-
coverage: get test
51-
$(GOTEST) -race -coverprofile=coverage.txt -covermode=atomic ./redisearch
53+
coverage: get
54+
$(GOTEST) -race -coverprofile=coverage.txt -covermode=atomic -v ./redisearch
5255

redisearch/client.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,6 @@ func NewClientFromPool(pool *redis.Pool, name string) *Client {
4646
return ret
4747
}
4848

49-
// GetRediSearchVersion returns RediSearch version by issuing "MODULE LIST" command
50-
// and iterating through the availabe modules up until "ft" is found as the name property
51-
func (c *Client) GetRediSearchVersion() (version int64, err error) {
52-
conn := c.pool.Get()
53-
defer conn.Close()
54-
var values []interface{}
55-
var moduleInfo []interface{}
56-
var moduleName string
57-
values, err = redis.Values(conn.Do("MODULE", "LIST"))
58-
if err != nil {
59-
return
60-
}
61-
for _, rawModule := range values {
62-
moduleInfo, err = redis.Values(rawModule, err)
63-
if err != nil {
64-
return
65-
}
66-
moduleName, err = redis.String(moduleInfo[1], err)
67-
if err != nil {
68-
return
69-
}
70-
if moduleName == "ft" {
71-
version, err = redis.Int64(moduleInfo[3], err)
72-
}
73-
}
74-
return
75-
}
76-
7749
// CreateIndex configures the index and creates it on redis
7850
func (i *Client) CreateIndex(schema *Schema) (err error) {
7951
return i.indexWithDefinition(i.name, schema, nil, err)

redisearch/client_test.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,34 @@ func teardown(c *Client) {
1919
flush(c)
2020
}
2121

22+
// getRediSearchVersion returns RediSearch version by issuing "MODULE LIST" command
23+
// and iterating through the availabe modules up until "ft" is found as the name property
24+
func (c *Client) getRediSearchVersion() (version int64, err error) {
25+
conn := c.pool.Get()
26+
defer conn.Close()
27+
var values []interface{}
28+
var moduleInfo []interface{}
29+
var moduleName string
30+
values, err = redis.Values(conn.Do("MODULE", "LIST"))
31+
if err != nil {
32+
return
33+
}
34+
for _, rawModule := range values {
35+
moduleInfo, err = redis.Values(rawModule, err)
36+
if err != nil {
37+
return
38+
}
39+
moduleName, err = redis.String(moduleInfo[1], err)
40+
if err != nil {
41+
return
42+
}
43+
if moduleName == "ft" {
44+
version, err = redis.Int64(moduleInfo[3], err)
45+
}
46+
}
47+
return
48+
}
49+
2250
func TestClient_Get(t *testing.T) {
2351

2452
c := createClient("test-get")
@@ -494,7 +522,7 @@ func TestClient_GetTagVals(t *testing.T) {
494522

495523
func TestClient_SynAdd(t *testing.T) {
496524
c := createClient("testsynadd")
497-
version, err := c.GetRediSearchVersion()
525+
version, err := c.getRediSearchVersion()
498526
assert.Nil(t, err)
499527
if version <= 10699 {
500528
sc := NewSchema(DefaultOptions).
@@ -516,7 +544,7 @@ func TestClient_SynAdd(t *testing.T) {
516544

517545
func TestClient_SynDump(t *testing.T) {
518546
c := createClient("testsyndump")
519-
version, err := c.GetRediSearchVersion()
547+
version, err := c.getRediSearchVersion()
520548
assert.Nil(t, err)
521549
sc := NewSchema(DefaultOptions).
522550
AddField(NewTextField("name")).
@@ -589,13 +617,13 @@ func TestClient_AddField(t *testing.T) {
589617

590618
func TestClient_GetRediSearchVersion(t *testing.T) {
591619
c := createClient("version-test")
592-
_, err := c.GetRediSearchVersion()
620+
_, err := c.getRediSearchVersion()
593621
assert.Nil(t, err)
594622
}
595623

596624
func TestClient_CreateIndexWithIndexDefinition(t *testing.T) {
597625
i := createClient("index-definition-test")
598-
version, err := i.GetRediSearchVersion()
626+
version, err := i.getRediSearchVersion()
599627
assert.Nil(t, err)
600628
if version >= 20000 {
601629

@@ -653,7 +681,7 @@ func TestClient_SynUpdate(t *testing.T) {
653681
sc := NewSchema(DefaultOptions).
654682
AddField(NewTextField("name")).
655683
AddField(NewTextField("addr"))
656-
version, err := c.GetRediSearchVersion()
684+
version, err := c.getRediSearchVersion()
657685
assert.Nil(t, err)
658686

659687
type args struct {

redisearch/example_client_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,13 @@ func ExampleClient_CreateIndexWithIndexDefinition() {
7575
}}
7676
c := redisearch.NewClientFromPool(pool, "products-from-hashes")
7777

78-
version, _ := c.GetRediSearchVersion()
79-
80-
// IndexDefinition is available for RediSearch 2.0+
81-
if version < 20000 {
82-
return
83-
}
84-
// Drop an existing index. If the index does not exist an error is returned
85-
c.Drop()
86-
8778
// Create a schema
8879
schema := redisearch.NewSchema(redisearch.DefaultOptions).
8980
AddField(redisearch.NewTextFieldOptions("name", redisearch.TextFieldOptions{Sortable: true})).
9081
AddField(redisearch.NewTextFieldOptions("description", redisearch.TextFieldOptions{Weight: 5.0, Sortable: true})).
9182
AddField(redisearch.NewNumericField("price"))
9283

84+
// IndexDefinition is available for RediSearch 2.0+
9385
// Create a index definition for automatic indexing on Hash updates.
9486
// In this example we will only index keys started by product:
9587
indexDefinition := redisearch.NewIndexDefinition().AddPrefix("product:")

0 commit comments

Comments
 (0)