Documentation ¶
Overview ¶
Package gokv contains a simple key-value store abstraction and multiple implementations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultBoltOptions = BoltOptions{
BucketName: "default",
Path: "bolt.db",
}
DefaultBoltOptions is a BoltOptions object with default values. BucketName: "default", Path: "bolt.db"
var DefaultRedisOptions = RedisOptions{
Address: "localhost:6379",
}
DefaultRedisOptions is a RedisOptions object with default values. Address: "localhost:6379", Password: "", DB: 0
Functions ¶
This section is empty.
Types ¶
type BoltClient ¶
type BoltClient struct {
// contains filtered or unexported fields
}
BoltClient is a gokv.Store implementation for bbolt (formerly known as Bolt / Bolt DB).
func NewBoltClient ¶
func NewBoltClient(boltOptions BoltOptions) (BoltClient, error)
NewBoltClient creates a new BoltClient. Note: Bolt uses an exclusive write lock on the database file so it cannot be shared by multiple processes. So when creating multiple Bolt clients you should always use a new database file (by setting a different Path in the BoltOptions).
Don't worry about closing the Bolt DB as long as you don't need to close the DB while the process that opened it runs.
func (BoltClient) Get ¶
func (c BoltClient) Get(k string, v interface{}) (bool, error)
Get retrieves the stored object for the given key and populates the fields of the object that v points to with the values of the retrieved object's values.
func (BoltClient) Set ¶
func (c BoltClient) Set(k string, v interface{}) error
Set stores the given object for the given key.
type BoltOptions ¶
type BoltOptions struct { // Bucket name for storing the key-value pairs. // Optional ("default" by default). BucketName string // Path of the DB file. // Optional ("bolt.db" by default). Path string }
BoltOptions are the options for the BoltClient.
type GoMap ¶
type GoMap struct {
// contains filtered or unexported fields
}
GoMap is a gokv.Store implementation for a simple Go sync.Map.
type RedisClient ¶
type RedisClient struct {
// contains filtered or unexported fields
}
RedisClient is a gokv.Store implementation for Redis.
func NewRedisClient ¶
func NewRedisClient(redisOptions RedisOptions) RedisClient
NewRedisClient creates a new RedisClient.
func (RedisClient) Get ¶
func (c RedisClient) Get(k string, v interface{}) (bool, error)
Get retrieves the object for the given key and points the passed pointer to it.
func (RedisClient) Set ¶
func (c RedisClient) Set(k string, v interface{}) error
Set stores the given object for the given key.
type RedisOptions ¶
type RedisOptions struct { // Address of the Redis server, including the port. // Optional ("localhost:6379" by default). Address string // Password for the Redis server. // Optional ("" by default). Password string // DB to use. // Optional (0 by default). DB int }
RedisOptions are the options for the Redis DB.
type Store ¶
type Store interface { // Set stores the given value for the given key. // The implementation automatically marshalls the value if required. // The marshalling target depends on the implementation. It can be JSON, gob etc. // Implementations should offer a configuration for this. Set(string, interface{}) error // Get retrieves the value for the given key. // The implementation automatically unmarshalls the value if required. // The unmarshalling source depends on the implementation. It can be JSON, gob etc. // The automatic unmarshalling requires a pointer to a proper type being passed as parameter. // The Get method will populate the fields of the object that the passed pointer // points to with the values of the retrieved object's values. // If no object is found it returns (false, nil). Get(string, interface{}) (bool, error) }
Store is an abstraction for different key-value store implementations. A store must be able to store and retrieve key-value pairs, with the key being a string and the value being any Go interface{}.