redis

package
v0.0.0-...-5a37ffa Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

redis相关的功能
	1. 初始化
		Init(redisCfg *RedisConfigST) error

	2. 使用接口
		Get(key string) (reply interface{}, error) 查询单个Key
		GetMulti(keys []string) (replys []interface{}, error) 查询多个KEY
		Set(key string, val interface{}, timeout int) error 设置单个Key
		Del(key string) error 删除key
		IncrBy(key string, step int) error key自增
		DecrBy(key string, step int) error key自减
		Do(command string, args ...interface{}) (reply interface{}, error) 未定义的接口使用

		// ID生成器,唯一的ID生成
		NewID(key string, base int64) (int64, error)

放全局函数

Index

Constants

This section is empty.

Variables

View Source
var (
	IDsMap sync.Map //用于缓存ID,ID即是需要全局唯一,递增的整型变量
)

Functions

func CondV

func CondV(cond bool, v1 interface{}, v2 interface{}) interface{}

二元组运算的实现 max = b>a ? b : a -> max = CondV(b>a, b, a).(a.Type())

func DecrBy

func DecrBy(key string, step int) (interface{}, error)

func Del

func Del(key string) error

func Do

func Do(command string, args ...interface{}) (reply interface{}, err error)

所有未定义的接口使用

func Expire

func Expire(key string, timeout int) error

func Get

func Get(key string) (interface{}, error)

func GetJsonObj

func GetJsonObj(key string, data interface{}) error

获取Json对象的数据

func HGet

func HGet(keys ...interface{}) (interface{}, error)

如果redis不支持MGET,则需要修改为一个一个的查询

func HMGet

func HMGet(keys ...interface{}) (interface{}, error)

如果redis不支持MGET,则需要修改为一个一个的查询

func HMSet

func HMSet(keys ...interface{}) error

如果redis不支持MGET,则需要修改为一个一个的查询

func HSet

func HSet(keys ...interface{}) error

如果redis不支持MGET,则需要修改为一个一个的查询

func IDInc

func IDInc(key string) (int64, error)

func IDIncDirect

func IDIncDirect(key string) (int64, error)

func IDIncU64

func IDIncU64(key string) (uint64, error)

func IncrBy

func IncrBy(key string, step int) (interface{}, error)

func Init

func Init(cfg *Config) (err error)

func MGet

func MGet(keys []interface{}) (interface{}, error)

如果redis不支持MGET,则需要修改为一个一个的查询

func Set

func Set(key string, val interface{}, timeout int) error

timeout 超时时间,单位秒

Types

type Config

type Config struct {
	Server       []string
	ConnTimeOut  int // 连接超时时间 单位秒
	ReadTimeOut  int
	WriteTimeOut int
	KeepAlive    int
	AliveTime    int
}

Config Redis的配置信息

type ID

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

type Pool

type Pool struct {
	*redis.Cluster
}

Pool Redis的连接池封装

func New

func New(cfg *Config) (*Pool, error)

New 根据配置创建连接池

func (*Pool) DecrBy

func (p *Pool) DecrBy(key string, step int) (interface{}, error)

func (*Pool) Del

func (p *Pool) Del(key string) error

func (*Pool) Expire

func (p *Pool) Expire(key string, timeout int) error

func (*Pool) Get

func (p *Pool) Get(key string) (interface{}, error)

func (*Pool) GetJsonObj

func (p *Pool) GetJsonObj(key string, data interface{}) error

获取Json对象的数据

func (*Pool) HGet

func (p *Pool) HGet(keys []interface{}) (interface{}, error)

func (*Pool) HMGet

func (p *Pool) HMGet(keys []interface{}) (interface{}, error)

func (*Pool) HMSet

func (p *Pool) HMSet(keys []interface{}) error

func (*Pool) HSet

func (p *Pool) HSet(keys []interface{}) error

func (*Pool) IDInc

func (p *Pool) IDInc(key string) (int64, error)

IDInc 为减少访问Redis次数,在此做缓存

func (*Pool) IDIncDirect

func (p *Pool) IDIncDirect(key string, n int) (int64, error)

IDIncDirect 直接从Redis获取,不缓存

func (*Pool) IncrBy

func (p *Pool) IncrBy(key string, step int) (interface{}, error)

func (*Pool) MGet

func (p *Pool) MGet(keys []interface{}) (interface{}, error)

如果redis不支持MGET,则需要修改为一个一个的查询

func (*Pool) Set

func (p *Pool) Set(key string, val interface{}, timeout int) error

timeout 超时时间,单位秒

Jump to

Keyboard shortcuts

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