Documentation ¶
Overview ¶
Package bluto is a Redis connection pool which can lend Redis connections. The connection and the pool wrap and enhance their Redigo counterparts. bluto manages and reuse existing connections and provides advanced config options e.g. for handling timeouts. It also Support more advanced feature like TestOnBorrow which is health-check for connections.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bluto ¶
type Bluto struct {
// contains filtered or unexported fields
}
Bluto is a wrapper over redis pool
func New ¶
New creates new Bluto instance
Example ¶
package main import ( "github.com/alibaba-go/bluto/bluto" ) func main() { bluto, _ := bluto.New(bluto.Config{ Address: "localhost:6379", ConnectTimeoutSeconds: 10, ReadTimeoutSeconds: 10, }) defer bluto.ClosePool() }
Output:
Example (AdvancedConfig) ¶
package main import ( "log" "github.com/alibaba-go/bluto/bluto" ) func main() { bluto, err := bluto.New(bluto.Config{ // ---------------------------------------- dial options Network: "tcp", Address: "localhost:6379", ConnectTimeoutSeconds: 5, ReadTimeoutSeconds: 5, WriteTimeoutSeconds: 5, KeepAliveSeconds: 300, // ---------------------------------------- pool options MaxIdle: 10, MaxActive: 10, IdleTimeoutSeconds: 60, MaxConnLifetimeSeconds: 120, }) defer bluto.ClosePool() if err != nil { log.Fatal(err) } }
Output:
func (*Bluto) Borrow ¶
Borrow borrows a redis connection from pool
Example ¶
package main import ( "fmt" "log" "github.com/alibaba-go/bluto/bluto" ) func main() { bluto, err := bluto.New(bluto.Config{ Address: "localhost:6379", ConnectTimeoutSeconds: 10, ReadTimeoutSeconds: 10, }) if err != nil { log.Fatal(err) } defer bluto.ClosePool() var pingResult string err = bluto.Borrow().Ping(&pingResult).Commit() if err != nil { log.Fatal(err) } fmt.Println(pingResult) }
Output: PONG
type Config ¶
type Config struct { // ---------------------------------------- dial options Network string Address string Password string ConnectTimeoutSeconds int ReadTimeoutSeconds int WriteTimeoutSeconds int KeepAliveSeconds int // ---------------------------------------- pool options MaxIdle int MaxActive int IdleTimeoutSeconds int MaxConnLifetimeSeconds int }
Config is used to get initialization configs for Pool
Click to show internal directories.
Click to hide internal directories.