store

package
v0.0.0-...-569f0c3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InMemory storage
	InMemory = "memory"
	// Redis storage
	Redis = "redis"
	// None Nullable storage
	None = "none"
)

Variables

View Source
var (
	// ErrUnknownStorage is used when the storage type is nknown
	ErrUnknownStorage = errors.New(http.StatusBadRequest, "Unknown storage type")
)

Functions

This section is empty.

Types

type InMemoryStore

type InMemoryStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

InMemoryStore is the redis store.

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

NewInMemoryStore returns an instance of memory store.

func NewInMemoryStoreWithOptions

func NewInMemoryStoreWithOptions() *InMemoryStore

NewInMemoryStoreWithOptions returns an instance of memory store with custom options.

func (*InMemoryStore) Exists

func (s *InMemoryStore) Exists(key string) (bool, error)

Exists checks if a key exists in the store

func (*InMemoryStore) Get

func (s *InMemoryStore) Get(key string) (string, error)

Get retreives a value from the store

func (*InMemoryStore) Publish

func (s *InMemoryStore) Publish(topic string, data []byte) error

Publish publishes in memory

func (*InMemoryStore) Remove

func (s *InMemoryStore) Remove(key string) error

Remove a value from the store

func (*InMemoryStore) Set

func (s *InMemoryStore) Set(key string, value string, expire int64) error

Set a value in the store

func (*InMemoryStore) Subscribe

func (s *InMemoryStore) Subscribe(channel string, callback func(notifier.Notification)) error

Subscribe subscribes to messages in memory

type Options

type Options struct {
	// Prefix is the prefix to use for the key.
	Prefix string

	// MaxRetry is the maximum number of retry under race conditions.
	MaxRetry int

	// CleanUpInterval is the interval for cleanup.
	CleanUpInterval time.Duration
}

Options are options for store.

type RedisStore

type RedisStore struct {
	// The prefix to use for the key.
	Prefix string

	// go-redis Client instance
	Client *redis.Client

	// The maximum number of retry under race conditions.
	MaxRetry int
}

RedisStore is the redis store.

func (*RedisStore) Exists

func (s *RedisStore) Exists(key string) (bool, error)

Exists checks if a key exists in the store

func (*RedisStore) Get

func (s *RedisStore) Get(key string) (string, error)

Get retreives a value from the store

func (*RedisStore) Publish

func (s *RedisStore) Publish(topic string, data []byte) error

Publish publishes to a topic in redis

func (*RedisStore) Remove

func (s *RedisStore) Remove(key string) error

Remove a value from the store

func (*RedisStore) Set

func (s *RedisStore) Set(key string, value string, expire int64) error

Set a value in the store

func (*RedisStore) Subscribe

func (s *RedisStore) Subscribe(channel string, callback func(notifier.Notification)) error

Subscribe subscribes to a topic in redis

type Store

type Store interface {
	Exists(key string) (bool, error)
	Get(key string) (string, error)
	Remove(key string) error
	Set(key string, value string, expire int64) error
}

Store is the common interface for datastores.

func Build

func Build(dsn string) (Store, error)

Build creates a new storage based on the provided DSN

func NewRedisStore

func NewRedisStore(client *redis.Client, prefix string) (Store, error)

NewRedisStore returns an instance of redis store.

func NewRedisStoreWithOptions

func NewRedisStoreWithOptions(client *redis.Client, options Options) (Store, error)

NewRedisStoreWithOptions returns an instance of redis store with custom options.

Jump to

Keyboard shortcuts

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