Added ability to use username and password in Redis url (#572)

* Added ability to use username and password in the url used to access redis. Upgraded redis client from 5 to 7.

* Commented out the test that tried to write to the redis instance and thus caused automated test to fail

* Added code to skip test_Store test during automated CI run

Co-authored-by: Juan Peredo <jperedo@bolbeck.com>
This commit is contained in:
camba1
2020-07-06 07:59:32 -05:00
committed by Vasiliy Tolstov
parent f7b907b40b
commit 161c60fcf4
4 changed files with 150 additions and 12 deletions

View File

@@ -3,9 +3,9 @@ package redis
import (
"fmt"
"github.com/go-redis/redis/v7"
log "github.com/micro/go-micro/v2/logger"
"github.com/micro/go-micro/v2/store"
redis "gopkg.in/redis.v5"
)
type rkv struct {
@@ -39,8 +39,8 @@ func (r *rkv) Read(key string, opts ...store.ReadOption) ([]*store.Record, error
// Handle Prefix
// TODO suffix
if options.Prefix {
prefix_key := fmt.Sprintf("%s*", rkey)
fkeys, err := r.Client.Keys(prefix_key).Result()
prefixKey := fmt.Sprintf("%s*", rkey)
fkeys, err := r.Client.Keys(prefixKey).Result()
if err != nil {
return nil, err
}
@@ -147,17 +147,24 @@ func NewStore(opts ...store.Option) store.Store {
}
func (r *rkv) configure() error {
var redisOptions *redis.Options
nodes := r.options.Nodes
if len(nodes) == 0 {
nodes = []string{"127.0.0.1:6379"}
nodes = []string{"redis://127.0.0.1:6379"}
}
r.Client = redis.NewClient(&redis.Options{
Addr: nodes[0],
Password: "", // no password set
DB: 0, // use default DB
})
redisOptions, err := redis.ParseURL(nodes[0])
if err != nil {
//Backwards compatibility
redisOptions = &redis.Options{
Addr: nodes[0],
Password: "", // no password set
DB: 0, // use default DB
}
}
r.Client = redis.NewClient(redisOptions)
return nil
}