Documentation ¶
Index ¶
- Variables
- type Cache
- type RedisClient
- func (r *RedisClient) Close() error
- func (r *RedisClient) Del(key string) error
- func (r *RedisClient) Get(key string) (string, error)
- func (r *RedisClient) GetBool(key string) (bool, error)
- func (r *RedisClient) GetJSON(key string, result interface{}) error
- func (r *RedisClient) Prefix() string
- func (r *RedisClient) Set(key string, value string, expiration time.Duration) error
- func (r *RedisClient) SetBool(key string, value bool, expiration time.Duration) error
- func (r *RedisClient) SetJSON(key string, value interface{}, expiration time.Duration) error
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("key not found in cache")
ErrNotFound is returned when the key was not found in the cache.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { Prefix() string Set(key string, value string, expiration time.Duration) error Get(key string) (string, error) SetBool(key string, value bool, expiration time.Duration) error GetBool(key string) (bool, error) SetJSON(key string, value interface{}, expiration time.Duration) error GetJSON(key string, result interface{}) error Del(key string) error Close() error }
Cache defines basic cache operartions including methods for setting and getting JSON objects.
type RedisClient ¶
RedisClient wraps the REDIS client to provide an implementation of the Cache interface. It allows defining a prefix that is applied to the key for all operations (optional).
func NewRedis ¶
func NewRedis(redisHost string, redisPort string, prefix string) (*RedisClient, error)
NewRedis creates a new RedisClient.
func (*RedisClient) Close ¶
func (r *RedisClient) Close() error
Close closes the connection to the REDIS server.
func (*RedisClient) Del ¶
func (r *RedisClient) Del(key string) error
Del deletes a key value pair from REDIS. If the client was set up with a prefix it will be added in front of the key.
func (*RedisClient) Get ¶
func (r *RedisClient) Get(key string) (string, error)
Get retrieves a value from REDIS. If the client was set up with a prefix it will be added in front of the key. If the value was not found ErrNotFound will be returned.
func (*RedisClient) GetBool ¶
func (r *RedisClient) GetBool(key string) (bool, error)
GetBool retrieves a boolean value from REDIS. If the client was set up with a prefix it will be added in front of the key.
func (*RedisClient) GetJSON ¶
func (r *RedisClient) GetJSON(key string, result interface{}) error
GetJSON retrieves stringified JSON data from REDIS and parses it into the provided struct. If the client was set up with a prefix it will be added in front of the key.
func (*RedisClient) Prefix ¶
func (r *RedisClient) Prefix() string
Prefix returns the prefix string that was defined for the REDIS client.
func (*RedisClient) Set ¶
Set saves a key value pair to REDIS. If the client was set up with a prefix it will be added in front of the key. Redis `SET key value [expiration]` command. Use expiration for `SETEX`-like behavior. Zero expiration means the key has no expiration time.