src

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

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 (
	DefaultLockTimeout = 60
	DefaultLockRenew   = 3
	DefaultLockPrefix  = "__LOCKER__"
)

Variables

View Source
var (
	Nil = gr.Nil
)

Functions

This section is empty.

Types

type Client

type Client = gr.Client

type Cmd

type Cmd = gr.Cmd

type Config

type Config struct {
	Network  string `yaml:"network" json:"network" label:"模式"`
	Host     string `yaml:"host" json:"host" label:"主机"`
	Port     int    `yaml:"port" json:"port" label:"端口"`
	Password string `yaml:"password" json:"password" label:"密码"`
	Database int    `yaml:"database" json:"database" label:"数据库号"`

	MaxActive   int `yaml:"max-active" json:"max_active" label:"最大连接数"`
	MaxLifetime int `yaml:"max-lifetime" json:"max_lifetime" label:"连接生命周期"`
	MinIdle     int `yaml:"min-idle" json:"min_idle" label:"最小连接"`

	DialTimeout  int `yaml:"dial-timeout" json:"dial_timeout" label:"连接超时"`
	ReadTimeout  int `yaml:"read-timeout" json:"read_timeout" label:"读取超时"`
	WriteTimeout int `yaml:"write-timeout" json:"write_timeout" label:"写入超时"`

	Logger bool `yaml:"log-command" json:"logger"`
	// contains filtered or unexported fields
}

Config 全局配置.

func (*Config) After

func (o *Config) After()

After 后置执行.

func (*Config) String added in v1.2.0

func (o *Config) String() (str string)

String 转成JSON字符串.

type Conn added in v1.2.0

type Conn = gr.Conn

type Locker

type Locker interface {
	// Release
	// 释放锁资源.
	Release()

	// Renew
	// 资源续期.
	Renew(seconds ...int)
}

Locker 分布式锁操作.

func Lock

func Lock(ctx context.Context, key string, seconds ...int) (Locker, error)

Lock 申请分布式锁.

type Manager added in v1.2.0

type Manager interface {
	// Client
	// 读客户端.
	Client() *Client

	// Config
	// 配置实例.
	Config() *Config

	// Connect
	// 获取连接.
	Connect(ctx context.Context) *Conn
}

Manager 管理器接口.

var (
	Mgr Manager
)

type Result added in v1.2.0

type Result interface {
	Error() error
	NotExist() bool
	String() string
	IsOk() bool
	ToInt() int
}

Result 命令结果.

func Del added in v1.2.0

func Del(ctx context.Context, key string) Result

Del 删除键名.

func Do added in v1.2.0

func Do(ctx context.Context, args ...any) (res Result)

Do 执行一条命令.

func Expire added in v1.2.1

func Expire(ctx context.Context, key string, second int) Result

func Get added in v1.2.0

func Get(ctx context.Context, key string) Result

Get 读取一个键值.

func NewResult added in v1.2.0

func NewResult(cmd *gr.Cmd) Result

func Set added in v1.2.0

func Set(ctx context.Context, key string, value any) Result

Set 设置一个键值对, 若目标 Key 不存在则创建.

func SetEx added in v1.2.0

func SetEx(ctx context.Context, key string, value any, seconds ...int) Result

SetEx 设置一个键值对, 并设置有效期, 若目标 Key 不存在则创建.

func SetNx added in v1.2.0

func SetNx(ctx context.Context, key string, value any, seconds ...int) Result

SetNx 设置一个键值对, 并设置有效期, 只有在目标 Key 不存在时有效.

Jump to

Keyboard shortcuts

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