redis

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeMode    = "node"
	ClusterMode = "cluster"
)

Variables

View Source
var (
	ErrNil                    = redis.Nil
	ErrInvalidExpireParameter = errors.New("expire must be larger than 0")
)

Functions

This section is empty.

Types

type Client

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

Client Redis客户端

func NewRedisClient

func NewRedisClient(config *ClientConfig) *Client

NewRedisClient 根据传入的Config新建Client

func (*Client) Del

func (rc *Client) Del(k ...string) error

Del 删除键值对

func (*Client) Exists

func (rc *Client) Exists(k string) (bool, error)

Exists 判断键值对是否存在

func (*Client) Expire

func (rc *Client) Expire(k string, expire int64) bool

Expire 设置键值对超时时间

func (*Client) Get

func (rc *Client) Get(k string) (string, error)

Get 通过键获取对应值,键值对不存在时返回空字符串

func (*Client) HashDel

func (rc *Client) HashDel(hashKey string, field ...string) error

HashDel 删除一个或多个哈希表字段

func (*Client) HashExist

func (rc *Client) HashExist(hashKey string, field string) (bool, error)

HashExist 获取在哈希表指定的key中是否存在目标字段

func (*Client) HashGet

func (rc *Client) HashGet(hashKey string, field string) (string, error)

HashGet 获取存储在哈希表中指定字段的值,未查找到则返回 err See ErrNil

func (*Client) HashGetAll

func (rc *Client) HashGetAll(hashKey string) (map[string]string, error)

HashGetAll 获取在哈希表中指定 key 的所有字段和值,不存在值则返回一个非nil的map,其len为0

func (*Client) HashLen

func (rc *Client) HashLen(hashKey string) (int64, error)

HashLen 获取在哈希表中指定Key的长度

func (*Client) HashSet

func (rc *Client) HashSet(hashKey string, field string, value string) error

HashSet 将哈希表 key 中的字段 field 的值设为 value

func (*Client) HashSetMap

func (rc *Client) HashSetMap(hashKey string, value map[string]interface{}) error

HashSetMap 将 map[string]interface 的内容存入对应key的哈希表中

func (*Client) HashSetNX

func (rc *Client) HashSetNX(hashKey string, field string, value string) (bool, error)

HashSetNX 只在值不存在时设置值

func (*Client) ListLength

func (rc *Client) ListLength(listKey string) (int, error)

ListLength llen 获取列表长度

func (*Client) ListRange

func (rc *Client) ListRange(listKey string, start int, stop int) ([]string, error)

ListRange lrange 获取列表指定范围内的元素

func (*Client) ListRemove

func (rc *Client) ListRemove(listKey string, count int, value string) error

ListRemove lrem 根据参数 COUNT 的值,移除列表中与参数 VALUE 相等的元素

func (*Client) ListTrim

func (rc *Client) ListTrim(listKey string, start int, stop int) error

ListTrim ltrim 对一个列表进行修改,只保留指定区间内的元素,不在指定区间之内的元素都将被删除

func (*Client) RightPush

func (rc *Client) RightPush(listKey string, v ...string) error

RightPush rpush 将值添加到列表尾部

func (*Client) Set

func (rc *Client) Set(k string, v string) error

Set sets a key-value pair.

func (*Client) SetExpire

func (rc *Client) SetExpire(key string, expire int64) error

SetExpire 修改key的过期时间

func (*Client) SetNXWithExpire

func (rc *Client) SetNXWithExpire(k string, v string, expire int64) (bool, error)

SetNXWithExpire sets a key-value pair with expire. True will be returned if target pair not exists, otherwise false will be returned

func (*Client) SetWithExpire

func (rc *Client) SetWithExpire(k string, v string, expire int64) error

SetWithExpire sets a key-value pair with expire.

func (*Client) Type

func (rc *Client) Type() string

type ClientConfig

type ClientConfig struct {
	Host           string
	Type           string        `json:",default=node,options=node|cluster"`
	MinIdle        int           `json:",default=1"`
	MaxActive      int           `json:",default=10"`
	IdleTimeout    time.Duration `json:",default=10s"`
	Verbose        bool          `json:",default=false,options=true|false"`
	Pass           string        `json:",optional"`
	ConnectTimeout time.Duration `json:",default=100ms"`
	ReadTimeout    time.Duration `json:",default=100ms"`
	WriteTimeout   time.Duration `json:",default=100ms"`
}

ClientConfig 配置信息

Jump to

Keyboard shortcuts

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