Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Service
- func (r *Service) CloseConnection() error
- func (r *Service) Connect()
- func (r *Service) Delete(key string) error
- func (r *Service) Get(key string) (interface{}, error)
- func (r *Service) GetAll(key string) (map[string]string, error)
- func (r *Service) GetAllKeysByPrefix(prefix string) ([]string, error)
- func (r *Service) GetBytes(key string) ([]byte, error)
- func (r *Service) GetInt(key string) (int, error)
- func (r *Service) GetString(key string) (string, error)
- func (r *Service) GetStringMap(key string) (map[string]string, error)
- func (r *Service) PingPong() (bool, error)
- func (r *Service) Set(key string, value []byte) (err error)
Constants ¶
const ( // DefaultRedisNetwork the redis network option, "tcp" DefaultRedisNetwork = "tcp" // DefaultRedisAddr the redis address option, "127.0.0.1:6379" DefaultRedisAddr = "127.0.0.1:6379" // DefaultRedisIdleTimeout the redis idle timeout option, time.Duration(5) * time.Minute DefaultRedisIdleTimeout = time.Duration(5) * time.Minute // DefaultRedisMaxAgeSeconds the redis storage last parameter (SETEX), 31556926.0 (1 year) DefaultRedisMaxAgeSeconds = 31556926.0 //1 year )
Variables ¶
var ( // ErrRedisClosed an error with message 'Redis is already closed' ErrRedisClosed = errors.New("Redis is already closed") // ErrKeyNotFound an error with message 'Key $thekey doesn't found' ErrKeyNotFound = errors.New("Key '%s' doesn't found") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Network "tcp" Network string // Addr "127.0.0.1:6379" Addr string // Password string .If no password then no 'AUTH'. Default "" Password string // If Database is empty "" then no 'SELECT'. Default "" Database string // MaxIdle 0 no limit MaxIdle int // MaxActive 0 no limit MaxActive int // IdleTimeout time.Duration(5) * time.Minute IdleTimeout time.Duration // Prefix "myprefix-for-this-website". Default "" Prefix string // MaxAgeSeconds how much long the redis should keep the session in seconds. Default 31556926.0 (1 year) MaxAgeSeconds int }
Config the redis configuration used inside sessions
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default configuration for Redis service
func (Config) MergeSingle ¶
MergeSingle merges the default with the given config and returns the result
type Service ¶
type Service struct { // Connected is true when the Service has already connected Connected bool // Config the redis config for this redis Config *Config // contains filtered or unexported fields }
Service the Redis service, contains the config and the redis pool
func (*Service) CloseConnection ¶
CloseConnection closes the redis connection
func (*Service) Connect ¶
func (r *Service) Connect()
Connect connects to the redis, called only once
func (*Service) Get ¶
Get returns value, err by its key you can use utils.Deserialize((.Get("yourkey"),&theobject{}) returns nil and a filled error if something wrong happens
func (*Service) GetAll ¶
GetAll returns all keys and their values from a specific key (map[string]string) returns a filled error if something bad happened
func (*Service) GetAllKeysByPrefix ¶
GetAllKeysByPrefix returns all []string keys by a key prefix from the redis
func (*Service) GetBytes ¶
GetBytes returns value, err by its key you can use utils.Deserialize((.GetBytes("yourkey"),&theobject{}) returns nil and a filled error if something wrong happens
func (*Service) GetInt ¶
GetInt returns value, err by its key you can use utils.Deserialize((.GetInt("yourkey"),&theobject{}) returns -1 int and a filled error if something wrong happens
func (*Service) GetString ¶
GetString returns value, err by its key you can use utils.Deserialize((.GetString("yourkey"),&theobject{}) returns empty string and a filled error if something wrong happens
func (*Service) GetStringMap ¶
GetStringMap returns map[string]string, err by its key returns nil and a filled error if something wrong happens