redis

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Redis

type Redis struct {
	Config *redis.Options
	Client *redis.Client
}

Redis provides a cache backed by a Redis server.

func New

func New(config *redis.Options) *Redis

New returns an initialized Redis cache object.

func (*Redis) DecrBy

func (r *Redis) DecrBy(key string, value int64) (int64, error)

DecrBy returns the value saved under a given key.

func (*Redis) Delete

func (r *Redis) Delete(key string) error

Delete removes a specific key and its value from the Redis server.

func (*Redis) Do

func (r *Redis) Do(cmd, key, seconds string) error

Do 设置过期时间 EXPIRE/PEXPIREAT

EXPIRE aa 60 接口定义:EXPIRE key "seconds" 接口描述:设置一个key在当前时间"seconds"(秒)之后过期。返回1代表设置成功,返回0代表key不存在或者无法设置过期时间。

PEXPIRE 接口定义:PEXPIRE key "milliseconds" 接口描述:设置一个key在当前时间"milliseconds"(毫秒)之后过期。返回1代表设置成功,返回0代表key不存在或者无法设置过期时间。

EXPIREAT aa 1586941008 接口定义:EXPIREAT key "timestamp" 接口描述:设置一个key在"timestamp"(时间戳(秒))之后过期。返回1代表设置成功,返回0代表key不存在或者无法设置过期时间。

PEXPIREAT aa 1586941008000 接口定义:PEXPIREAT key "milliseconds-timestamp" 接口描述:设置一个key在"milliseconds-timestamp"(时间戳(毫秒))之后过期。返回1代表设置成功,返回0代表key不存在或者无法设置过期时间

TTL 接口定义:TTL key     接口描述:获取key的过期时间。如果key存在过期时间,返回剩余生存时间(秒);如果key是永久的,返回-1;如果key不存在或者已过期,返回-2。

PTTL 接口定义:PTTL key     接口描述:获取key的过期时间。如果key存在过期时间,返回剩余生存时间(毫秒);如果key是永久的,返回-1;如果key不存在或者已过期,返回-2。

PERSIST 接口定义:PERSIST key     接口描述:移除key的过期时间,将其转换为永久状态。如果返回1,代表转换成功。如果返回0,代表key不存在或者之前就已经是永久状态。

SETEX 接口定义:SETEX key "seconds" "value"   接口描述:SETEX在逻辑上等价于SET和EXPIRE合并的操作,区别之处在于SETEX是一条命令,而命令的执行是原子性的,所以不会出现并发问题。

func (*Redis) Expire

func (r *Redis) Expire(key string, seconds time.Duration) (bool, error)

Expire 设置过期时间

func (*Redis) Fetch

func (r *Redis) Fetch(key string, fc func() interface{}) (string, error)

Fetch returns the value for the key if it exists or sets and returns the value via the passed function.

func (*Redis) Get

func (r *Redis) Get(key string) (string, error)

Get returns the value saved under a given key.

func (*Redis) GetByte

func (r *Redis) GetByte(key string) ([]byte, error)

GetByte returns the value saved under a given key.

func (*Redis) HDel

func (r *Redis) HDel(key string, field string) error

HDel 返回名称为key的hash中field对应的value

func (*Redis) HExists

func (r *Redis) HExists(key string, field string) error

HExists 返回名称为key的hash中field对应的value

func (*Redis) HGet

func (r *Redis) HGet(key string, field string) (string, error)

HGet 返回名称为key的hash中field对应的value

func (*Redis) HGetall

func (r *Redis) HGetall(key string) (map[string]string, error)

HGetall 返回名称为key的hash中所有的键(field)及其对应的value

func (*Redis) HLen

func (r *Redis) HLen(key string) (int64, error)

HLen 返回名称为key的list的长度

func (*Redis) HMSet

func (r *Redis) HMSet(key string, fields map[string]interface{}) error

HMSet 向名称为map的hash中添加元素field

func (*Redis) HSet

func (r *Redis) HSet(key string, field string, value interface{}) error

HSet 向名称为key的hash中添加元素field

func (*Redis) IncrBy

func (r *Redis) IncrBy(key string, value int64) (int64, error)

IncrBy returns the value saved under a given key.

func (*Redis) LIndex

func (r *Redis) LIndex(key string, index int64) (string, error)

LIndex 返回名称为key的list中index位置的元素

func (*Redis) LLen

func (r *Redis) LLen(key string) (int64, error)

LLen 返回名称为key的list的长度

func (*Redis) LPush

func (r *Redis) LPush(key string, value interface{}) error

LPush 在名称为key的list头添加一个值为value的 元素

func (*Redis) LRange added in v1.2.1

func (r *Redis) LRange(key string) ([]string, error)

LRange 对应RPush获取值 在名称为key的list尾添加一个值为value的元素

func (*Redis) LRem added in v1.2.1

func (r *Redis) LRem(key string, value interface{}) error

LRem 在名称为key的list 删除 一个值为value的元素

func (*Redis) LSet

func (r *Redis) LSet(key string, index int64, value interface{}) (string, error)

LSet 给名称为key的list中index位置的元素赋值

func (*Redis) RPush

func (r *Redis) RPush(key string, value interface{}) error

RPush 在名称为key的list尾添加一个值为value的元素

func (*Redis) SAdd

func (r *Redis) SAdd(key string, field string) error

func (*Redis) SRandMember

func (r *Redis) SRandMember(key string) (string, error)

func (*Redis) Set

func (r *Redis) Set(key string, value interface{}) error

Set saves an arbitrary value under a specific key.

func (*Redis) Unmarshal

func (r *Redis) Unmarshal(key string, object interface{}) error

Unmarshal retrieves a value from the Redis server and unmarshals it into the passed object.

Jump to

Keyboard shortcuts

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