gokvstores

package module
v0.0.0-...-63253df Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2016 License: MIT Imports: 6 Imported by: 0

README

kvstores
========

kvstores is a collection of custom key/value storage backends for Go.

Currently, it supports the following backends:

* Redis
* An in-memory LRU cache

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DummyStore

type DummyStore struct{}

DummyStore is a noop store (caching disabled).

func (DummyStore) AppendSlice

func (s DummyStore) AppendSlice(key string, values ...interface{}) error

AppendSlice appends values to an existing slice. If key does not exist, creates slice.

func (DummyStore) Close

func (s DummyStore) Close() error

Close closes the connection to the store.

func (DummyStore) Delete

func (s DummyStore) Delete(key string) error

Delete deletes the given key.

func (DummyStore) Exists

func (s DummyStore) Exists(key string) (bool, error)

Exists checks if the given key exists.

func (DummyStore) Flush

func (s DummyStore) Flush() error

Flush flushes the store.

func (DummyStore) Get

func (s DummyStore) Get(key string) (interface{}, error)

Get returns value for the given key.

func (DummyStore) GetMap

func (s DummyStore) GetMap(key string) (map[string]interface{}, error)

GetMap returns map for the given key.

func (DummyStore) GetSlice

func (s DummyStore) GetSlice(key string) ([]interface{}, error)

GetSlice returns slice for the given key.

func (DummyStore) Set

func (s DummyStore) Set(key string, value interface{}) error

Set sets value for the given key.

func (DummyStore) SetMap

func (s DummyStore) SetMap(key string, value map[string]interface{}) error

SetMap sets map for the given key.

func (DummyStore) SetSlice

func (s DummyStore) SetSlice(key string, value []interface{}) error

SetSlice sets slice for the given key.

type KVStore

type KVStore interface {
	// Get returns value for the given key.
	Get(key string) (interface{}, error)

	// Set sets value for the given key.
	Set(key string, value interface{}) error

	// GetMap returns map for the given key.
	GetMap(key string) (map[string]interface{}, error)

	// SetMap sets map for the given key.
	SetMap(key string, value map[string]interface{}) error

	// GetSlice returns slice for the given key.
	GetSlice(key string) ([]interface{}, error)

	// SetSlice sets slice for the given key.
	SetSlice(key string, value []interface{}) error

	// AppendSlice appends values to an existing slice.
	// If key does not exist, creates slice.
	AppendSlice(key string, values ...interface{}) error

	// Exists checks if the given key exists.
	Exists(key string) (bool, error)

	// Delete deletes the given key.
	Delete(key string) error

	// Flush flushes the store.
	Flush() error

	// Close closes the connection to the store.
	Close() error
}

KVStore is the KV store interface.

func NewMemoryStore

func NewMemoryStore(expiration time.Duration, cleanupInterval time.Duration) (KVStore, error)

NewMemoryStore returns in-memory KVStore.

func NewRedisClientStore

func NewRedisClientStore(options *RedisClientOptions, expiration time.Duration) (KVStore, error)

NewRedisClientStore returns Redis client instance of KVStore.

func NewRedisClusterStore

func NewRedisClusterStore(options *RedisClusterOptions, expiration time.Duration) (KVStore, error)

NewRedisClusterStore returns Redis cluster client instance of KVStore.

type MemoryStore

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

MemoryStore is the in-memory implementation of KVStore.

func (*MemoryStore) AppendSlice

func (c *MemoryStore) AppendSlice(key string, values ...interface{}) error

AppendSlice appends values to the given slice.

func (*MemoryStore) Close

func (c *MemoryStore) Close() error

Close does nothing for this backend.

func (*MemoryStore) Delete

func (c *MemoryStore) Delete(key string) error

Delete deletes the given key.

func (*MemoryStore) Exists

func (c *MemoryStore) Exists(key string) (bool, error)

Exists checks if the given key exists.

func (*MemoryStore) Flush

func (c *MemoryStore) Flush() error

Flush removes all items from the cache.

func (*MemoryStore) Get

func (c *MemoryStore) Get(key string) (interface{}, error)

Get returns item from the cache.

func (*MemoryStore) GetMap

func (c *MemoryStore) GetMap(key string) (map[string]interface{}, error)

GetMap returns map for the given key.

func (*MemoryStore) GetSlice

func (c *MemoryStore) GetSlice(key string) ([]interface{}, error)

GetSlice returns slice for the given key.

func (*MemoryStore) Set

func (c *MemoryStore) Set(key string, value interface{}) error

Set sets value in the cache.

func (*MemoryStore) SetMap

func (c *MemoryStore) SetMap(key string, value map[string]interface{}) error

SetMap sets a map for the given key.

func (*MemoryStore) SetSlice

func (c *MemoryStore) SetSlice(key string, value []interface{}) error

SetSlice sets slice for the given key.

type RedisClient

type RedisClient interface {
	Ping() *redis.StatusCmd
	Exists(key string) *redis.BoolCmd
	Del(keys ...string) *redis.IntCmd
	FlushDb() *redis.StatusCmd
	Close() error
	Process(cmd redis.Cmder) error
	Get(key string) *redis.StringCmd
	Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
	HGetAll(key string) *redis.StringStringMapCmd
	HMSet(key string, fields map[string]string) *redis.StatusCmd
	SMembers(key string) *redis.StringSliceCmd
	SAdd(key string, members ...interface{}) *redis.IntCmd
}

RedisClient is an interface thats allows to use Redis cluster or a redis single client seamlessly.

type RedisClientOptions

type RedisClientOptions struct {
	Network            string
	Addr               string
	Dialer             func() (net.Conn, error)
	Password           string
	DB                 int
	MaxRetries         int
	DialTimeout        time.Duration
	ReadTimeout        time.Duration
	WriteTimeout       time.Duration
	PoolSize           int
	PoolTimeout        time.Duration
	IdleTimeout        time.Duration
	IdleCheckFrequency time.Duration
	ReadOnly           bool
}

RedisClientOptions are Redis client options.

type RedisClusterOptions

type RedisClusterOptions struct {
	Addrs              []string
	MaxRedirects       int
	ReadOnly           bool
	RouteByLatency     bool
	Password           string
	DialTimeout        time.Duration
	ReadTimeout        time.Duration
	WriteTimeout       time.Duration
	PoolSize           int
	PoolTimeout        time.Duration
	IdleTimeout        time.Duration
	IdleCheckFrequency time.Duration
}

RedisClusterOptions are Redis cluster options.

type RedisStore

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

RedisStore is the Redis implementation of KVStore.

func (*RedisStore) AppendSlice

func (r *RedisStore) AppendSlice(key string, values ...interface{}) error

AppendSlice appends values to the given slice.

func (*RedisStore) Close

func (r *RedisStore) Close() error

Close closes the client connection.

func (*RedisStore) Delete

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

Delete deletes key.

func (*RedisStore) Exists

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

Exists checks key existence.

func (*RedisStore) Flush

func (r *RedisStore) Flush() error

Flush flushes the current database.

func (*RedisStore) Get

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

Get returns value for the given key.

func (*RedisStore) GetMap

func (r *RedisStore) GetMap(key string) (map[string]interface{}, error)

GetMap returns map for the given key.

func (*RedisStore) GetSlice

func (r *RedisStore) GetSlice(key string) ([]interface{}, error)

GetSlice returns slice for the given key.

func (*RedisStore) Set

func (r *RedisStore) Set(key string, value interface{}) error

Set sets the value for the given key.

func (*RedisStore) SetMap

func (r *RedisStore) SetMap(key string, values map[string]interface{}) error

SetMap sets map for the given key.

func (*RedisStore) SetSlice

func (r *RedisStore) SetSlice(key string, values []interface{}) error

SetSlice sets map for the given key.

Jump to

Keyboard shortcuts

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