gfrds

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

下面封装一些常用的命令函数,不常用的自己用标准的调用方法。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnCnf

type ConnCnf struct {
	// single redis
	Addr string `v:"match=ipv4:port"`

	// sentinel
	SentinelAddrs []string `v:"match=ipv4:port"`
	MasterName    string   `v:""`
	SentinelPass  string   `v:""`
	SlaveOnly     bool     `v:""`

	// common
	Pass     string `v:"required"`
	DB       int    `v:""`
	PoolSize int    `v:""`
	MinIdle  int    `v:""`

	// 扩展:节点的权重
	Weight uint16 `v:""` // 权重
}

go-redis

func ParseDsn

func ParseDsn(connStr string) *ConnCnf

type GfRedis

type GfRedis struct {
	Cli    *redis.Client
	Ctx    context.Context
	Weight uint16
}

go-redis

func NewGoRedis

func NewGoRedis(cf *ConnCnf) *GfRedis

直接连接redis go-redis 底层自带连接池功能,不需要你再管理了。 看看 go-redis/redis.go 中的代码: 第330行 func (c *baseClient) process(ctx context.Context, cmd Cmder) 第288行 func (c *baseClient) withConn( 第292行 cn, err := c.getConn(ctx)

func (*GfRedis) Del

func (rdx *GfRedis) Del(key string) (int64, error)

func (*GfRedis) Expire

func (rdx *GfRedis) Expire(key string, seconds time.Duration) (bool, error)

func (*GfRedis) Get

func (rdx *GfRedis) Get(key string) (string, error)

func (*GfRedis) Ping

func (rdx *GfRedis) Ping() (string, error)

func (*GfRedis) Set

func (rdx *GfRedis) Set(key string, value any, seconds time.Duration) (string, error)

func (*GfRedis) SetEX

func (rdx *GfRedis) SetEX(key string, value any, seconds time.Duration) (string, error)

func (*GfRedis) SetNX

func (rdx *GfRedis) SetNX(key string, value any, seconds time.Duration) (bool, error)

Jump to

Keyboard shortcuts

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