Skip to content

Commit

Permalink
update gcache pool
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjunshi committed May 21, 2021
1 parent d117f6d commit 7896baa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lib/base/base_hmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func NewHmap() *Hmap {
}
}

// Data :
func (h *Hmap) Data() map[string]interface{} {
return h.data
}

// Len :
func (h *Hmap) Len() int {
return h.size
Expand Down
13 changes: 7 additions & 6 deletions lib/example/gcacheclient/example_gcacheclient.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package examplegcacheclient

import (
"strconv"
"time"

"github.com/jameschz/go-base/lib/gcache"
Expand Down Expand Up @@ -55,12 +56,12 @@ func TestDriver() {
cache.Close()

// test connection timeout
// for i := 0; i < 5; i++ {
// time.Sleep(10 * time.Second)
// cache = gcache.D("default")
// cache.Set("test11", "test1")
// cache.Close()
// }
for i := 0; i < 5; i++ {
time.Sleep(10 * time.Second)
cache = gcache.D("default")
cache.Set("test.timeout."+strconv.Itoa(i), "test1")
cache.Close()
}

}

Expand Down
9 changes: 8 additions & 1 deletion lib/gcache/pool/gcache_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func createDataSource(driver *gcachedriver.Driver, node string) *gcachebase.Data
Addr: addr,
DB: db,
// Pool Settings
PoolSize: driver.PoolIdleMinSize,
PoolSize: driver.PoolInitSize,
MinIdleConns: driver.PoolIdleMinSize,
IdleTimeout: time.Duration(driver.PoolIdleTimeoutMin * int(time.Minute)),
})
Expand Down Expand Up @@ -105,6 +105,13 @@ func Init() (err error) {
_cPool.Set(cKey, createDataSource(cDriver, cNode))
}
}
// heart beat
go func() {
time.Sleep(1 * time.Minute)
for _, ds := range _cPool.Data() {
ds.(*gcachebase.DataSource).RedisConn.Ping()
}
}()
// for debug
debugPrint("gcachepool.Init", _cPool)
// init ok status
Expand Down

0 comments on commit 7896baa

Please sign in to comment.