GetRedisClient returns the RedisClient of specified address & maxIdle & maxActive
(address string, maxIdle, maxActive int)
| 75 | |
| 76 | // GetRedisClient returns the RedisClient of specified address & maxIdle & maxActive |
| 77 | func GetRedisClient(address string, maxIdle, maxActive int) *RedisClient { |
| 78 | if maxIdle <= 0 { |
| 79 | maxIdle = defaultMaxIdle |
| 80 | } |
| 81 | if maxActive <= 0 { |
| 82 | maxActive = defaultMaxActive |
| 83 | } |
| 84 | |
| 85 | var rc *RedisClient |
| 86 | var mok bool |
| 87 | |
| 88 | mapMutex.RLock() |
| 89 | rc, mok = redisMap[address] |
| 90 | mapMutex.RUnlock() |
| 91 | |
| 92 | if !mok { |
| 93 | rc = &RedisClient{ |
| 94 | Address: address, |
| 95 | client: newClient(address, maxIdle, maxActive), |
| 96 | maxIdle: maxIdle, |
| 97 | maxActive: maxActive, |
| 98 | } |
| 99 | mapMutex.Lock() |
| 100 | redisMap[address] = rc |
| 101 | mapMutex.Unlock() |
| 102 | } |
| 103 | return rc |
| 104 | } |
| 105 | |
| 106 | // GetObj returns the content specified by key |
| 107 | func (rc *RedisClient) GetObj(key string) (interface{}, error) { |