bluto

package
v0.0.0-...-917504b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 4 Imported by: 0

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

func GetPool

func GetPool(config Config) (*redis.Pool, error)

GetPool returns a redis connection pool which the users can use to borrows a connection from the pool

Types

type Bluto

type Bluto struct {
	// contains filtered or unexported fields
}

Bluto is a wrapper over redis pool

func New

func New(config Config) (*Bluto, error)

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

func (bl *Bluto) Borrow() *commander.Commander

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

func (*Bluto) ClosePool

func (bl *Bluto) ClosePool() error

ClosePool closes redis pool

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL