msActionStorage

package
v0.0.0-...-0bff97c Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2017 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewRedisStorage = func(config map[string]interface{}) (Storage, error) {
	dsn, ok := config["dsn"]
	if !ok {
		err := fmt.Errorf("the DSN configuration option is required for the Redis storage")
		return nil, err
	}

	sDSN := dsn.(string)

	client, err := redis.Dial("tcp", sDSN)
	if err != nil {
		err := fmt.Errorf("failed to connect to Redis: %s", err.Error())
		return nil, err
	}

	storage := Redis{
		dsn:    sDSN,
		client: client,
	}

	return storage, nil
}

NewRedisStorage implements the StorageFactory function type. It initiates a connection to the Redis database defined in the given configuration, and it returns the Storage engine object.

Functions

This section is empty.

Types

type Redis

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

Redis implements the Storage interface, allowing to use Redis as a Storage engine.

func (Redis) Get

func (storage Redis) Get(id int) (*common.Action, error)

Get implements Storage.Get(). It retrieves from Storage and returns the Action for the given ID.

func (Redis) Set

func (storage Redis) Set(action common.Action) (*int, error)

Set implements Storage.Set(). It stores the given Action object to the Redis Storage.

type RedisClient

type RedisClient interface {
	Cmd(string, ...interface{}) *redis.Resp
}

RedisClient is an interface that is used to allow dependency injection of the Redis client that makes the requests to the Redis datastore. Dependency injection is necessary for testing purposes.

type Storage

type Storage interface {
	Get(int) (*common.Action, error)
	Set(common.Action) (*int, error)
}

Storage is an interface that should be implemented by all Storage engines. It defines an API for storing and retrieving Action objects.

func Create

func Create(config map[string]interface{}) (Storage, error)

Create creates and returns a Storage provider, given the configuration that includes configuration required by the provider.

type StorageFactory

type StorageFactory func(confing map[string]interface{}) (Storage, error)

StorageFactory is a function type that should be implemented by all Storage engine factories. It defines a function type that receives the required configuration as a map, and it returns the Storage engine object. The configuration should include the requested engine keyed "STORAGE_ENGINE" plus any configuration required by the engine itself.

Jump to

Keyboard shortcuts

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