skip to Main Content

I’m trying to use Go to connect to my RediSearch (Redis module) instance.

Combing through the documentation and Go code that generates the client, I don’t see how to pass authentication options to the Redigo client within… Is this an oversight on my part or are we just expected to use RediSearch without securing the database?

I’ve also tried the following when generating a RediSearch client. Each gives errors regarding the format of the URL:

redisearch.NewClient("[email protected]:6379", index)
redisearch.NewClient("redis://[email protected]:6379", index)

Within pool.go, in the NewSingleHostPool function that returns a client, it seems like it should pass DialOptions into the Dial Redigo function instead of nil, and have those options be passed into the RediSearch NewClient function…

2

Answers


  1. Call NewClientWithPool with a pool dial function of your choice.

    p := &redis.Pool{
        Dial: func() (*Conn, error) { 
           return redis.DialURL("redis://[email protected]:6379") 
        },
        MaxIdle: 3,                     // adjust to taste 
        IdleTimeout: 240 * time.Second, // adjust to taste
    
    }
    c := redissearch.NewClientFromPool(p, index)
    
    Login or Signup to reply.
  2. A nice way to do this is like so, with built-in constructs for password auth by redigo:

    func newPool(server string, password string) *redis.Pool {
        return &redis.Pool{
            MaxIdle:     3,
            IdleTimeout: 240 * time.Second,
            Dial: func() (redis.Conn, error) {
                return redis.Dial("tcp",
                    server,
                    redis.DialPassword(password))
            },
    
            TestOnBorrow: func(c redis.Conn, t time.Time) error {
                _, err := c.Do("PING")
                return err
            },
        }
    }
    

    Your server should look like this: redis-1344.333.us-east-1-mz.ec2.com:17885 and the password is plain text.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search