library-go/store/valkey/client_manager.go

51 lines
941 B
Go

package valkey
import (
"crypto/tls"
"github.com/valkey-io/valkey-go"
"github.com/valkey-io/valkey-go/valkeyhook"
)
const (
defaultDatabase = 0
)
func getClient(r *VK) (valkey.Client, error) {
var tlsConfig *tls.Config
if r.tls {
tlsConfig = &tls.Config{
InsecureSkipVerify: true,
}
}
store, err := valkey.NewClient(valkey.ClientOption{
InitAddress: []string{r.Addr},
Password: r.Pass,
SelectDB: defaultDatabase,
TLSConfig: tlsConfig,
})
if err != nil {
return nil, err
}
hooks := append([]valkeyhook.Hook{}, r.hooks...)
for _, hook := range hooks {
valkeyhook.WithHook(store, hook)
}
return store, nil
// defaultDurationHook, breakerHook{
// brk: r.brk
//
// 監控的
// connCollector.registerClient(&statGetter{
// clientType: NodeType,
// key: r.Addr,
// poolSize: nodePoolSize,
// poolStats: func() *red.PoolStats {
// return store.PoolStats()
// },
// })
}