ledis

package
v0.0.0-...-fbc11cf Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2014 License: MIT, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package ledis is a client for the ledisdb.

Config

Config struct contains configuration for ledisdb:

Addr            ledisdb server address, like 127.0.0.1:6380
MaxIdleConns    max idle connections for ledisdb

Client

The client is the primary interface for ledisdb. You must first create a client with proper config for working.

cfg := new(Config)
cfg.Addr = "127.0.0.1:6380"
cfg.MaxIdleConns = 4

c := NewClient(cfg)

The most important function for client is Do function to send commands to remote server.

reply, err := c.Do("ping")

reply, err := c.Do("set", "key", "value")

reply, err := c.Do("get", "key")

Connection

You can use an independent connection to send commands.

//get a connection
conn := c.Get()

//connection send command
conn.Do("ping")

Reply Helper

You can use reply helper to convert a reply to a specific type.

exists, err := ledis.Bool(c.Do("exists", "key"))

score, err := ledis.Int64(c.Do("zscore", "key", "member"))

Index

Constants

This section is empty.

Variables

View Source
var ErrNil = errors.New("ledis: nil returned")

ErrNil indicates that a reply value is nil.

Functions

func Bool

func Bool(reply interface{}, err error) (bool, error)

Bool is a helper that converts a command reply to a boolean. If err is not equal to nil, then Bool returns false, err. Otherwise Bool converts the reply to boolean as follows:

Reply type      Result
integer         value != 0, nil
bulk string     strconv.ParseBool(reply)
nil             false, ErrNil
other           false, error

func Bytes

func Bytes(reply interface{}, err error) ([]byte, error)

Bytes is a helper that converts a command reply to a slice of bytes. If err is not equal to nil, then Bytes returns nil, err. Otherwise Bytes converts the reply to a slice of bytes as follows:

Reply type      Result
bulk string     reply, nil
simple string   []byte(reply), nil
nil             nil, ErrNil
other           nil, error

func Float64

func Float64(reply interface{}, err error) (float64, error)

Float64 is a helper that converts a command reply to 64 bit float. If err is not equal to nil, then Float64 returns 0, err. Otherwise, Float64 converts the reply to an int as follows:

Reply type    Result
bulk string   parsed reply, nil
nil           0, ErrNil
other         0, error

func Int

func Int(reply interface{}, err error) (int, error)

Int is a helper that converts a command reply to an integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int converts the reply to an int as follows:

Reply type    Result
integer       int(reply), nil
bulk string   parsed reply, nil
nil           0, ErrNil
other         0, error

func Int64

func Int64(reply interface{}, err error) (int64, error)

Int64 is a helper that converts a command reply to 64 bit integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int64 converts the reply to an int64 as follows:

Reply type    Result
integer       reply, nil
bulk string   parsed reply, nil
nil           0, ErrNil
other         0, error

func MultiBulk

func MultiBulk(reply interface{}, err error) ([]interface{}, error)

MultiBulk is deprecated. Use Values.

func String

func String(reply interface{}, err error) (string, error)

String is a helper that converts a command reply to a string. If err is not equal to nil, then String returns "", err. Otherwise String converts the reply to a string as follows:

Reply type      Result
bulk string     string(reply), nil
simple string   reply, nil
nil             "",  ErrNil
other           "",  error

func Strings

func Strings(reply interface{}, err error) ([]string, error)

Strings is a helper that converts an array command reply to a []string. If err is not equal to nil, then Strings returns nil, err. If one of the array items is not a bulk string or nil, then Strings returns an error.

func Uint64

func Uint64(reply interface{}, err error) (uint64, error)

Uint64 is a helper that converts a command reply to 64 bit integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int64 converts the reply to an int64 as follows:

Reply type    Result
integer       reply, nil
bulk string   parsed reply, nil
nil           0, ErrNil
other         0, error

func Values

func Values(reply interface{}, err error) ([]interface{}, error)

Values is a helper that converts an array command reply to a []interface{}. If err is not equal to nil, then Values returns nil, err. Otherwise, Values converts the reply as follows:

Reply type      Result
array           reply, nil
nil             nil, ErrNil
other           nil, error

Types

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg *Config) *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) Do

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

func (*Client) Get

func (c *Client) Get() *Conn

type Config

type Config struct {
	Addr         string
	MaxIdleConns int
}

type Conn

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

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) Do

func (c *Conn) Do(cmd string, args ...interface{}) (interface{}, error)

type Error

type Error string

Error represents an error returned in a command reply.

func (Error) Error

func (err Error) Error() string

Jump to

Keyboard shortcuts

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