gokvstores

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: MIT Imports: 8 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 (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 (DummyStore) Close() error

Close closes the connection to the store.

func (DummyStore) Delete

func (DummyStore) Delete(key string) error

Delete deletes the given key.

func (DummyStore) DeleteMap

func (DummyStore) DeleteMap(key string, fields ...string) error

DeleteMap removes the specified fields from the map stored at key.

func (DummyStore) Exists

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

Exists checks if the given key exists.

func (DummyStore) Flush

func (DummyStore) Flush() error

Flush flushes the store.

func (DummyStore) Get

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

Get returns value for the given key.

func (DummyStore) GetMap

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

GetMap returns map for the given key.

func (DummyStore) GetMaps

func (DummyStore) GetMaps(keys []string) (map[string]map[string]interface{}, error)

GetMaps returns maps for the given keys.

func (DummyStore) GetSlice

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

GetSlice returns slice for the given key.

func (DummyStore) Keys

func (DummyStore) Keys(pattern string) ([]interface{}, error)

Keys returns all keys matching pattern

func (DummyStore) MGet

func (DummyStore) MGet(keys []string) (map[string]interface{}, error)

MGet returns map of key, value for a list of keys.

func (DummyStore) Set

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

Set sets value for the given key.

func (DummyStore) SetMap

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

SetMap sets map for the given key.

func (DummyStore) SetMaps

func (DummyStore) SetMaps(maps map[string]map[string]interface{}) error

SetMaps sets the given maps.

func (DummyStore) SetSlice

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

SetSlice sets slice for the given key.

func (DummyStore) SetWithExpiration

func (DummyStore) SetWithExpiration(key string, value interface{}, expiration time.Duration) error

SetWithExpiration sets the value for the given key for a specified duration.

type KVStore

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

	// MGet returns map of key, value for a list of keys.
	MGet(keys []string) (map[string]interface{}, error)

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

	// SetWithExpiration sets the value for the given key for a specified duration.
	SetWithExpiration(key string, value interface{}, expiration time.Duration) error

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

	// GetMaps returns maps for the given keys.
	GetMaps(keys []string) (map[string]map[string]interface{}, error)

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

	// SetMaps sets the given maps.
	SetMaps(maps map[string]map[string]interface{}) error

	// DeleteMap removes the specified fields from the map stored at key.
	DeleteMap(key string, fields ...string) 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

	// Return all keys matching pattern
	Keys(pattern string) ([]interface{}, 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) DeleteMap

func (c *MemoryStore) DeleteMap(key string, fields ...string) error

DeleteMap removes the specified fields from the map stored at 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) GetMaps

func (c *MemoryStore) GetMaps(keys []string) (map[string]map[string]interface{}, error)

GetMaps returns maps for the given keys.

func (*MemoryStore) GetSlice

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

GetSlice returns slice for the given key.

func (*MemoryStore) Keys

func (c *MemoryStore) Keys(pattern string) ([]interface{}, error)

Keys returns all keys matching pattern

func (*MemoryStore) MGet

func (c *MemoryStore) MGet(keys []string) (map[string]interface{}, error)

MGet returns map of key, value for a list of keys.

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

func (c *MemoryStore) SetMaps(maps map[string]map[string]interface{}) error

SetMaps sets the given maps.

func (*MemoryStore) SetSlice

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

SetSlice sets slice for the given key.

func (*MemoryStore) SetWithExpiration

func (c *MemoryStore) SetWithExpiration(key string, value interface{}, expiration time.Duration) error

SetWithExpiration sets the value for the given key for a specified duration.

type RedisClient

type RedisClient interface {
	Ping(ctx context.Context) *redis.StatusCmd
	Exists(ctx context.Context, key ...string) *redis.IntCmd
	Del(ctx context.Context, keys ...string) *redis.IntCmd
	FlushDB(ctx context.Context) *redis.StatusCmd
	Close() error
	Process(ctx context.Context, cmd redis.Cmder) error
	Get(ctx context.Context, key string) *redis.StringCmd
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
	MGet(ctx context.Context, keys ...string) *redis.SliceCmd
	HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd
	HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
	HMSet(ctx context.Context, key string, values ...interface{}) *redis.BoolCmd
	SMembers(ctx context.Context, key string) *redis.StringSliceCmd
	SAdd(ctx context.Context, key string, members ...interface{}) *redis.IntCmd
	Keys(ctx context.Context, pattern string) *redis.StringSliceCmd
	Pipeline() redis.Pipeliner
}

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(ctx context.Context, network, addr string) (net.Conn, error)
	Username           string
	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
	UseTLS             bool
}

RedisClientOptions are Redis client options.

type RedisClusterOptions

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

RedisClusterOptions are Redis cluster options.

type RedisPipeline

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

RedisPipeline is a struct which contains an opend redis pipeline transaction

func (RedisPipeline) Close

func (r RedisPipeline) Close() error

Close implements RedisClient Close for pipeline

func (RedisPipeline) Del

func (r RedisPipeline) Del(ctx context.Context, keys ...string) *redis.IntCmd

Del implements RedisClient Del for pipeline

func (RedisPipeline) Exists

func (r RedisPipeline) Exists(ctx context.Context, key ...string) *redis.IntCmd

Exists implements RedisClient Exists for pipeline

func (RedisPipeline) FlushDB

func (r RedisPipeline) FlushDB(ctx context.Context) *redis.StatusCmd

FlushDb implements RedisClient FlushDb for pipeline

func (RedisPipeline) Get

Get implements RedisClient Get for pipeline

func (RedisPipeline) HDel

func (r RedisPipeline) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd

HDel implements RedisClient HDel for pipeline

func (RedisPipeline) HGetAll

HGetAll implements RedisClient HGetAll for pipeline

func (RedisPipeline) HMSet

func (r RedisPipeline) HMSet(ctx context.Context, key string, values ...interface{}) *redis.BoolCmd

HMSet implements RedisClient HMSet for pipeline

func (RedisPipeline) Keys

func (r RedisPipeline) Keys(ctx context.Context, pattern string) *redis.StringSliceCmd

Keys implements RedisClient Keys for pipeline

func (RedisPipeline) MGet

func (r RedisPipeline) MGet(ctx context.Context, keys ...string) *redis.SliceCmd

MGet implements RedisClient MGet for pipeline

func (RedisPipeline) Ping

Ping implements RedisClient Ping for pipeline

func (RedisPipeline) Pipeline

func (r RedisPipeline) Pipeline() redis.Pipeliner

Pipeline returns Redis pipeline

func (RedisPipeline) Process

func (r RedisPipeline) Process(ctx context.Context, cmd redis.Cmder) error

Process implements RedisClient Process for pipeline

func (RedisPipeline) SAdd

func (r RedisPipeline) SAdd(ctx context.Context, key string, members ...interface{}) *redis.IntCmd

SAdd implements RedisClient SAdd for pipeline

func (RedisPipeline) SMembers

func (r RedisPipeline) SMembers(ctx context.Context, key string) *redis.StringSliceCmd

SMembers implements RedisClient SMembers for pipeline

func (RedisPipeline) Set

func (r RedisPipeline) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd

Set implements RedisClient Set for pipeline

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

func (r *RedisStore) DeleteMap(key string, fields ...string) error

DeleteMap removes the specified fields from the map stored at 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) GetMaps

func (r *RedisStore) GetMaps(keys []string) (map[string]map[string]interface{}, error)

GetMaps returns maps for the given keys.

func (*RedisStore) GetSlice

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

GetSlice returns slice for the given key.

func (*RedisStore) Keys

func (r *RedisStore) Keys(pattern string) ([]interface{}, error)

Keys returns all keys matching pattern.

func (*RedisStore) MGet

func (r *RedisStore) MGet(keys []string) (map[string]interface{}, error)

MGet returns map of key, value for a list of keys.

func (*RedisStore) Pipeline

func (r *RedisStore) Pipeline(f func(r *RedisStore) error) ([]redis.Cmder, error)

Pipeline uses pipeline as a Redis client to execute multiple calls at once

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

func (r *RedisStore) SetMaps(maps map[string]map[string]interface{}) error

SetMaps sets the given maps.

func (*RedisStore) SetSlice

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

SetSlice sets map for the given key.

func (*RedisStore) SetWithExpiration

func (r *RedisStore) SetWithExpiration(key string, value interface{}, expiration time.Duration) error

SetWithExpiration sets the value for the given key.

Jump to

Keyboard shortcuts

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