gokvstores

package module
v0.0.0-...-c9af9d0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2015 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

View Source
var ErrNil = errors.New("redigo: nil returned")

Functions

func Bool

func Bool(reply interface{}) (bool, error)

Bool is a helper that converts a command reply to a boolean. If err is not equal to nil, then Bool returns false, err. Otherwise Bool converts the reply to boolean as follows:

Reply type      Result
integer         value != 0, nil
bulk string     strconv.ParseBool(reply)
nil             false, ErrNil
other           false, error

func Bytes

func Bytes(reply interface{}) ([]byte, error)

Bytes is a helper that converts a command reply to a slice of bytes. If err is not equal to nil, then Bytes returns nil, err. Otherwise Bytes converts the reply to a slice of bytes as follows:

Reply type      Result
bulk string     reply, nil
simple string   []byte(reply), nil
nil             nil, ErrNil
other           nil, error

func Float64

func Float64(reply interface{}) (float64, error)

Float64 is a helper that converts a command reply to 64 bit float. If err is not equal to nil, then Float64 returns 0, err. Otherwise, Float64 converts the reply to an int as follows:

Reply type    Result
bulk string   parsed reply, nil
nil           0, ErrNil
other         0, error

func Int

func Int(reply interface{}) (int, error)

Int is a helper that converts a command reply to an integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int converts the reply to an int as follows:

Reply type    Result
integer       int(reply), nil
bulk string   parsed reply, nil
nil           0, ErrNil
other         0, error

func Int64

func Int64(reply interface{}) (int64, error)

Int64 is a helper that converts a command reply to 64 bit integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int64 converts the reply to an int64 as follows:

Reply type    Result
integer       reply, nil
bulk string   parsed reply, nil
nil           0, ErrNil
other         0, error

func MultiBulk

func MultiBulk(reply interface{}) ([]interface{}, error)

MultiBulk is deprecated. Use Values.

func String

func String(reply interface{}) (string, error)

String is a helper that converts a command reply to a string. If err is not equal to nil, then String returns "", err. Otherwise String converts the reply to a string as follows:

Reply type      Result
bulk string     string(reply), nil
simple string   reply, nil
nil             "",  ErrNil
other           "",  error

func Strings

func Strings(reply interface{}) ([]string, error)

Strings is a helper that converts an array command reply to a []string. If err is not equal to nil, then Strings returns nil, err. If one of the array items is not a bulk string or nil, then Strings returns an error.

func Uint64

func Uint64(reply interface{}) (uint64, error)

Uint64 is a helper that converts a command reply to 64 bit integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int64 converts the reply to an int64 as follows:

Reply type    Result
integer       reply, nil
bulk string   parsed reply, nil
nil           0, ErrNil
other         0, error

func Values

func Values(reply interface{}) ([]interface{}, error)

Values is a helper that converts an array command reply to a []interface{}. If err is not equal to nil, then Values returns nil, err. Otherwise, Values converts the reply as follows:

Reply type      Result
array           reply, nil
nil             nil, ErrNil
other           nil, error

Types

type CacheKVStore

type CacheKVStore struct {
	Cache *CacheKVStoreConnection
}

func (*CacheKVStore) Close

func (c *CacheKVStore) Close() error

func (*CacheKVStore) Connection

func (c *CacheKVStore) Connection() KVStoreConnection

type CacheKVStoreConnection

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

Cache is an LRU cache, safe for concurrent access.

func NewCacheKVStoreConnection

func NewCacheKVStoreConnection(maxEntries int) *CacheKVStoreConnection

New returns a new cache with the provided maximum items.

func (*CacheKVStoreConnection) Append

func (c *CacheKVStoreConnection) Append(key string, value interface{}) error

Appends the value to the existing item which is stored under provided key evicting an old item if necessary.

func (*CacheKVStoreConnection) Close

func (c *CacheKVStoreConnection) Close() error

func (*CacheKVStoreConnection) Delete

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

func (*CacheKVStoreConnection) Exists

func (c *CacheKVStoreConnection) Exists(key string) bool

func (*CacheKVStoreConnection) Flush

func (c *CacheKVStoreConnection) Flush() error

func (*CacheKVStoreConnection) Get

func (c *CacheKVStoreConnection) Get(key string) interface{}

Get fetches the key's value from the cache. The ok result will be true if the item was found.

func (*CacheKVStoreConnection) Len

func (c *CacheKVStoreConnection) Len() int

Len returns the number of items in the cache.

func (*CacheKVStoreConnection) RemoveOldest

func (c *CacheKVStoreConnection) RemoveOldest() (key string, value interface{})

RemoveOldest removes the oldest item in the cache and returns its key and value. If the cache is empty, the empty string and nil are returned.

func (*CacheKVStoreConnection) Set

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

Add adds the provided key and value to the cache, evicting an old item if necessary.

type Error

type Error string

func (Error) Error

func (err Error) Error() string

type KVStore

type KVStore interface {
	Connection() KVStoreConnection
	Close() error
}

func NewCacheKVStore

func NewCacheKVStore(maxEntries int) KVStore

func NewRedisKVStore

func NewRedisKVStore(host string, port int, password string, db int) KVStore

type KVStoreConnection

type KVStoreConnection interface {
	Close() error
	Get(key string) interface{}
	Delete(key string) error
	Flush() error
	Exists(key string) bool
	Set(key string, value interface{}) error
	Append(key string, value interface{}) error
}

type RedisKVStore

type RedisKVStore struct {
	Pool *redis.Pool
}

func (*RedisKVStore) Close

func (k *RedisKVStore) Close() error

func (*RedisKVStore) Connection

func (k *RedisKVStore) Connection() KVStoreConnection

type RedisKVStoreConnection

type RedisKVStoreConnection struct {
	Connection redis.Conn
}

func (*RedisKVStoreConnection) Append

func (k *RedisKVStoreConnection) Append(key string, value interface{}) error

func (*RedisKVStoreConnection) Close

func (k *RedisKVStoreConnection) Close() error

func (*RedisKVStoreConnection) Delete

func (k *RedisKVStoreConnection) Delete(key string) error

func (*RedisKVStoreConnection) Exists

func (k *RedisKVStoreConnection) Exists(key string) bool

func (*RedisKVStoreConnection) Flush

func (k *RedisKVStoreConnection) Flush() error

func (*RedisKVStoreConnection) Get

func (k *RedisKVStoreConnection) Get(key string) interface{}

func (*RedisKVStoreConnection) Set

func (k *RedisKVStoreConnection) Set(key string, value interface{}) error

Jump to

Keyboard shortcuts

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