cache

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cache offers common cache capbilities, current the only supported backend is redis

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GobRegister

func GobRegister(models ...interface{})

GobRegister registers models with gob.

func NewRedisCacher

func NewRedisCacher(server, password string, dbIndex ...int) error

NewRedisCacher creates a new redis cacher

Types

type Cacher

type Cacher interface {
	Set(key string, value interface{}, expiration ...int64) error
	Get(key string) (interface{}, error)
	Del(key string)
	Scan(cursor int, count int, pattern string) (nextCursor int, keys []string, err error)
	Expire(key string, expiration int) error
	TTL(key string) (int, error)
	SetGob(key string, value interface{}, expiration ...int64)
	GetGob(key string) (interface{}, error)
	SetJSON(key string, value interface{}, expiration ...int64)
	GetJSON(key string) (jsonBytes []byte, err error)
	HSet(hash, key string, value interface{}, expiration ...int64) error
	HGet(hash, key string) (interface{}, error)
	HINCRBY(hash, key string, value interface{}) error
}

Cacher defines the interface for all typs of cacher. e.g. redis, memcached and etc.

type RedisCacher

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

RedisCacher is an redis implementation of cacher.

var Redis *RedisCacher

Redis is the only one redis cacher, we don't support multiple intances of redis cacher for now.

func (*RedisCacher) ClosePool

func (o *RedisCacher) ClosePool()

ClosePool closes the redis pool

func (*RedisCacher) Del

func (o *RedisCacher) Del(key string)

Del a key

func (*RedisCacher) Expire

func (o *RedisCacher) Expire(key string, expiration int) error

Expire sets a expiration time for key

func (*RedisCacher) Flush

func (o *RedisCacher) Flush() error

Flush flushes all keys in selected db.

func (*RedisCacher) FlushAll

func (o *RedisCacher) FlushAll() error

FlushAll flushes all keys in all db.

func (*RedisCacher) Get

func (o *RedisCacher) Get(key string) (interface{}, error)

Get a value from key

func (*RedisCacher) GetBytes

func (o *RedisCacher) GetBytes(key string) ([]byte, error)

GetBytes gets a []byte value from key

func (*RedisCacher) GetConn

func (o *RedisCacher) GetConn() redis.Conn

GetConn gets a connection

func (*RedisCacher) GetDBSize

func (o *RedisCacher) GetDBSize() (interface{}, error)

GetDBSize get the number of keys in the currently-selected database.

func (*RedisCacher) GetFloat64

func (o *RedisCacher) GetFloat64(key string) (float64, error)

GetFloat64 gets a float64 value from key

func (*RedisCacher) GetGob

func (o *RedisCacher) GetGob(key string) (interface{}, error)

GetGob gets a gob encoded value from key

func (*RedisCacher) GetInt64

func (o *RedisCacher) GetInt64(key string) (int64, error)

GetInt64 gets a int64 value from key

func (*RedisCacher) GetJSON

func (o *RedisCacher) GetJSON(key string) (jsonBytes []byte, err error)

GetJSON gets a json value from key

func (*RedisCacher) GetString

func (o *RedisCacher) GetString(key string) (string, error)

GetString gets a string value from key

func (*RedisCacher) HDel added in v1.0.3

func (o *RedisCacher) HDel(hash, key string) (interface{}, error)

HDel deletes a value from hash set

func (*RedisCacher) HGet

func (o *RedisCacher) HGet(hash, key string) (interface{}, error)

HGet gets a value from hash set

func (*RedisCacher) HINCRBY

func (o *RedisCacher) HINCRBY(hash, key string, value interface{}) error

HINCRBY increments a value for hash set by key.

func (*RedisCacher) HMGet added in v1.5.0

func (o *RedisCacher) HMGet(hash string, keys ...interface{}) (values []interface{}, err error)

HMGet gets a value from hash set

func (*RedisCacher) HSet

func (o *RedisCacher) HSet(hash, key string, value interface{}, expiration ...int64) error

HSet sets a key:value in hash set.

func (*RedisCacher) MultipleGet

func (o *RedisCacher) MultipleGet(keys ...string) (values []interface{}, err error)

MultipleGet gets the values for keys in bulk.

func (*RedisCacher) MultipleGetJSON

func (o *RedisCacher) MultipleGetJSON(keys ...string) (values [][]byte, err error)

MultipleGetJSON gets the values for keys in bulk and return json bytes

func (*RedisCacher) Scan

func (o *RedisCacher) Scan(cursor int, count int, pattern string) (nextCursor int, keys []string, err error)

Scan through the keys with given cursor, pattern and count

func (*RedisCacher) Set

func (o *RedisCacher) Set(key string, value interface{}, expiration ...int64) error

Set a key value pair, the value can be string, int64 and etc.

func (*RedisCacher) SetGob

func (o *RedisCacher) SetGob(key string, value interface{}, expiration ...int64) error

SetGob sets a key value pair, value will be gob encoded

func (*RedisCacher) SetJSON

func (o *RedisCacher) SetJSON(key string, value interface{}, expiration ...int64) error

SetJSON sets a key value pair, the value is a json

func (*RedisCacher) TTL

func (o *RedisCacher) TTL(key string) (int, error)

TTL gets the remaining seconds for key

Jump to

Keyboard shortcuts

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