utilgo: github.com/upyun/utilgo/radixutil Index | Files

package radixutil

import "github.com/upyun/utilgo/radixutil"

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

Package Files

client.go db.go db_cluster.go db_normal.go db_sentinel.go doc.go info.go

Constants

const DefaultTimeout = 30 * time.Second

DefaultTimeout is used when reading from socket

Variables

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
)
var Debug bool

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

func BuildAllInfoMap Uses

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 Uses

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 Uses

func InitDB(config *ConfigMeta)

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

type Client Uses

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 Uses

func New(addr ...string) *Client

New return a *Client for Cmd

func (*Client) Cmd Uses

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

Cmd do the redis cmd directly

type ConfigMeta Uses

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 Uses

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 Uses

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 Uses

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

Package radixutil imports 9 packages (graph). Updated 2016-08-21. Refresh now. Tools for package owners.