radixutil

package
v0.0.0-...-4553cd5 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package radixutil is used for retrieving redis connections, and has helper methods for interacting with the data held within redis. Use this package with https://github.com/mediocregopher/radix.v2

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is used when reading from socket

Variables

View Source
var (
	// Conf global DB configs
	Conf *ConfigMeta
	// Inst is an instance of DBer which is automatically initialized and which is
	// what should be used by the rest of okq
	Inst DBer
)
View Source
var Debug bool

Debug If true turns on debug logging and agg support (see https://github.com/grooveshark/golib)

Functions

func BuildAllInfoMap

func BuildAllInfoMap(infostring string) map[string]map[string]string

BuildAllInfoMap will call `INFO ALL` and return a mapping of map[string]string for each section in the output

func BuildMapFromInfoString

func BuildMapFromInfoString(input string) map[string]string

BuildMapFromInfoString will take the string from a Redis info call and return a map[string]string

func InitDB

func InitDB(config *ConfigMeta)

InitDB init DB with configs, if config is nil, then default configs will be used.

Types

type Client

type Client struct {

	// Timeout to use for reads/writes to redis. This defaults to DefaultTimeout,
	// but can be overwritten immediately after NewClient is called
	Timeout time.Duration
	// contains filtered or unexported fields
}

Client is a client for the redis. It can talk to a pool of redis instances and failover from one to the other if one loses connectivity

func New

func New(addr ...string) *Client

New return a *Client for Cmd

func (*Client) Cmd

func (c *Client) Cmd(cmd string, args ...interface{}) *redis.Resp

Cmd do the redis cmd directly

type ConfigMeta

type ConfigMeta struct {
	// RedisAddr Address redis is listening on
	RedisAddr string `json:"redis_addr"`
	// RedisSentinels A sentinel address to connect to through to the client - overrides other options
	RedisSentinels []string `json:"redis_sentinel_addr"`
	// RedisSentinelGroup A redis sentinel group name for selecting which redis masters to connect
	RedisSentinelGroup string `json:"redis_sentinel_group"`
	// RedisCluster Whether or not to treat the redis address as a node in a larger cluster
	RedisCluster bool `json:"redis_cluster"`
	// RedisSentinel Whether or not to redis sentinel mode
	RedisSentinel bool `json:"redis_sentinel"`
}

ConfigMeta contains DB configs

type DBer

type DBer interface {

	// Cmd is a function which will perform the given cmd/args in redis and
	// returns the resp. It automatically handles using redis cluster, if that
	// is enabled
	Cmd(string, ...interface{}) *redis.Resp

	// Pipe runs a set of commands (given by p) one after the other. It is *not*
	// guaranteed that all the commands will be run on the same client. If any
	// commands return an error the pipeline will stop and return that error.
	// Otherwise the Resp from each command is returned in a slice
	//
	//	r, err := db.Pipe(
	//		db.PP("SET", "foo", "bar"),
	//		db.PP("GET", "foo"),
	//	)
	Pipe(...*PipePart) ([]*redis.Resp, error)

	// Scan is a function which returns a channel to which keys matching the
	// given pattern are written to. The channel must be read from until it is
	// closed, which occurs when there are no more keys or when an error has
	// occurred (this error will be logged)
	//
	// This should not be used in any critical paths
	Scan(string) <-chan string

	// GetAddr returns any valid address of a redis instance. Useful for cases
	// where we want to create redis connections external to this db package
	GetAddr() (string, error)
}

DBer is implemented and used by the rest of okq to interact with whatever backend has been chosen

type PipePart

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

PipePart is a single command to be run in a pipe. See Pipe for an example on usage

func PP

func PP(cmd string, args ...interface{}) *PipePart

PP should be called NewPipePart, but that's pretty verbose. It simple returns a new PipePart, to be used in a call to Pipe

Jump to

Keyboard shortcuts

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