pkg/storage/redis: add authentication support (#1159)

Fixes #1157
This commit is contained in:
Cuong Manh Le 2020-07-29 23:08:38 +07:00 committed by GitHub
parent 05545b3e1d
commit 3039407597
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 9 deletions

View file

@ -148,4 +148,4 @@ jobs:
uses: actions/checkout@v2
- name: test
run: go test -v -tags redis ./pkg/storage/redis/...
run: go test -v -tags redis ./pkg/storage/redis/... ./internal/databroker/...

View file

@ -831,7 +831,7 @@ The backend storage that databroker server will use, available types: `memory`,
- Config File Key: `databroker_storage_connection_string`
- Type: `string`
- **Required** when storage type is `redis`
- Example: `":6379"`
- Example: `"redis://localhost:6379/0"`
The connection string that server will use to connect to storage backend.

View file

@ -9,7 +9,7 @@ import (
)
func newTestServer() *Server {
address := ":6379"
address := "redis://localhost:6379/0"
if redisURL := os.Getenv("REDIS_URL"); redisURL != "" {
address = redisURL
}

View file

@ -35,14 +35,12 @@ type DB struct {
}
// New returns new DB instance.
func New(address, recordType string, deletePermanentAfter int64) (*DB, error) {
func New(rawURL, recordType string, deletePermanentAfter int64) (*DB, error) {
db := &DB{
pool: &redis.Pool{
Wait: true,
DialContext: func(ctx context.Context) (redis.Conn, error) {
ctx, cancelFn := context.WithTimeout(ctx, 5*time.Second)
defer cancelFn()
c, err := redis.DialContext(ctx, "tcp", address)
Dial: func() (redis.Conn, error) {
c, err := redis.DialURL(rawURL)
if err != nil {
return nil, fmt.Errorf(`redis.DialURL(): %w`, err)
}

View file

@ -27,7 +27,7 @@ func cleanup(c redis.Conn, db *DB, t *testing.T) {
func TestDB(t *testing.T) {
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
address := ":6379"
address := "redis://localhost:6379/0"
if redisURL := os.Getenv("REDIS_URL"); redisURL != "" {
address = redisURL
}