storage

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package storage provides a type for storing Go objects in Redis.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is the error returned when the given key is not found.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Comma-separated list of sentinel servers.
	//
	// Example: 10.10.10.10:6379,10.10.10.1:6379,10.10.10.2:6379.
	SentinelAddrs      string `envconfig:"SENTINEL_ADDRS"`
	SentinelMasterName string `envconfig:"SENTINEL_MASTER_NAME"`

	RedisAddr          string `envconfig:"REDIS_ADDR" default:"127.0.0.1:6379"`
	Password           string `envconfig:"REDIS_PASSWORD"`
	PoolSize           int    `envconfig:"REDIS_POOL_SIZE"`
	PoolTimeout        int    `envconfig:"REDIS_POOL_TIMEOUT_SECONDS"`
	IdleTimeout        int    `envconfig:"REDIS_IDLE_TIMEOUT_SECONDS"`
	IdleCheckFrequency int    `envconfig:"REDIS_IDLE_CHECK_FREQUENCY_SECONDS"`
}

Config contains configuration for the Redis, in the standard proposed by Gizmo.

func (*Config) RedisClient

func (c *Config) RedisClient() *redis.Client

RedisClient creates a new instance of the client using the underlying configuration.

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage is the basic type that provides methods for saving, listing and deleting types on Redis.

func NewStorage

func NewStorage(cfg *Config) (*Storage, error)

NewStorage returns a new instance of storage with the given configuration.

func (*Storage) Delete

func (s *Storage) Delete(key string) error

Delete deletes the given key from redis, returning ErrNotFound when it doesn't exist.

func (*Storage) FieldMap

func (s *Storage) FieldMap(hash interface{}) (map[string]interface{}, error)

FieldMap extract the map of fields from the given type (which can be a struct, a map[string]string or pointer to those).

func (*Storage) Load

func (s *Storage) Load(key string, out interface{}) error

Load loads the given key in the given output. The output must be a pointer to a struct or a map[string]string.

func (*Storage) RedisClient

func (s *Storage) RedisClient() *redis.Client

RedisClient returns the underlying Redis client.

func (*Storage) Save

func (s *Storage) Save(key string, hash interface{}) error

Save creates the given key as a Redis hash.

The given hash must be either a struct or map[string]string.

Jump to

Keyboard shortcuts

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