-
Couldn't load subscription status.
- Fork 69
Shared pool among clients and fixed pool resources release #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fe698b7
15bd156
6715a7a
51643f4
c3a2be0
f96a40a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,33 @@ | ||
| package redisearch | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/gomodule/redigo/redis" | ||
| "math/rand" | ||
| "sync" | ||
| "time" | ||
| "github.com/gomodule/redigo/redis" | ||
| ) | ||
|
|
||
| type ConnPool interface { | ||
| Get() redis.Conn | ||
| Close() error | ||
| } | ||
|
|
||
| type SingleHostPool struct { | ||
| *redis.Pool | ||
| } | ||
|
|
||
| func NewSingleHostPool(host string) *SingleHostPool { | ||
| ret := redis.NewPool(func() (redis.Conn, error) { | ||
| // TODO: Add timeouts. and 2 separate pools for indexing and querying, with different timeouts | ||
| pool := &redis.Pool{Dial: func() (redis.Conn, error) { | ||
| return redis.Dial("tcp", host) | ||
| }, maxConns) | ||
| ret.TestOnBorrow = func(c redis.Conn, t time.Time) (err error) { | ||
| }, MaxIdle: maxConns} | ||
| pool.TestOnBorrow = func(c redis.Conn, t time.Time) (err error) { | ||
| if time.Since(t) > time.Second { | ||
| _, err = c.Do("PING") | ||
| } | ||
| return err | ||
| } | ||
| return &SingleHostPool{ret} | ||
| return &SingleHostPool{pool} | ||
| } | ||
|
|
||
| type MultiHostPool struct { | ||
|
|
@@ -65,3 +66,20 @@ func (p *MultiHostPool) Get() redis.Conn { | |
| return pool.Get() | ||
|
|
||
| } | ||
|
|
||
| func (p *MultiHostPool) Close() (err error) { | ||
| p.Lock() | ||
| defer p.Unlock() | ||
| for host, pool := range p.pools { | ||
| poolErr := pool.Close() | ||
| //preserve pool error if not nil but continue | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @itamarhaber what do you think about the following solution? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lovely 🔨 |
||
| if poolErr != nil { | ||
| if err == nil { | ||
| err = fmt.Errorf("Error closing pool for host %s. Got %v.", host, poolErr) | ||
| } else { | ||
| err = fmt.Errorf("%v Error closing pool for host %s. Got %v.", err, host, poolErr) | ||
| } | ||
| } | ||
| } | ||
| return | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.