cache

package
v0.0.0-...-a8c716a Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client 单机模式

func (*Client) AddSet

func (c *Client) AddSet(ctx context.Context, key string, values ...interface{}) error

AddSet 向key集合中添加成员

func (*Client) AddZSet

func (c *Client) AddZSet(ctx context.Context, key string, members ...*ZSetMember) error

AddZSet 向key有序集合添加成员 members map[成员数据]分数

func (*Client) CardZSet

func (c *Client) CardZSet(ctx context.Context, key string) (int64, error)

CardZSet 获取有序集合的成员数

func (*Client) CheckSetMember

func (c *Client) CheckSetMember(ctx context.Context, key string, value interface{}) (bool, error)

CheckSetMember 检查成员是否在集合内

func (*Client) Del

func (c *Client) Del(ctx context.Context, key ...string) error

Del 删除key

func (*Client) FlushDB

func (c *Client) FlushDB(ctx context.Context, isAll bool) error

FlushDB 删除数据 isAll 是否使用FlushAll

func (*Client) GetExpire

func (c *Client) GetExpire(ctx context.Context, key string) (time.Duration, error)

GetExpire 获取ttl

func (*Client) GetHashField

func (c *Client) GetHashField(ctx context.Context, key, field string) (string, error)

GetHashField 获取执行hash的指定field数据 TODO: @zcf 当field对应的数据为非string数据类型时, 需要对该方法进行改造(例如: 返回[]byte); 如果要改造,需要对redis interface同步修改

func (*Client) GetMixed

func (c *Client) GetMixed(ctx context.Context, key string, value interface{}) error

GetMixed 获取到key对应的value mixed redis's basic type TODO: @zcf 根据实际应用,考虑在功能前加入对"key是否存在进行判断"

func (*Client) IsExist

func (c *Client) IsExist(ctx context.Context, key ...string) bool

******************************** 通用接口 ************************************* IsExist 判断key是否存在

func (*Client) LenList

func (c *Client) LenList(ctx context.Context, key string) (int64, error)

LenList 获取指定列表长度

func (*Client) MembersWithScoreZSet

func (c *Client) MembersWithScoreZSet(ctx context.Context, key string) ([]*ZSetMember, error)

MembersWithScoreZSet 从高到低获取有序集合的成员及分数

func (*Client) PopList

func (c *Client) PopList(ctx context.Context, key string, value interface{}) error

PopList 从头部(左边)开始获取并删除

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, key string, value interface{}) error

********************************** pubsub接口 ***************************************

func (*Client) PushList

func (c *Client) PushList(ctx context.Context, key string, values ...interface{}) error

PushList 向key对应的list中从尾部(右边)追加数据

func (*Client) RemMembersZSet

func (c *Client) RemMembersZSet(ctx context.Context, key string, members ...string) error

RemMembersZSet 移除key有序集合中的members

func (*Client) RemSetEle

func (c *Client) RemSetEle(ctx context.Context, key string, values ...interface{}) error

RemSetEle 移除key集合中的元素

func (*Client) ScanKey

func (c *Client) ScanKey(ctx context.Context, match string) chan string

ScanKey 扫描字符串值

func (*Client) SetExpire

func (c *Client) SetExpire(ctx context.Context, key string, ttl time.Duration) error

SetExpire 设置key的ttl

func (*Client) SetHash

func (c *Client) SetHash(ctx context.Context, key string, value map[string]interface{}) error

SetHash设置hash数据

HMSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})

TODO: @zcf redis 的Hash不支持 层级结构

func (*Client) SetNX

func (c *Client) SetNX(ctx context.Context, key, value string, ttl time.Duration) error

SetNX 设置分布式锁

func (*Client) SetStr

func (c *Client) SetStr(ctx context.Context, key, value string) error

******************************** string接口 ************************************* Set 设置key数据(不含TTL)

func (*Client) SetStrTTL

func (c *Client) SetStrTTL(ctx context.Context, key, value string, ttl time.Duration) error

SetStrTTL 设置key数据(含TTL)

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, channels ...string) (<-chan *Message, error)

type Cluster

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

Cluster 集群模式

func (*Cluster) AddSet

func (c *Cluster) AddSet(ctx context.Context, key string, values ...interface{}) error

AddSet 向key集合中添加成员

func (*Cluster) AddZSet

func (c *Cluster) AddZSet(ctx context.Context, key string, members ...*ZSetMember) error

AddZSet 向key有序集合添加成员 members map[成员数据]分数

func (*Cluster) CardZSet

func (c *Cluster) CardZSet(ctx context.Context, key string) (int64, error)

CardZSet 获取有序集合的成员数

func (*Cluster) CheckSetMember

func (c *Cluster) CheckSetMember(ctx context.Context, key string, value interface{}) (bool, error)

CheckSetMember 检查成员是否在集合内

func (*Cluster) Del

func (c *Cluster) Del(ctx context.Context, key ...string) error

Del 删除key

func (*Cluster) FlushDB

func (c *Cluster) FlushDB(ctx context.Context, isAll bool) error

FlushDB 删除数据 isAll 是否使用FlushAll

func (*Cluster) GetExpire

func (c *Cluster) GetExpire(ctx context.Context, key string) (time.Duration, error)

GetExpire 获取ttl

func (*Cluster) GetHashField

func (c *Cluster) GetHashField(ctx context.Context, key, field string) (string, error)

GetHashField 获取执行hash的指定field数据 TODO: @zcf 当field对应的数据为非string数据类型时, 需要对该方法进行改造(例如: 返回[]byte); 如果要改造,需要对redis interface同步修改

func (*Cluster) GetMixed

func (c *Cluster) GetMixed(ctx context.Context, key string, value interface{}) error

GetMixed 获取到key对应的value mixed redis's basic type TODO: @zcf 根据实际应用,考虑在功能前加入对"key是否存在进行判断"

func (*Cluster) IsExist

func (c *Cluster) IsExist(ctx context.Context, key ...string) bool

******************************** 通用接口 ************************************* IsExist 判断key是否存在

func (*Cluster) LenList

func (c *Cluster) LenList(ctx context.Context, key string) (int64, error)

LenList 获取指定列表长度

func (*Cluster) MembersWithScoreZSet

func (c *Cluster) MembersWithScoreZSet(ctx context.Context, key string) ([]*ZSetMember, error)

MembersWithScoreZSet 从高到低获取有序集合的成员及分数

func (*Cluster) PopList

func (c *Cluster) PopList(ctx context.Context, key string, value interface{}) error

PopList 从头部(左边)开始获取并删除

func (*Cluster) Publish

func (c *Cluster) Publish(ctx context.Context, key string, value interface{}) error

********************************** pubsub接口 ***************************************

func (*Cluster) PushList

func (c *Cluster) PushList(ctx context.Context, key string, values ...interface{}) error

PushList 向key对应的list中从尾部(右边)追加数据

func (*Cluster) RemMembersZSet

func (c *Cluster) RemMembersZSet(ctx context.Context, key string, members ...string) error

RemMembersZSet 移除key有序集合中的members

func (*Cluster) RemSetEle

func (c *Cluster) RemSetEle(ctx context.Context, key string, values ...interface{}) error

RemSetEle 移除key集合中的元素

func (*Cluster) ScanKey

func (c *Cluster) ScanKey(ctx context.Context, match string) chan string

ScanKey 扫描字符串值

func (*Cluster) SetExpire

func (c *Cluster) SetExpire(ctx context.Context, key string, ttl time.Duration) error

SetExpire 设置key的ttl

func (*Cluster) SetHash

func (c *Cluster) SetHash(ctx context.Context, key string, value map[string]interface{}) error

SetHash设置hash数据

HMSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})

TODO: @zcf redis 的Hash不支持 层级结构

func (*Cluster) SetNX

func (c *Cluster) SetNX(ctx context.Context, key, value string, ttl time.Duration) error

SetNX 设置分布式锁

func (*Cluster) SetStr

func (c *Cluster) SetStr(ctx context.Context, key, value string) error

******************************** string接口 ************************************* Set 设置key数据(不含TTL)

func (*Cluster) SetStrTTL

func (c *Cluster) SetStrTTL(ctx context.Context, key, value string, ttl time.Duration) error

SetStrTTL 设置key数据(含TTL)

func (*Cluster) Subscribe

func (c *Cluster) Subscribe(ctx context.Context, channels ...string) (<-chan *Message, error)

type DeployMode

type DeployMode string

声明支持的redis部署模式

const (
	ClientMod   DeployMode = "client"   // 单机模式
	ClusterMod  DeployMode = "cluster"  // 集群模式
	SentinelMod DeployMode = "sentinel" // 哨兵模式
)

type ListFlag

type ListFlag int8

声明对list的操作点

const (
	StartPoint ListFlag = iota + 1 // 列表的头部(左边)
	EndPoint                       // 列表的尾部(右边)
)

type Message

type Message struct {
	Channel      string
	Pattern      string
	Payload      interface{}
	PayloadSlice []string
}

type OptionFunc

type OptionFunc func(*redis.Options)

func WithAuth

func WithAuth(user, passwd string) OptionFunc

WithAuth 配置鉴权

func WithPasswd

func WithPasswd(passwd string) OptionFunc

WithPasswd 配置密码

type OptionFuncForCluster

type OptionFuncForCluster func(*redis.ClusterOptions)

func ClusterWithAuth

func ClusterWithAuth(user, passwd string) OptionFuncForCluster

WithAuth 配置鉴权

func ClusterWithPasswd

func ClusterWithPasswd(passwd string) OptionFuncForCluster

WithPasswd 配置密码

type Redis

type Redis interface {
	IsExist(ctx context.Context, key ...string) bool
	FlushDB(ctx context.Context, isAll bool) error
	Del(ctx context.Context, key ...string) error
	SetExpire(ctx context.Context, key string, ttl time.Duration) error
	GetExpire(ctx context.Context, key string) (time.Duration, error)
	GetMixed(ctx context.Context, key string, value interface{}) error
	ScanKey(ctx context.Context, match string) chan string

	SetStr(ctx context.Context, key, value string) error
	SetStrTTL(ctx context.Context, key, value string, ttl time.Duration) error
	SetNX(ctx context.Context, key, value string, ttl time.Duration) error

	SetHash(ctx context.Context, key string, value map[string]interface{}) error
	GetHashField(ctx context.Context, key, field string) (string, error)

	PushList(ctx context.Context, key string, values ...interface{}) error
	LenList(ctx context.Context, key string) (int64, error)
	PopList(ctx context.Context, key string, value interface{}) error

	AddSet(ctx context.Context, key string, values ...interface{}) error
	CheckSetMember(ctx context.Context, key string, value interface{}) (bool, error)
	RemSetEle(ctx context.Context, key string, values ...interface{}) error

	AddZSet(ctx context.Context, key string, members ...*ZSetMember) error
	CardZSet(ctx context.Context, key string) (int64, error)
	MembersWithScoreZSet(ctx context.Context, key string) ([]*ZSetMember, error)
	RemMembersZSet(ctx context.Context, key string, members ...string) error
	Publish(ctx context.Context, channel string, message interface{}) error
	Subscribe(ctx context.Context, channels ...string) (<-chan *Message, error)
}

func InitRedisClient

func InitRedisClient(ctx context.Context, conf *RedisConf) (client Redis, err error)

InitRedisClient 实例化redis连接对象

func NewClient

func NewClient(ctx context.Context, addr string, db int, ops ...OptionFunc) (Redis, error)

func NewCluster

func NewCluster(ctx context.Context, addr []string, ops ...OptionFuncForCluster) (Redis, error)

type RedisConf

type RedisConf struct {
	DeployMode DeployMode `json:"deployMode"`
	Endpoints  []string   `json:"endpoints"`
	User       string     `json:"user"`
	Password   string     `json:"passwd"`
	Db         int        `json:"db"`
}

RedisConf redis的连接配置 nolint

type Sentinel

type Sentinel struct{}

Sentinel 哨兵模式

type ZSetMember

type ZSetMember struct {
	Score  float64     `json:"score"`
	Member interface{} `json:"member"`
}

ZSetMember 有序集合的数据结构

Jump to

Keyboard shortcuts

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