Documentation ¶
Overview ¶
Package cache offers common cache capbilities, current the only supported backend is redis
Index ¶
- func GobRegister(models ...interface{})
- func NewRedisCacher(server, password string, dbIndex ...int) error
- type Cacher
- type RedisCacher
- func (o *RedisCacher) ClosePool()
- func (o *RedisCacher) Del(key string)
- func (o *RedisCacher) Expire(key string, expiration int) error
- func (o *RedisCacher) Flush() error
- func (o *RedisCacher) FlushAll() error
- func (o *RedisCacher) Get(key string) (interface{}, error)
- func (o *RedisCacher) GetBytes(key string) ([]byte, error)
- func (o *RedisCacher) GetConn() redis.Conn
- func (o *RedisCacher) GetDBSize() (interface{}, error)
- func (o *RedisCacher) GetFloat64(key string) (float64, error)
- func (o *RedisCacher) GetGob(key string) (interface{}, error)
- func (o *RedisCacher) GetInt64(key string) (int64, error)
- func (o *RedisCacher) GetJSON(key string) (jsonBytes []byte, err error)
- func (o *RedisCacher) GetString(key string) (string, error)
- func (o *RedisCacher) HDel(hash, key string) (interface{}, error)
- func (o *RedisCacher) HGet(hash, key string) (interface{}, error)
- func (o *RedisCacher) HINCRBY(hash, key string, value interface{}) error
- func (o *RedisCacher) HSet(hash, key string, value interface{}, expiration ...interface{}) error
- func (o *RedisCacher) MultipleGet(keys ...string) (values []interface{}, err error)
- func (o *RedisCacher) MultipleGetJSON(keys ...string) (values [][]byte, err error)
- func (o *RedisCacher) Scan(cursor int, count int, pattern string) (nextCursor int, keys []string, err error)
- func (o *RedisCacher) Set(key string, value interface{}, expiration ...interface{}) error
- func (o *RedisCacher) SetGob(key string, value interface{}, expiration ...interface{}) error
- func (o *RedisCacher) SetJSON(key string, value interface{}, expiration ...interface{}) error
- func (o *RedisCacher) TTL(key string) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRedisCacher ¶
NewRedisCacher creates a new redis cacher
Types ¶
type Cacher ¶
type Cacher interface { Set(key string, value interface{}, expiration ...interface{}) 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 ...interface{}) GetGob(key string) (interface{}, error) SetJSON(key string, value interface{}, expiration ...interface{}) GetJSON(key string) (jsonBytes []byte, err error) HSet(hash, key string, value interface{}, expiration ...interface{}) 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) 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) 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) HSet ¶
func (o *RedisCacher) HSet(hash, key string, value interface{}, expiration ...interface{}) 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 ...interface{}) 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 ...interface{}) error
SetGob sets a key value pair, value will be gob encoded
func (*RedisCacher) SetJSON ¶
func (o *RedisCacher) SetJSON(key string, value interface{}, expiration ...interface{}) error
SetJSON sets a key value pair, the value is a json