redis

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

ErrNil indicates that a reply value is nil.

View Source
var (
	ErrNoReply = errors.New("redis: no reply in result set")
)

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 ByteSlices

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

ByteSlices is a helper that converts an array command reply to a [][]byte. If err is not equal to nil, then ByteSlices returns nil, err. Nil array items are stay nil. ByteSlices returns an error if an array item is not a bulk string or nil.

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 Int64Map

func Int64Map(result interface{}, err error) (map[string]int64, error)

Int64Map is a helper that converts an array of strings (alternating key, value) into a map[string]int64. The HGETALL commands return replies in this format. Requires an even number of values in result.

func Int64s

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

Int64s is a helper that converts an array command reply to a []int64. If err is not equal to nil, then Int64s returns nil, err.

func IntMap

func IntMap(result interface{}, err error) (map[string]int, error)

IntMap is a helper that converts an array of strings (alternating key, value) into a map[string]int. The HGETALL commands return replies in this format. Requires an even number of values in result.

func Ints

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

Ints is a helper that converts an array command reply to a []int. If err is not equal to nil, then Ints returns nil, err.

func MultiBulk deprecated

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

MultiBulk is a helper that converts an array command reply to a []interface{}.

Deprecated: Use Values instead.

func NewPool

func NewPool(c *Config, options ...redis.DialOption) *redis.Pool

func Scan

func Scan(src []interface{}, dest ...interface{}) ([]interface{}, error)

Scan copies from src to the values pointed at by dest.

The values pointed at by dest must be an integer, float, boolean, string, []byte, interface{} or slices of these types. Scan uses the standard strconv package to convert bulk strings to numeric and boolean types.

If a dest value is nil, then the corresponding src value is skipped.

If a src element is nil, then the corresponding dest value is not modified.

To enable easy use of Scan in a loop, Scan returns the slice of src following the copied values.

func ScanSlice

func ScanSlice(src []interface{}, dest interface{}, fieldNames ...string) error

ScanSlice scans src to the slice pointed to by dest. The elements the dest slice must be integer, float, boolean, string, struct or pointer to struct values.

Struct fields must be integer, float, boolean or string values. All struct fields are used unless a subset is specified using fieldNames.

func ScanStruct

func ScanStruct(src []interface{}, dest interface{}) error

ScanStruct scans alternating names and values from src to a struct. The HGETALL and CONFIG GET commands return replies in this format.

ScanStruct uses exported field names to match values in the response. Use 'redis' field tag to override the name:

Field int `redis:"myName"`

Fields with the tag redis:"-" are ignored.

Integer, float, boolean, string and []byte fields are supported. Scan uses the standard strconv package to convert bulk string values to numeric and boolean types.

If a src element is nil, then the corresponding field is not modified.

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 StringMap

func StringMap(result interface{}, err error) (map[string]string, error)

StringMap is a helper that converts an array of strings (alternating key, value) into a map[string]string. The HGETALL and CONFIG GET commands return replies in this format. Requires an even number of values in result.

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. Nil array items are converted to "" in the output slice. Strings returns an error if an array item is not a bulk string or nil.

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 Args

type Args []interface{}

Args is a helper for constructing command arguments from structured values.

func (Args) Add

func (args Args) Add(value ...interface{}) Args

Add returns the result of appending value to args.

func (Args) AddFlat

func (args Args) AddFlat(v interface{}) Args

AddFlat returns the result of appending the flattened value of v to args.

Maps are flattened by appending the alternating keys and map values to args.

Slices are flattened by appending the slice elements to args.

Structs are flattened by appending the alternating names and values of exported fields to args. If v is a nil struct pointer, then nothing is appended. The 'redis' field tag overrides struct field names. See ScanStruct for more information on the use of the 'redis' field tag.

Other types are appended to args as is.

type Config

type Config struct {
	Active      int
	Idle        int
	IdleTimeout time.Duration
	WaitTimeout time.Duration
	Wait        bool

	Name         string
	Addr         string
	Auth         string
	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	SlowLog      time.Duration
}

Config client settings.

type Pipeliner

type Pipeliner interface {
	// Send writes the command to the client's output buffer.
	Send(commandName string, args ...interface{})

	// Exec executes all commands and get replies.
	Exec(ctx context.Context) (rs *Replies, err error)
}

type Redis

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

func NewRedis

func NewRedis(c *Config, options ...redis.DialOption) *Redis

func (*Redis) Close

func (r *Redis) Close() error

Close closes connection pool

func (*Redis) Conn

func (r *Redis) Conn(ctx context.Context) redis.Conn

Conn direct gets a connection

func (*Redis) Do

func (r *Redis) Do(ctx context.Context, commandName string, args ...interface{}) (reply interface{}, err error)

Do gets a new conn from pool, then execute Do with this conn, finally close this conn. ATTENTION: Don't use this method with transaction command like MULTI etc. Because every Do will close conn automatically, use r.Conn to get a raw conn for this situation.

func (*Redis) Pipeline

func (r *Redis) Pipeline() (p Pipeliner)

type Replies

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

func (*Replies) Next

func (rs *Replies) Next() bool

func (*Replies) Scan

func (rs *Replies) Scan() (reply interface{}, err error)

Jump to

Keyboard shortcuts

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