Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( DefaultHost = "127.0.0.1" DefaultNetwork = "tcp" DefaultPort = 6379 DefaultMaxActive = 10 DefaultMinIdle = 2 DefaultMaxLifetime = 60 DefaultTimeoutDial = 5 DefaultTimeoutRead = 3 DefaultTimeoutWrite = 3 )
View Source
const ( DefaultLockDuration = time.Second * 60 DefaultLockRenew = 25 DefaultLockPrefix = "__LOCKER__" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Network string `yaml:"network"` Host string `yaml:"host"` Port int `yaml:"port"` Password string `yaml:"password"` Database int `yaml:"database"` MaxActive int `yaml:"max-active"` MaxLifetime int `yaml:"max-lifetime"` MinIdle int `yaml:"min-idle"` DialTimeout int `yaml:"dial-timeout"` ReadTimeout int `yaml:"read-timeout"` WriteTimeout int `yaml:"write-timeout"` }
Config is a component used to parse configurations.
type Connection ¶
type ConnectorManager ¶
type ConnectorManager interface { // Do // send a command directly. Do(ctx context.Context, args ...any) (*Cmd, error) // GetClient // returns a redis client. GetClient() (client *Client, err error) // GetConfig // returns a config component. GetConfig() *Config // GetConnection // acquire a redis connection from pool. GetConnection(ctx context.Context) (connection *Connection, err error) // GetError // returns a error on connector. GetError() error }
ConnectorManager is an interface used to manage redis connection.
var Connector ConnectorManager
Connector is a singleton instance used to manage redis connection.
type Locker ¶
type Locker interface { // Release // applied resource. Release() // Renew // prevent distributed lock from being deleted due to timeout. Renew(seconds ...int) }
Locker is an interface of locker.
func Lock ¶
Lock apply a distributed lock resource. Return nil if given key applied by other connection.
Example ¶
ctx := context.Background() key := "key" // Apply distributed lock resource. res, err := Lock(ctx, key) if err != nil { return } // Apply failed, It's applied by other goroutine. if res == nil { return } // Release applied distributed lock resource when done. defer res.Release() res.Renew() // Your logic code ... time.Sleep(time.Second * 3)
Output:
Click to show internal directories.
Click to hide internal directories.