kvs

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2015 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const NanosecondsPerMillisecond = 1000000

NanosecondsPerMillisecond is used to convert between ns and ms.

View Source
const TTLNever time.Duration = -1

TTLNever means do not expire a key

Variables

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

ErrNotFound is returned when an entry is not found in memory database.

Functions

func Hash

func Hash(s string) string

Hash returns the hash value of a string. The returned value is useful as a key.

Types

type KeyValueStore

type KeyValueStore interface {
	Set(key, value string, ttl time.Duration) error
	Get(key string) (string, error)
	Del(key string) error
	FlushDB() error
}

KeyValueStore represents simple key value storage.

func NewDefaultMemoryStore

func NewDefaultMemoryStore() KeyValueStore

NewDefaultMemoryStore creates an instance of MemoryKeyValueStore with default settings.

func NewDefaultRedisStore

func NewDefaultRedisStore() (KeyValueStore, error)

NewDefaultRedisStore instantiates Redis.

type MemoryKeyValueStore

type MemoryKeyValueStore struct {
	Cache *gocache.Cache
	// contains filtered or unexported fields
}

MemoryKeyValueStore is an in-memory cache implementation of KeyValueStore.

func NewMemoryKeyValueStore

func NewMemoryKeyValueStore(cleanupInterval time.Duration) *MemoryKeyValueStore

NewMemoryKeyValueStore creates an instance of MemoryKeyValueStore with given backing.

func (*MemoryKeyValueStore) Del

func (store *MemoryKeyValueStore) Del(key string) error

Del deletes value given key.

func (*MemoryKeyValueStore) FlushDB

func (store *MemoryKeyValueStore) FlushDB() error

FlushDB clears all keys

func (*MemoryKeyValueStore) Get

func (store *MemoryKeyValueStore) Get(key string) (string, error)

Get retrieves a value given key.

func (*MemoryKeyValueStore) Set

func (store *MemoryKeyValueStore) Set(key, value string, ttl time.Duration) error

Set sets a key with time-to-live.

type RedisStore

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

RedisStore is a concrete implementation of KeyValueStore for Redis.

func NewRedisStore

func NewRedisStore(ns string, host string, password string) (*RedisStore, error)

NewRedisStore creates a new instance of RedisTokenStore.

func (*RedisStore) Del

func (rs *RedisStore) Del(key string) error

Del deletes a key

func (*RedisStore) FlushDB

func (rs *RedisStore) FlushDB() error

FlushDB removes all keys.

func (*RedisStore) Get

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

Get gets

func (*RedisStore) Set

func (rs *RedisStore) Set(key, value string, ttl time.Duration) error

Set sets a key's value with TTL. Use cache.TTLNever to never expire.

Jump to

Keyboard shortcuts

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