Skip to content

Commit 22a2c3c

Browse files
committed
Added getting statistics of all connection pools
1 parent bfd7635 commit 22a2c3c

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v2.1.0 (2022-07-12)
2+
3+
- Added getting statistics of all connection pools
4+
15
## v2.0.1 (2022-06-16)
26

37
- Fixed error return value for MGetWithGD

ha_conn_factory.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ func NewHAConnFactory(cfg *HAConfig) (*HAConnFactory, error) {
8686
return factory, nil
8787
}
8888

89+
func (factory *HAConnFactory) stats() map[string]*redis.PoolStats {
90+
return map[string]*redis.PoolStats{
91+
factory.master.redisCli.Options().Addr: factory.master.redisCli.PoolStats(),
92+
}
93+
}
94+
8995
func (factory *HAConnFactory) close() {
9096
factory.master.redisCli.Close()
9197
factory.slaves.close()

pool.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var (
2525
type ConnFactory interface {
2626
getSlaveConn(key ...string) (*redis.Client, error)
2727
getMasterConn(key ...string) (*redis.Client, error)
28+
stats() map[string]*redis.PoolStats
2829
close()
2930
}
3031

@@ -160,12 +161,8 @@ func NewShard(cfg *ShardConfig) (*Pool, error) {
160161
}, nil
161162
}
162163

163-
func (p *Pool) Stats() (*redis.PoolStats, error) {
164-
conn, err := p.connFactory.getMasterConn()
165-
if err != nil {
166-
return nil, err
167-
}
168-
return conn.PoolStats(), nil
164+
func (p *Pool) Stats() map[string]*redis.PoolStats {
165+
return p.connFactory.stats()
169166
}
170167

171168
func (p *Pool) Close() {

shard_conn_factory.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ func NewShardConnFactory(cfg *ShardConfig) (*ShardConnFactory, error) {
6363
return factory, nil
6464
}
6565

66+
func (factory *ShardConnFactory) stats() map[string]*redis.PoolStats {
67+
results := make(map[string]*redis.PoolStats, len(factory.shards))
68+
69+
for _, shard := range factory.shards {
70+
result := shard.stats()
71+
for addr, stats := range result {
72+
results[addr] = stats
73+
}
74+
}
75+
76+
return results
77+
}
78+
6679
func (factory *ShardConnFactory) close() {
6780
for _, shard := range factory.shards {
6881
shard.close()

0 commit comments

Comments
 (0)