service

package
v11.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2018 License: BSD-3-Clause, BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
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
)

Variables

View Source
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
}

Config the redis configuration used inside sessions

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default configuration for Redis service.

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 New

func New(cfg ...Config) *Service

New returns a Redis service filled by the passed config to connect call the .Connect().

func (*Service) CloseConnection

func (r *Service) CloseConnection() error

CloseConnection closes the redis connection

func (*Service) Connect

func (r *Service) Connect()

Connect connects to the redis, called only once

func (*Service) Delete

func (r *Service) Delete(key string) error

Delete removes redis entry by specific key

func (*Service) Get

func (r *Service) Get(key string) (interface{}, error)

Get returns value, err by its key returns nil and a filled error if something bad happened.

func (*Service) GetAll

func (r *Service) GetAll() (interface{}, error)

GetAll returns all redis entries using the "SCAN" command (2.8+).

func (*Service) GetBytes

func (r *Service) GetBytes(key string) ([]byte, error)

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) GetKeys

func (r *Service) GetKeys(prefix string) ([]string, error)

GetKeys returns all redis keys using the "SCAN" with MATCH command. Read more at: https://redis.io/commands/scan#the-match-option.

func (*Service) PingPong

func (r *Service) PingPong() (bool, error)

PingPong sends a ping and receives a pong, if no pong received then returns false and filled error

func (*Service) Set

func (r *Service) Set(key string, value interface{}, secondsLifetime int64) (err error)

Set sets a key-value to the redis store. The expiration is setted by the MaxAgeSeconds.

func (*Service) TTL

func (r *Service) TTL(key string) (seconds int64, hasExpiration bool, found bool)

TTL returns the seconds to expire, if the key has expiration and error if action failed. Read more at: https://redis.io/commands/ttl

func (*Service) UpdateTTL

func (r *Service) UpdateTTL(key string, newSecondsLifeTime int64) error

UpdateTTL will update the ttl of a key. Using the "EXPIRE" command. Read more at: https://redis.io/commands/expire#refreshing-expires

func (*Service) UpdateTTLMany

func (r *Service) UpdateTTLMany(prefix string, newSecondsLifeTime int64) error

UpdateTTLMany like `UpdateTTL` but for all keys starting with that "prefix", it is a bit faster operation if you need to update all sessions keys (although it can be even faster if we used hash but this will limit other features), look the `sessions/Database#OnUpdateExpiration` for example.

Jump to

Keyboard shortcuts

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