redix

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXPIRE = "expire" // 过期时间
	NX     = "nx"     // 如果不存在,则SET
	XX     = "xx"     // 如果存在,则SET
)

Variables

This section is empty.

Functions

func Init

func Init()

Types

type Config

type Config struct {
	Name     string `mapstructure:"name"`
	Conn     string `mapstructure:"conn"`
	Password string `mapstructure:"password"`
	Timeout  int    `mapstructure:"timeout"`
	DB       int    `mapstructure:"db"`
	PoolSize int    `mapstructure:"pool_size"`
}

type Iterator

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

Iterator 迭代器

func NewIterator

func NewIterator(data []interface{}) *Iterator

func (*Iterator) HasNext

func (i *Iterator) HasNext() bool

func (*Iterator) Next

func (i *Iterator) Next() (res interface{})

type MResult

type MResult struct {
	Value []interface{}
	Error error
}

MResult 列表查询结果

func NewMResult

func NewMResult(value []interface{}, err error) *MResult

func (*MResult) Iterator

func (m *MResult) Iterator() *Iterator

func (*MResult) Result

func (m *MResult) Result(defaultValue ...[]interface{}) []interface{}

type Operation

type Operation struct {
	Name  string
	Value interface{}
}

func WithExpire

func WithExpire(t int) *Operation

WithExpire 超时

func WithNX

func WithNX() *Operation

WithNX 不存在写入

func WithXX

func WithXX() *Operation

WithXX 存在写入

type Operations

type Operations []*Operation

func (Operations) Find

func (o Operations) Find(name string) *Result

type Redis

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

func DB

func DB(name string) *Redis

DB 根据名称获取数据库连接

func (*Redis) Client

func (r *Redis) Client() *redis.Client

func (*Redis) Context

func (r *Redis) Context() context.Context

func (*Redis) Del

func (r *Redis) Del(key string) *Result

Del 删除key

func (*Redis) Get

func (r *Redis) Get(key string) *Result

Get 返回与键 key 相关联的字符串值

func (*Redis) Inrc

func (r *Redis) Inrc(key string) *Result

Inrc 数字加一

func (*Redis) Keys

func (r *Redis) Keys(arg string) *Result

Keys 返回key列表

func (*Redis) Lock

func (r *Redis) Lock(key string, acquire, timeout time.Duration) (string, error)

Lock 分布式锁

func (*Redis) MGet

func (r *Redis) MGet(key string) *MResult

MGet 返回包含了所有给定键的值的列表

func (*Redis) Set

func (r *Redis) Set(key string, value interface{}, ops ...*Operation) *Result

Set 将字符串值 value 关联到 key

func (*Redis) TTL

func (r *Redis) TTL(key string) *Result

TTL 返回剩余有效期

func (*Redis) UnLock

func (r *Redis) UnLock(key, code string) bool

UnLock 释放分布式锁

type Result

type Result struct {
	Value interface{}
	Error error
}

Result 查询单个结果

func NewResult

func NewResult(value interface{}, err error) *Result

NewResult 新建查询结果

func (*Result) Result

func (r *Result) Result(defaultValue ...interface{}) interface{}

Result 返回查询结果的值,defaultValue 表示默认值

Jump to

Keyboard shortcuts

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