Quantcast
Channel: redigo different pool connect to single server - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Cerise Limón for redigo different pool connect to single server

$
0
0

The dial functions use the single variable v. The functions use the last value assigned to v when called.

To fix the problem, declare a variable inside the scope of the for loop and use that variable in the dial function:

for k, v := range connections {
    v := v // Declare variable scoped inside for loop 
    redisPool := &redis.Pool{
        Dial: func() (redis.Conn, error) {
            return redis.Dial("tcp", v)  // uses variable scoped inside for loop
        },
    ...

Separate from this issue, the pool settings don't make sense. Because the pool is configured to discard connections that have been idle for 10 seconds, the test on borrow function never pings the server.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>