Documentation ¶
Index ¶
- Constants
- Variables
- func Drivers() []string
- func Register(name string, driver CacheDriverer)
- type CacheDriverer
- type Cacher
- type PoolSettings
- type RedisCache
- func (r *RedisCache) Close() error
- func (r *RedisCache) Decr(key string, num ...int) (int, error)
- func (r *RedisCache) Delete(key string) error
- func (r *RedisCache) Get(key string) ([]byte, error)
- func (r *RedisCache) Incr(key string, num ...int) (int, error)
- func (r *RedisCache) Set(key string, value []byte, expiration ...time.Duration) error
- type RedisDSN
- type RedisDriver
- type RedisSettings
Constants ¶
View Source
const ( URL_PARAM_POOL_MAX_ACTIVE = "pool_max_active" URL_PARAM_POOL_MAX_IDLE = "pool_max_idle" URL_PARAM_POOL_IDLE_TIMEOUT = "pool_idle_timeout" URL_PARAM_EXPIRATION = "expiration" URL_PARAM_PREFIX = "prefix" DEFAULT_POOL_MAX_ACTIVE = 20 DEFAULT_POOL_MAX_IDLE = 10 DEFAULT_POOL_IDLE_TIMEOUT = 200 * time.Millisecond DEFAULT_EXPIRATION = 0 * time.Second DEFAULT_PREFIX = "" )
View Source
const (
LOCMEM_DEFAULT_DATABASE = "default"
)
Variables ¶
View Source
var (
ErrNotFound = errors.New("locmem item not found")
)
Functions ¶
func Register ¶
func Register(name string, driver CacheDriverer)
Register makes a cache driver available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.
Types ¶
type CacheDriverer ¶
type CacheDriverer interface { Open(dsn string) (Cacher, error) OpenConnection(connection interface{}, settings ...string) (Cacher, error) }
CacheDriverer interface
All cache drivers must satisfy this interface.
type Cacher ¶
type Cacher interface { // returns cache value by key Get(key string) ([]byte, error) // Sets key to value, if expiration is not given it's used from settings Set(key string, value []byte, expiration ...time.Duration) error // Deletes key in cache Delete(key string) error // Increments key by 1, if num is given by that amout will be incremented Incr(key string, num ...int) (int, error) // Decrements key by 1, if num is given it decrements by given number Decr(key string, num ...int) (int, error) // Return cache to cache pool Close() error }
Cache interface
All cache implementations must satisfy this interface.
func Open ¶
Opens cache by dsn This method is preferred to use for instantiate Cache. DSN is used as connector. Additional settings are set as url parameters.
Example:
redis://localhost:5379/0?pool_max_active=10&expiration=10
Which translates to connection to localhost:5379 redis pool max_active=10 and expiration for cache.Set default value will be set to 10 seconds
type PoolSettings ¶
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
Redis cache implementation
func (*RedisCache) Close ¶
func (r *RedisCache) Close() error
closes cache (it's underlying connection)
func (*RedisCache) Decr ¶
func (r *RedisCache) Decr(key string, num ...int) (int, error)
Decrements key in cache
func (*RedisCache) Get ¶
func (r *RedisCache) Get(key string) ([]byte, error)
returns data from cache
type RedisDriver ¶
type RedisDriver struct{}
func (*RedisDriver) OpenConnection ¶
func (r *RedisDriver) OpenConnection(connection interface{}, settings ...string) (Cacher, error)
type RedisSettings ¶
type RedisSettings struct {
// contains filtered or unexported fields
}
func NewRedisSettings ¶
func NewRedisSettings(values *godsn.DSNValues) (*RedisSettings, error)
func NewRedisSettingsFromQuery ¶
func NewRedisSettingsFromQuery(query string) (*RedisSettings, error)
func (*RedisSettings) Prefixed ¶
func (r *RedisSettings) Prefixed(str string) string
returns prefixed string
Click to show internal directories.
Click to hide internal directories.