redis

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Address:   "localhost:6379",
	Codec:     encoding.JSON,
	KeyPrefix: "gokv",
}

DefaultOptions is an Options object with default values. Address: "localhost:6379", Password: "", DB: 0, Codec: encoding.JSON

Functions

func DefaultKeyFunc

func DefaultKeyFunc(prefix, s string) string

DefaultKeyFunc is the default implementation of cache keys All it does is to preprend "gokv:" to the key sent in by client code

Types

type KeyFunc

type KeyFunc func(prefix, s string) string

KeyFunc defines a transformer for cache keys

type Options

type Options 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
	// Encoding format.
	// Optional (encoding.JSON by default).
	Codec encoding.Codec
	// key fn
	KeyFn KeyFunc
	// key prefix
	KeyPrefix string
}

Options are the options for the Redis client.

type Store

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

Store is a io.Store implementation for Redis.

func New

func New(options Options) *Store

NewClient creates a new Redis client.

You must call the Close() method on the client when you're done working with it.

func (*Store) Close

func (c *Store) Close() error

Close closes the client. It must be called to release any open resources.

func (*Store) Delete

func (c *Store) Delete(k string) error

Delete deletes the stored value for the given key. Deleting a non-existing key-value pair does NOT lead to an error. The key must not be "".

func (*Store) Get

func (c *Store) Get(k string, v interface{}) (found bool, err error)

Get retrieves the stored value for the given key. You need to pass a pointer to the value, so in case of a struct the automatic unmarshalling can populate the fields of the object that v points to with the values of the retrieved object's values. If no value is found it returns (false, nil). The key must not be "" and the pointer must not be nil.

func (*Store) Has

func (c *Store) Has(k string) bool

Has judge store has a key for k

func (*Store) Set

func (c *Store) Set(k string, v interface{}) error

Set stores the given value for the given key. Values are automatically marshalled to JSON or gob (depending on the configuration). The key must not be "" and the value must not be nil.

func (*Store) SetEx

func (c *Store) SetEx(k string, v interface{}, expires time.Duration) error

SetEx store the give value for the given key and the key expire after expires.

Jump to

Keyboard shortcuts

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