xcache

package
v0.0.0-...-bad164b Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisClient

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

func NewRedisClient

func NewRedisClient(masterName string, addresses []string, password string, logger *xlog.Logger) (*RedisClient, error)

func NewRedisClientByConfig

func NewRedisClientByConfig(config *RedisConfig, logger *xlog.Logger) (*RedisClient, error)

func (*RedisClient) Client

func (r *RedisClient) Client() redis.UniversalClient

func (*RedisClient) Delete

func (r *RedisClient) Delete(k string, timeout time.Duration) (bool, error)

func (*RedisClient) Exists

func (r *RedisClient) Exists(k string, timeout time.Duration) bool

func (*RedisClient) Get

func (r *RedisClient) Get(k string, timeout time.Duration) ([]byte, error)

func (*RedisClient) RedLockFunc

func (r *RedisClient) RedLockFunc(key string, fn func() error, options ...redsync.Option) (err error)

竞争的key,成功后执行fn,fn执行完毕后释放锁

func (*RedisClient) Set

func (r *RedisClient) Set(k, v string, expiration, timeout time.Duration) error

func (*RedisClient) Shadow

func (r *RedisClient) Shadow(logger *xlog.Logger) *RedisClient

创建一个影子redis对象,用于分布式锁

type RedisConfig

type RedisConfig struct {
	Addresses    []string      `yaml:"addresses"` //非哨兵模式时,配置多个地址表示集群模式
	Password     string        `yaml:"password"`
	MasterName   string        `yaml:"master"` //有配置master表示哨兵模式
	Db           int           `yaml:"db"`
	IsConsole    bool          `yaml:"is_console"` //是否打印日志
	DialTimeout  time.Duration `yaml:"dial_timeout"`
	ReadTimeout  time.Duration `yaml:"read_timeout"`
	WriteTimeout time.Duration `yaml:"write_timeout"`
	PoolSize     int           `yaml:"pool_size"`
	MinIdleConns int           `yaml:"min_idle_conns"`
	MaxRetries   int           `yaml:"max_retries"`
}

Jump to

Keyboard shortcuts

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