redis

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: ISC Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RESPTypeSimpleString = RESPType('+') // simple string
	RESPTypeError        = RESPType('-') // error
	RESPTypeInteger      = RESPType(':') // integer
	RESPTypeBulkString   = RESPType('$') // bulk string
	RESPTypeArray        = RESPType('*') // array header
)

Variables

View Source
var (
	CmdDISCARD = RawCmd{[]byte("*1\r\n$7\r\nDISCARD\r\n")}
	CmdEXEC    = RawCmd{[]byte("*1\r\n$4\r\nEXEC\r\n")}
	CmdMULTI   = RawCmd{[]byte("*1\r\n$5\r\nMULTI\r\n")}
	CmdUNWATCH = RawCmd{[]byte("*1\r\n$7\r\nUNWATCH\r\n")}
)

constant commands without results

View Source
var ErrRespUnexpectedType = errors.New("unexpected resp type")

Functions

This section is empty.

Types

type ArrayEntDecoder

type ArrayEntDecoder struct {
	*RReader
	// contains filtered or unexported fields
}

ArrayEntDecoder is an implementation of ent.Decoder that decodes values in a known order. E.g. with keys=["key1", "key2", "key3"], reads "value1" "value2" "value3".

func (*ArrayEntDecoder) Key

func (r *ArrayEntDecoder) Key() string

func (*ArrayEntDecoder) More

func (r *ArrayEntDecoder) More() bool

type DictEntDecoder

type DictEntDecoder struct {
	*RReader
	// contains filtered or unexported fields
}

DictEntDecoder is an implementation of ent.Decoder which reads keys and values interleaved. E.g. "key1" "value1" "key2" "value2" ...

func (*DictEntDecoder) Key

func (r *DictEntDecoder) Key() string

func (*DictEntDecoder) More

func (r *DictEntDecoder) More() bool

type Ent

type Ent = ent.Ent

type EntEncoder

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

EntEncoder is an implementation of ent.Encoder Since we store ents in Redis hashes (HSET, HGET, et al) values must all be strings, which is why this is not really using RWriter.

func (*EntEncoder) BeginDict

func (c *EntEncoder) BeginDict(length int)

func (*EntEncoder) BeginEnt

func (c *EntEncoder) BeginEnt(version uint64)

func (*EntEncoder) BeginHSET

func (c *EntEncoder) BeginHSET(key []byte, nfields int)

func (*EntEncoder) BeginList

func (c *EntEncoder) BeginList(length int)

func (*EntEncoder) Blob

func (c *EntEncoder) Blob(v []byte)

func (*EntEncoder) Bool

func (c *EntEncoder) Bool(v bool)

func (*EntEncoder) Buffer

func (c *EntEncoder) Buffer() []byte

func (*EntEncoder) EndDict

func (c *EntEncoder) EndDict()

func (*EntEncoder) EndEnt

func (c *EntEncoder) EndEnt()

func (*EntEncoder) EndList

func (c *EntEncoder) EndList()

func (*EntEncoder) Err

func (c *EntEncoder) Err() error

func (*EntEncoder) Float

func (c *EntEncoder) Float(v float64, bitsize int)

func (*EntEncoder) Int

func (c *EntEncoder) Int(v int64, bitsize int)

func (*EntEncoder) Key

func (c *EntEncoder) Key(k string)

func (*EntEncoder) Str

func (c *EntEncoder) Str(v string)

func (*EntEncoder) Uint

func (c *EntEncoder) Uint(v uint64, bitsize int)

type EntIterator added in v0.2.8

type EntIterator struct {
	IdIterator
	// contains filtered or unexported fields
}

------

func MakeEntIterator added in v0.2.8

func MakeEntIterator(e Ent, s *EntStorage) *EntIterator

func (*EntIterator) Next added in v0.2.8

func (it *EntIterator) Next(e ent.Ent) bool

type EntStorage

type EntStorage struct {
	*Redis
}

func NewEntStorage

func NewEntStorage(r *Redis) *EntStorage

func (*EntStorage) Close

func (s *EntStorage) Close() error

Close closes the ent storage. Does not close s.Redis.

func (*EntStorage) Create added in v0.2.8

func (s *EntStorage) Create(e ent.Ent, fields ent.FieldSet) (id uint64, err error)

CreateEnt is part of the ent.Storage interface, used by TYPE.Create()

func (*EntStorage) Delete added in v0.2.8

func (s *EntStorage) Delete(e ent.Ent, id uint64) error

DeleteEnt is part of the ent.Storage interface, used by TYPE.PermanentlyDelete()

func (*EntStorage) FindByIndex added in v0.2.8

func (s *EntStorage) FindByIndex(
	entType string, x *ent.EntIndex, key []byte, limit int, flags ent.LookupFlags,
) (ids []uint64, err error)

FindEntIdsByIndex is part of the ent.Storage interface, used by FindTYPEByINDEX

func (*EntStorage) IterateEnts added in v0.2.8

func (s *EntStorage) IterateEnts(e Ent) ent.EntIterator

func (*EntStorage) IterateIds added in v0.2.8

func (s *EntStorage) IterateIds(entType string) ent.IdIterator

func (*EntStorage) LoadById added in v0.2.8

func (s *EntStorage) LoadById(e Ent, id uint64) (version uint64, err error)

LoadEntById is part of the ent.Storage interface, used by LoadTYPEById()

func (*EntStorage) LoadByIndex added in v0.2.8

func (s *EntStorage) LoadByIndex(
	e Ent, x *ent.EntIndex, key []byte, limit int, flags ent.LookupFlags,
) ([]Ent, error)

LoadEntsByIndex is part of the ent.Storage interface, used by LoadTYPEByINDEX

func (*EntStorage) Save added in v0.2.8

func (s *EntStorage) Save(e Ent, fields ent.FieldSet) (nextVersion uint64, err error)

SaveEnt is part of the ent.Storage interface, used by TYPE.Save()

type IdIterator added in v0.2.8

type IdIterator struct {
	RawCmd
	// contains filtered or unexported fields
}

func MakeIdIterator added in v0.2.8

func MakeIdIterator(entType string, r *Redis) *IdIterator

func (*IdIterator) Err added in v0.2.8

func (it *IdIterator) Err() error

func (*IdIterator) Next added in v0.2.8

func (it *IdIterator) Next(id *uint64) bool

func (*IdIterator) Run added in v0.2.8

func (it *IdIterator) Run(conn radix.Conn) error

func (*IdIterator) UnmarshalRESP added in v0.2.8

func (it *IdIterator) UnmarshalRESP(rs *bufio.Reader) error

type RCmd

type RCmd struct {
	Encode func(w *RIOWriter) error
	Decode func(r *RReader) error
}

func (*RCmd) Keys

func (a *RCmd) Keys() []string

func (*RCmd) MarshalRESP

func (a *RCmd) MarshalRESP(w io.Writer) error

func (*RCmd) Run

func (a *RCmd) Run(c radix.Conn) error

func (*RCmd) String

func (a *RCmd) String() string

func (*RCmd) UnmarshalRESP

func (a *RCmd) UnmarshalRESP(r *bufio.Reader) error

type RESPType

type RESPType = byte

type RIOWriter

type RIOWriter struct {
	RWriter
	// contains filtered or unexported fields
}

RIOWriter is an extension of RWriter with buffered IO, writing to a io.Writer

func (*RIOWriter) Blob

func (w *RIOWriter) Blob(data []byte)

func (*RIOWriter) Flush

func (w *RIOWriter) Flush()

type RReader

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

func (*RReader) AnyData

func (r *RReader) AnyData(buf []byte) []byte

AnyData reads the next message uninterpreted. If buf is not nil, it is used for reading the data and a slice of it is returned. If buf is nil or its cap is less than needed, a new byte array is allocated.

func (*RReader) AppendBlob

func (r *RReader) AppendBlob(buf []byte) []byte

AppendBlob reads the next message (uninterpreted) and appends it to buf

func (*RReader) Blob

func (r *RReader) Blob() []byte

Blob reads the next message uninterpreted.

func (*RReader) Bool

func (r *RReader) Bool() bool

Bool reads a boolean value

func (*RReader) BytesArray

func (r *RReader) BytesArray() [][]byte

BytesArray reads an array of raw byte arrays

func (*RReader) DictHeader

func (r *RReader) DictHeader() int

func (*RReader) Discard

func (r *RReader) Discard()

Discard reads & discards the next message, including entire arrays

func (*RReader) Err

func (r *RReader) Err() error

Err returns the error state of the reader

func (*RReader) Float

func (r *RReader) Float(bitsize int) float64

Float reads a floating point number

func (*RReader) HexUint

func (r *RReader) HexUint(bitsize int) uint64

func (*RReader) Int

func (r *RReader) Int(bitsize int) int64

Int reads a signed integer

func (*RReader) IntArray

func (r *RReader) IntArray(bitsize int) []int64

IntArray reads an array of integers

func (*RReader) ListHeader

func (r *RReader) ListHeader() int

ListHeader reads an array header, returning the number of elements that follows. Returns -1 to signal "nil array" and 0 signals "empty array" since the RESP protocol makes that distinction (though Go does not.)

func (*RReader) Next

func (r *RReader) Next(buf []byte) []byte

Next is a low-level read function which reads whatever RESP message comes next, without and interpretation. Note that in the case typ is RESPTypeArray the caller is responsible for reading ParseInt(data) more messages (array elements) to uphold the read stream integrity. When typ==RESPTypeError, r.Err() is set to reflect the error message. buf is optional. If nil new buffers are allocated for the response (data), else buf is used for data if it's large enough.

func (*RReader) Scalar

func (r *RReader) Scalar() (typ RESPType, data []byte)

Scalar reads any scalar value. Compound types like arrays are skipped & discarded.

func (*RReader) SetErr

func (r *RReader) SetErr(err error)

func (*RReader) Str

func (r *RReader) Str() string

Str reads the next message as a string. If the message read is not a RESP string type, the empty string is returned. To read the next message's content as a string regardless of its type, use `string(r.Bytes())`

func (*RReader) StrArray

func (r *RReader) StrArray() []string

StrArray reads an array of strings

func (*RReader) Type added in v0.2.8

func (r *RReader) Type() RESPType

Type returns the RESP type of the most recently read value

func (*RReader) Uint

func (r *RReader) Uint(bitsize int) uint64

Uint reads an unsigned integer

type RWriter

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

func (*RWriter) ArrayHeader

func (w *RWriter) ArrayHeader(length int)

func (*RWriter) Blob

func (w *RWriter) Blob(data []byte)

func (*RWriter) Bool

func (w *RWriter) Bool(v bool)

func (*RWriter) Err

func (w *RWriter) Err() error

Err returns the error state of the writer

func (*RWriter) Float

func (w *RWriter) Float(v float64, bitsize int)

func (*RWriter) Int

func (w *RWriter) Int(v int64, bitsize int)

func (*RWriter) Str

func (w *RWriter) Str(s string)

func (*RWriter) StringArray

func (w *RWriter) StringArray(sv ...string)

func (*RWriter) Uint

func (w *RWriter) Uint(v uint64, bitsize int)

type RawCmd

type RawCmd struct {
	Data []byte // never mutated
}

RawCmd sends verbatim bytes over a redis connection and discards any replies

func MakeBulkStringCmd added in v0.2.8

func MakeBulkStringCmd(cmd string, args ...[]byte) *RawCmd

func MakeSingleKeyCmd added in v0.2.8

func MakeSingleKeyCmd(cmd string, key []byte) *RawCmd

func (*RawCmd) Command added in v0.2.8

func (c *RawCmd) Command() []byte

func (*RawCmd) Keys

func (c *RawCmd) Keys() []string

func (*RawCmd) MarshalRESP

func (c *RawCmd) MarshalRESP(w io.Writer) error

func (*RawCmd) Run

func (c *RawCmd) Run(conn radix.Conn) error

func (*RawCmd) String

func (c *RawCmd) String() string

func (*RawCmd) UnmarshalRESP

func (c *RawCmd) UnmarshalRESP(r *bufio.Reader) error

type RawCmdHexUint

type RawCmdHexUint struct {
	RawCmd
	ResultPtr *uint64
}

func (*RawCmdHexUint) Run

func (c *RawCmdHexUint) Run(conn radix.Conn) error

func (*RawCmdHexUint) UnmarshalRESP

func (c *RawCmdHexUint) UnmarshalRESP(r *bufio.Reader) error

type Redis

type Redis struct {
	Logger *log.Logger
	// contains filtered or unexported fields
}

func (*Redis) Batch

func (r *Redis) Batch(f func(c radix.Conn) error) error

func (*Redis) BatchOnRClient

func (r *Redis) BatchOnRClient(f func(c radix.Conn) error) error

func (*Redis) Close

func (r *Redis) Close() error

func (*Redis) Del

func (r *Redis) Del(key string) error

func (*Redis) GetBytes

func (r *Redis) GetBytes(key string) (value []byte, err error)

func (*Redis) GetString

func (r *Redis) GetString(key string) (value string, err error)

func (*Redis) HGet

func (r *Redis) HGet(key, field string, value_out interface{}) error

func (*Redis) Open

func (r *Redis) Open(rwaddr, roaddr string, connPoolSize int) error

func (*Redis) OpenRetry

func (r *Redis) OpenRetry(rwaddr, roaddr string, connPoolSize int)

OpenRetry calls Open until it succeeds, with a second delay in between

func (*Redis) RClient

func (r *Redis) RClient() *radix.Pool

RClient returns a redis connection for reading

func (*Redis) Set

func (r *Redis) Set(key string, value interface{}) error

func (*Redis) SetConnections

func (r *Redis) SetConnections(rwc, roc *radix.Pool) error

func (*Redis) SetExpiring

func (r *Redis) SetExpiring(key string, ttl time.Duration, value interface{}) error

func (*Redis) UpdateExpire

func (r *Redis) UpdateExpire(key string, ttl time.Duration) error

func (*Redis) WClient

func (r *Redis) WClient() *radix.Pool

WClient returns a redis connection for writing (can also read)

type ZRangeEntIdsCmd

type ZRangeEntIdsCmd struct {
	RawCmd
	Result []uint64
	// contains filtered or unexported fields
}

func (*ZRangeEntIdsCmd) Run

func (c *ZRangeEntIdsCmd) Run(conn radix.Conn) error

func (*ZRangeEntIdsCmd) UnmarshalRESP

func (c *ZRangeEntIdsCmd) UnmarshalRESP(r *bufio.Reader) error

Jump to

Keyboard shortcuts

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