redis

package
v0.0.0-...-c0abf8a Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDbNotFound    = errors.New("Cache: The database to be closed does not exist")
	ErrAliasNotExist = errors.New("Cache: The specified alias does not exist")

	ErrDriverTypeNotFound = errors.New("Cache: Driver Type does not exist")

	ErrPoolDisconnected = errors.New("Cache: Connection pool has been disconnected")

	ErrNotHaveAvailableConn = errors.New("Cache: No connections available")

	ErrValueNotBeenNil = errors.New("Cache: Value cannot be empty")
	ErrKeyNotBeenNil   = errors.New("Cache: Key cannot be empty")

	ErrHashScan = errors.New("Cache: Wrong hash structure")

	ErrScanStructValue = errors.New("Cache: value must be non-nil pointer to a struct")
)
View Source
var EnableCache bool

是否启用缓存,默认为true

Functions

func RegisterDb

func RegisterDb(aliasName string, driverType DriverType, host, pwd string, params ...int) error

Types

type Database

type Database interface {
	Open(settings *connectionURL) error
	Close() error
	//判断key是否存在
	Exists(Prefix, key string) (bool, error)
	Expire(Prefix, key string, expireSecond int) (int64, error)
	SGet(Prefix, key string) (string, error)
	SSet(Prefix, key string, value interface{}, expireSecond int) error
	Del(Prefix, key string) (int64, error)
	HSet(Prefix, key, field string, value interface{}) (int64, error)
	HSetExpire(Prefix, key, field, data string, expireSecond int) (int64, error)

	//HGetVals Redis Hvals 命令返回哈希表所有域(field)的值。
	HGetVals(Prefix, key string) ([]string, error)
	HGetAll(Prefix string, key string) (map[string]string, error)
	HGetValsByMulKey(Prefix string, keys ...string) (hv []HVal, err error)
	HDel(Prefix, key string, fields ...string) (int64, error)
	HExist(Prefix, key string, fields string) (bool, error)
}

func GetCache

func GetCache(aliasName string) (Database, error)

GetCache

type DriverType

type DriverType int
const (
	DriverRedis DriverType = 0
)

type HVal

type HVal struct {
	Field string
	Value string
}

type RedisDB

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

func (*RedisDB) Close

func (cache *RedisDB) Close() error

func (*RedisDB) Del

func (cache *RedisDB) Del(Prefix, key string) (int64, error)

func (*RedisDB) Exists

func (cache *RedisDB) Exists(Prefix, key string) (bool, error)

func (*RedisDB) Expire

func (cache *RedisDB) Expire(Prefix, key string, expireSecond int) (int64, error)

func (*RedisDB) HDel

func (cache *RedisDB) HDel(Prefix, key string, fields ...string) (int64, error)

func (*RedisDB) HExist

func (cache *RedisDB) HExist(Prefix, key, field string) (bool, error)

func (*RedisDB) HGetAll

func (cache *RedisDB) HGetAll(Prefix string, key string) (map[string]string, error)

func (*RedisDB) HGetVals

func (cache *RedisDB) HGetVals(Prefix, key string) ([]string, error)

func (*RedisDB) HGetValsByMulKey

func (cache *RedisDB) HGetValsByMulKey(Prefix string, keys ...string) (hv []HVal, err error)

hash bucket: get all values,each with field,value

func (*RedisDB) HSet

func (cache *RedisDB) HSet(Prefix, key, field string, value interface{}) (int64, error)

func (*RedisDB) HSetExpire

func (cache *RedisDB) HSetExpire(Prefix, key, field, data string, expireSecond int) (int64, error)

hash bucket:set ,with expiration

func (*RedisDB) Open

func (cache *RedisDB) Open(settings *connectionURL) error

func (*RedisDB) SGet

func (cache *RedisDB) SGet(Prefix, key string) (string, error)

func (*RedisDB) SSet

func (cache *RedisDB) SSet(Prefix, key string, value interface{}, expireSecond int) error

Jump to

Keyboard shortcuts

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