redis

package
v0.0.0-...-9c04300 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK   = "OK"
	PING = "PING"
	PONG = "PONG"

	// key
	DEL    = "DEL"
	EXISTS = "EXISTS"
	INCRBY = "INCRBY"

	// string
	SET = "SET"
	NX  = "NX"
	EX  = "EX"
	GET = "GET"

	// hash
	HDEL    = "HDEL"
	HSET    = "HSET"
	HGET    = "HGET"
	HMGET   = "HMGET"
	HGETALL = "HGETALL"
	HINCRBY = "HINCRBY"

	// set
	SADD     = "SADD"
	SREM     = "SREM"
	SMEMBERS = "SMEMBERS"

	// zorder
	ZINCRBY    = "ZINCRBY"
	ZREVRANGE  = "ZREVRANGE"
	ZSCORE     = "ZSCORE"
	ZREVRANK   = "ZREVRANK"
	WITHSCORES = "WITHSCORES"
)

Variables

View Source
var (
	ErrAtomicLockFailed   = errors.New("lock failed")   // 加锁失败
	ErrAtomicUnlockFailed = errors.New("unlock failed") // 解锁失败
)

Functions

This section is empty.

Types

type Atomic

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

Redis分布式锁

func (*Atomic) Exec

func (a *Atomic) Exec(f func()) (bool, error)

执行分布式事务

func (*Atomic) Expired

func (a *Atomic) Expired(s int64) *Atomic

Key过期时间

func (*Atomic) Lock

func (a *Atomic) Lock() error

获取分布式锁

func (*Atomic) Ticker

func (a *Atomic) Ticker(ms int64) *Atomic

重试频率

func (*Atomic) Timeout

func (a *Atomic) Timeout(s int64) *Atomic

加锁超时时间

func (*Atomic) Unlock

func (a *Atomic) Unlock() error

释放分布式锁

type Hash

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

func (*Hash) Consume

func (h *Hash) Consume(field interface{}, value int64) (int64, bool, error)

为表中指定域加上增量 若增量为负数且与原值计算后为负数则不会进行计算

func (*Hash) Delete

func (h *Hash) Delete(fields ...interface{}) error

删除表中的一个或多个域

func (*Hash) Get

func (h *Hash) Get(field, value interface{}) (bool, error)

获取表中指定域的值

func (*Hash) GetAll

func (h *Hash) GetAll(value interface{}) error

获取表中所有的域和值

func (*Hash) Gets

func (h *Hash) Gets(value interface{}, fields ...interface{}) error

获取表中一个或多个域的值

func (*Hash) Increment

func (h *Hash) Increment(field interface{}, increment int64) (int64, error)

为表中指定域的值加上增量

func (*Hash) Set

func (h *Hash) Set(field, value interface{}) error

为表中的域设置值

type Key

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

func (*Key) Delete

func (k *Key) Delete(keys ...interface{}) error

删除一个或多个键

func (*Key) Exist

func (k *Key) Exist(key interface{}) (bool, error)

检查键是否存在

func (*Key) Get

func (k *Key) Get(key, value interface{}) (bool, error)

获取键的值

func (*Key) Incr

func (k *Key) Incr(key interface{}, value int64) (int64, error)

为键加上增量

func (*Key) Set

func (k *Key) Set(key, value interface{}) error

设置键的值

func (*Key) SetEX

func (k *Key) SetEX(key, value interface{}, second int64) error

设置键的值并设置过期时间

func (*Key) SetNEX

func (k *Key) SetNEX(key, value interface{}, second int64) (bool, error)

当键不存在时设置键的值并设置过期时间

func (*Key) SetNX

func (k *Key) SetNX(key, value interface{}) (bool, error)

当键不存在时设置键的值

type Option

type Option struct {
	Network   string // 网络类型
	Address   string // 地址
	Password  string // 密码
	Database  int    // 数据库
	MaxIdle   int    // 最大空闲连接数
	MaxActive int    // 最大活跃连接数
	Log       bool   // 显示日志
}

type Redis

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

func New

func New(option *Option) (*Redis, error)

func (*Redis) Atomic

func (r *Redis) Atomic(key string) *Atomic

func (*Redis) Do

func (r *Redis) Do(cmd string, args ...interface{}) (interface{}, error)

执行redis命令

func (*Redis) Hash

func (r *Redis) Hash(key string) *Hash

func (*Redis) Key

func (r *Redis) Key() *Key

func (*Redis) Script

func (r *Redis) Script() *script

func (*Redis) Set

func (r *Redis) Set(key string) *Set

func (*Redis) Singleton

func (r *Redis) Singleton(key string) *Singleton

func (*Redis) ZOrder

func (r *Redis) ZOrder(key string) *ZOrder

type Script

type Script struct {
	Name   string
	Script *redis.Script
}

type Set

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

func (*Set) Add

func (s *Set) Add(members ...interface{}) error

将一个或多个成员加入到集合中

func (*Set) Keys

func (s *Set) Keys(value interface{}) error

获取集合中的所有成员

func (*Set) Remove

func (s *Set) Remove(members ...interface{}) error

移除集合中的一个或多个成员

type Singleton

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

func (*Singleton) Exec

func (s *Singleton) Exec(f func()) (bool, error)

type ZOrder

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

func (*ZOrder) Incr

func (z *ZOrder) Incr(member interface{}, increment int64) error

为成员增加分值

func (*ZOrder) Range

func (z *ZOrder) Range(start, stop int, value interface{}) error

返回指定区间内的成员 从0开始

func (*ZOrder) Rank

func (z *ZOrder) Rank(member interface{}) (int64, bool, error)

获取成员的排名 从0开始

func (*ZOrder) Score

func (z *ZOrder) Score(member interface{}) (int64, bool, error)

获取成员的分值

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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