Documentation ¶
Index ¶
- func IsAuthError(err error) bool
- func IsUnknownCommand(err error) bool
- func SetupAuth(username string, password string) func(ctx context.Context, client *Client, pipe *Pipeline) error
- type Client
- type Error
- type LenReader
- type Pipeline
- func (r *Pipeline) ArrayLength() (int, error)
- func (r *Pipeline) ArrayStack() []int
- func (r *Pipeline) Bytes() ([]byte, error)
- func (r *Pipeline) Close() error
- func (r *Pipeline) Error() string
- func (r *Pipeline) HasMore() bool
- func (r *Pipeline) Int() (int, error)
- func (r *Pipeline) JSON(v interface{}) error
- func (r *Pipeline) Next() bool
- func (r *Pipeline) NextSubMessage() (*SubMessage, error)
- func (r *Pipeline) Ok() error
- func (r *Pipeline) String() (string, error)
- func (r *Pipeline) Strings() ([]string, error)
- func (r *Pipeline) WriteTo(w io.Writer) (int64, error)
- type PoolStats
- type SubMessage
- type SubMessageType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAuthError ¶
func IsUnknownCommand ¶
IsUnknownCommand returns whether err is an "unknown command" error.
func SetupAuth ¶ added in v0.7.0
func SetupAuth( username string, password string, ) func(ctx context.Context, client *Client, pipe *Pipeline) error
SetupAuth returns a Setup function that authenticates with the given username and password.
AuthUsername is the username used for authentication.
If set, AuthPassword must also be set. If not using Redis ACLs, just set AuthPassword.
See more: https://redis.io/commands/auth/ AuthPassword is the password used for authentication. Authentication must be set before any other commands are sent, and must not change during the lifetime of the client.
See more: https://redis.io/commands/auth/
Types ¶
type Client ¶
type Client struct { // ConnectionPoolSize limits the size of the connection pool. If 0, connections // are not pooled. ConnectionPoolSize int // IdleTimeout is the amount of time after which an idle connection will // be closed. IdleTimeout time.Duration // Dial is the function used to create new connections. Dial func(ctx context.Context) (net.Conn, error) // Setup is called after a new connection is established, but before any // commands are sent. It is useful for selecting a database or authenticating. // // See SetupAuth for authenticating with a username and password. Setup func(ctx context.Context, client *Client, pipe *Pipeline) error // contains filtered or unexported fields }
func NewFromURL ¶ added in v0.6.0
func (*Client) Command ¶
Command sends a command to the server and returns the result. The error is encoded into the result for ergonomics.
See Pipeline for more information on argument types.
The caller should call Close on the result when finished with it.
func (*Client) Pipeline ¶
Pipeline sends a command to the server and returns the promise of a result. r may be nil, as in the case of the first command in a pipeline. Each successive call to Pipeline should re-use the last returned Pipeline.
Known arg types are strings, []byte, LenReader, and fmt.Stringer. All other types will be converted to JSON.
It is safe to keep a pipeline running for a long time, with many send and receive cycles.
Example:
p := client.Pipeline(ctx, nil, "SET", "foo", "bar") defer p.Close() p = client.Pipeline(ctx, r, "GET", "foo") // Read the result of SET first. err := p.Ok() if err != nil { // handle error } got, err := p.Bytes() if err != nil { // handle error } fmt.Println(string(got))
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents an error returned by the Redis server, as opposed to a a protocol or network error.
type LenReader ¶
LenReader is an io.Reader that also knows its length. A new one may be created with NewLenReader.
type Pipeline ¶
type Pipeline struct { // CloseOnRead determines whether the Pipeline is closed after the first read. // // It is set to True when the result is returned from Command, and // False when it is returned from Pipeline. // // It is ignored if in the middle of reading an array, or if the result // is of a subscribe command. CloseOnRead bool // contains filtered or unexported fields }
Pipeline is the result of a command.
Its methods are not safe for concurrent use.
func (*Pipeline) ArrayLength ¶
ArrayLength reads the next message as an array length. It does not close the Pipeline even if CloseOnRead is true.
func (*Pipeline) ArrayStack ¶
ArrayStack returns the position of the result within an array.
The returned slice must not be modified.
func (*Pipeline) Bytes ¶
Bytes returns the result as a byte slice.
Refer to r.CloseOnRead for whether the result is closed after the first read.
func (*Pipeline) Close ¶
Close releases all resources associated with the result.
It is safe to call Close multiple times.
func (*Pipeline) Int ¶
Int returns the result as an integer.
Refer to r.CloseOnRead for whether the result is closed after the first read.
func (*Pipeline) NextSubMessage ¶
func (r *Pipeline) NextSubMessage() (*SubMessage, error)
NextSubMessage reads the next subscribe from the pipeline. Read more: https://redis.io/docs/manual/pubsub/.
It does not close the Pipeline even if CloseOnRead is true.
func (*Pipeline) Ok ¶
Ok returns whether the result is "OK". Note that it may fail even if the
command succeeded. For example, a successful GET will return a value.
func (*Pipeline) String ¶
String returns the result as a string.
Refer to r.CloseOnRead for whether the result is closed after the first read.
type SubMessage ¶
type SubMessage struct { // Type is either "subscribe" (acknowledgement of subscription) or "message" Type SubMessageType Channel string // Payload is the number of channels subscribed to if Type is "subscribe", Payload string }
SubMessage is a message received from a pubsub subscription.
type SubMessageType ¶
type SubMessageType string
const ( SubMessageSubscribe SubMessageType = "subscribe" SubMessageMessage SubMessageType = "message" )