aredis

package module
v0.0.0-...-6811b4b Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2016 License: MIT Imports: 4 Imported by: 0

README

Aredis Build Status Coverage Status

Aredis is a wrapper around https://github.com/garyburd/redigo for apihook apis.

Docs

Docs are available at: http://godoc.org/github.com/apihooks/aredis.

Tests

Test need a working Redis connection. Using following command to run the tests:

go test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Name is the identifier of worker using this library. This is used to
	// prefix keys along with Version in Redis.
	Name    string
	Version string

	// Seperator is a string that seperates Name, Version and the key.
	Seperator string
	// contains filtered or unexported fields
}

Client is a client for this library. Use New() to initalize it.

func New

func New(url string, c *Config) (*Client, error)

New initializeds new Client along with Redis connection pool.

func (*Client) Close

func (c *Client) Close() error

Close closes Redis connection.

func (*Client) Do

func (c *Client) Do(cmd, key string, rest ...interface{}) (interface{}, error)

Do is the primary method for interacting with Redis. It runs the given cmd in a redis conn from the pool and closes it when done.

It also prefixes all keys with name and version passed in Config when initializing.

func (*Client) GetConn

func (c *Client) GetConn() redis.Conn

GetConn returns a single redigo Redis connection. Be sure to close the connection when finished.

func (*Client) GetObject

func (c *Client) GetObject(origin, key string, o interface{}) error

GetObject gets marshalled object for origin and key. key: <worker>:<version>:<origin>:<key>

func (*Client) GetPool

func (c *Client) GetPool() *redis.Pool

GetPool returns the redigo Redis connection pool.

func (*Client) GetSettings

func (c *Client) GetSettings(origin string, s interface{}) error

GetSettings gets settings for origin. key: <worker>:<version>:<origin>:settings

func (*Client) IsErrNil

func (c *Client) IsErrNil(err error) bool

IsErrNil returns true if err is key doesn't exist in Redis.

func (*Client) Prefix

func (c *Client) Prefix(key string) string

Prefix prefixes given key with name and version passed in Config when initializing.

func (*Client) SaveObject

func (c *Client) SaveObject(origin, key string, o interface{}) error

SaveObject saves object as json string for origin and key. It uses string instead of bytes for ease of debugging.

key: <worker>:<version>:<origin>:<key>

func (*Client) SaveSettings

func (c *Client) SaveSettings(origin string, s interface{}) error

SaveSettings saves given settings for origin. key: <worker>:<version>:<origin>:settings

func (*Client) WithOrigin

func (c *Client) WithOrigin(origin, key string) string

WithOrigin prefixes origin to key to indicate key belongs to that origin.

type Config

type Config struct {
	// Name is identifier of app using this library. This is used as prefix in
	// keys.
	Name string

	// Version is version of app using this library. This is used as prefix in
	// keys.
	Version string

	// MaxIdle is redigo/redis setting.
	MaxIdle int

	// MaxActive is redigo/redis setting.
	MaxActive int

	// IdleTimeout is redigo/redis setting.
	IdleTimeout time.Duration
}

Config is the user definable options.

func NewDefaultConfig

func NewDefaultConfig(name, version string) *Config

NewDefaultConfig returns *Config with sane defaults for redigo/redis.

Jump to

Keyboard shortcuts

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