1

I'm developing a golang web project with Redigo to connect to a redis docker container.

While the golang web application is in running state, I've changed the value of a redis key using SET MyFlag true in redis-cli. But this is not reflecting in my webapp. When MyFlag is fetched using flag, err := redis.Bool(conn.Do("GET", "MyFlag")), it gives the old value.

But, after the webapp is restarted, the same command fetches the new value.

conn is retrieved from a redis connection pool. This is the configuration for redis pool

redisPool = &redis.Pool{
        MaxIdle:     5,
        IdleTimeout: 240 * time.Second,
        MaxActive:   10,
        Wait:        true,
        Dial: func() (redis.Conn, error) {
            c, err := redis.Dial("tcp", db.GetUrl())
            if err != nil {
                return nil, err
            }
            password := db.GetPassword()
            if password != "" {
                if _, err := c.Do("AUTH", password); err != nil {
                    _ = c.Close()
                    return nil, err
                }
            }
            return c, nil
        },
    }

Is this the issue of caching in Redis/Redigo/Docker ?

Ramanujan R
  • 1,601
  • 2
  • 23
  • 43
  • Redigo does not do any caching. – Charlie Tumahai Sep 29 '19 at 13:37
  • 2
    Furthermore, the config of the pool is rather uninteresting. What would be more interesting is the actual code using it. – Markus W Mahlberg Sep 29 '19 at 21:38
  • 1
    Use [redis.DialPassword](https://godoc.org/github.com/gomodule/redigo/redis#DialPassword) to simplify the pool dial function. That said, this has nothing to do with the issue. – Charlie Tumahai Sep 30 '19 at 01:00
  • Thanks @CeriseLimón for your valuable input – Ramanujan R Sep 30 '19 at 09:24
  • @MarkusWMahlberg We tried it again after changing `MaxIdle: 10`. **It worked!** But I can't see any reason for that. Someone please shed some light on this behavior. – Ramanujan R Sep 30 '19 at 09:31
  • The pool configuration is not the problem. Something else changed when max idle was changed from 5 to 10 or the change covered up some other bug. Is it possible that the application and redis-cli connected to different servers? Does the application handle the error returned from `redis.Bool(conn.Do("GET", "MyFlag"))` ? Perhaps `flag` is false because the command failed or the returned value is not in a format expected by `redis.Bool`. – Charlie Tumahai Sep 30 '19 at 13:27

0 Answers0