Documentation ¶
Index ¶
- Variables
- func ErrWrongToken(expToken byte, token byte) error
- func ErrWrongType(v interface{}, expected string) error
- func ScanArray(r *bufio.Reader) (int, error)
- func ScanBulkString(r *bufio.Reader) (int, error)
- func ScanInteger(r *bufio.Reader) (int, error)
- func ScanSimpleString(r *bufio.Reader) (int, error)
- type ArrayReader
- func (a *ArrayReader) Err() error
- func (r *ArrayReader) Expect(vars ...string) error
- func (a *ArrayReader) Init(defaultScanFunc ScanFunc) error
- func (a *ArrayReader) Len() int
- func (r *ArrayReader) Next() *ArrayReader
- func (r *ArrayReader) NextIs(scanFunc ScanFunc) *ArrayReader
- func (r *ArrayReader) Scan(dst interface{}) error
- func (r *ArrayReader) SwitchOnNext() string
- type ArrayWriter
- type Client
- type Message
- type MessageChan
- type MessageChanMap
- type PoolOptions
- type PubSubOpts
- type Reader
- type RedisPattern
- type Result
- type ScanFunc
- type Scanner
- type StrInt
- type SubClient
- type Subscriber
- type TrimOptions
Constants ¶
This section is empty.
Variables ¶
var ErrConnDial = errors.New("Received error whilst establishing connection")
ErrConnDial error during dial
var ErrConnRead = errors.New("Received error whilst reading from connection")
ErrConnRead received error when reading from connection
var ErrConnWrite = errors.New("Received error whilst writing to connection")
ErrConnWrite error when writing to connection
var ErrMalformedString = errors.New("Expected CRLF terminated string, but did not receive one")
ErrMalformedString received expected length, but it isn't terminated properly
var ErrMixedTopicTypes = errors.New("All the topics need to be either of type string or of RedisPattern, but not of both")
ErrMixedTopicTypes is given when you pass in arguments of both RedisPattern and String
var ErrNoMoreRows = errors.New("No more rows")
ErrNoMoreRows is returned when an ArrayResult does not contain any more entries when Next() is called
var ErrOptsDialAndURL = errors.New("Both Dial and URL is set, can only set one")
ErrOptsDialAndURL cannot combine both dial and URL for pool options
var ErrRetryable = errors.New("Temporary error, please retry!")
ErrRetryable is an error that can be retried
var ErrWrongPrefix = errors.New("Wrong prefix on string")
ErrWrongPrefix returns when we expected a certain type prefix, but received another
Functions ¶
func ErrWrongToken ¶
ErrWrongToken is used internally in the Redis Reader when it checks whether the token expected and this is not the case
func ErrWrongType ¶
ErrWrongType is returned when the function receives an unsupported type
Types ¶
type ArrayReader ¶
type ArrayReader struct {
// contains filtered or unexported fields
}
func NewArrayReader ¶
func NewArrayReader(r *Reader) *ArrayReader
func (*ArrayReader) Err ¶
func (a *ArrayReader) Err() error
func (*ArrayReader) Expect ¶
func (r *ArrayReader) Expect(vars ...string) error
Expect does an Any byte comparison with the values passed in against the next value in the array
func (*ArrayReader) Init ¶
func (a *ArrayReader) Init(defaultScanFunc ScanFunc) error
func (*ArrayReader) Next ¶
func (r *ArrayReader) Next() *ArrayReader
Next prepares the next row to be used by `Scan()`, it returns either a "no more rows" error or a connection/read error will be wrapped.
func (*ArrayReader) NextIs ¶
func (r *ArrayReader) NextIs(scanFunc ScanFunc) *ArrayReader
func (*ArrayReader) Scan ¶
func (r *ArrayReader) Scan(dst interface{}) error
Scan operates the same as `Scan` on a single result
func (*ArrayReader) SwitchOnNext ¶
func (r *ArrayReader) SwitchOnNext() string
SwitchOnNext returns a string value of the next value in the ArrayReader which is a pointer to the underlying byte slice - as the name implies, it is mostly implemented for switch cases where there's a guarantee that the next Scan/SwitchOnNext call will happen after the last use of this value. If you want to not only switch on the value or do a one-off comparison, please use Scan() instead.
type ArrayWriter ¶
type ArrayWriter struct {
// contains filtered or unexported fields
}
func NewArrayWriter ¶
func NewArrayWriter(bufw *bufio.Writer) *ArrayWriter
func (*ArrayWriter) Add ¶
func (w *ArrayWriter) Add(items ...interface{}) error
func (*ArrayWriter) AddString ¶
func (w *ArrayWriter) AddString(items ...string) *ArrayWriter
func (*ArrayWriter) Flush ¶
func (w *ArrayWriter) Flush() error
func (*ArrayWriter) Init ¶
func (w *ArrayWriter) Init(length int) *ArrayWriter
func (*ArrayWriter) Len ¶
func (w *ArrayWriter) Len() int
func (*ArrayWriter) Reset ¶
func (w *ArrayWriter) Reset(wr io.Writer)
type Client ¶
type Client interface { // Get executes a get command on a redis server and returns a Result type, which you can use Scan // on to get the result put into a variable Get(ctx context.Context, key string) (*Result, error) // Set sets a Value in redis, it accepts a TTL which can be put to 0 to disable TTL Set(ctx context.Context, key string, value driver.Value, ttl int) error // Del removes a key from the redis server Del(ctx context.Context, key string) error // Ping pings the server, mostly an internal command to ensure the subscription connection is still working Ping(ctx context.Context) error // Publish publishes a message to the selected topic, it returns an int of the number of clients // that received the message Publish(ctx context.Context, topic string, message driver.Value) (recvCount int, err error) }
Client is the interface to interact with Redis. It uses connections with a single buffer attached, much like the MySQL driver implementation. This allows it to reduce stack allocations.
type Message ¶
type Message struct { Ctx context.Context Result *Result // contains filtered or unexported fields }
I can't really have more than one message per connection "active" at a time because the reader, the result etc are all tied to the connection (and we should really not be advancing the reader in another thread) - so the idea here with the pool and stuff is pretty stupid. I should add the message to the subscription manager and listen for it on the channel at the top of every loop of Listen()
type MessageChan ¶
type MessageChan <-chan *Message
type MessageChanMap ¶
type MessageChanMap map[string]MessageChan
type PoolOptions ¶
type PoolOptions struct { // MaxSize is the maximum size of the connection pool. If reached, it will // block the next client request until a connection is free MaxSize int // MaxIdle How many connections that can remain idle in the pool, will // otherwise be reaped by the trimming thread // Default: 5 MaxIdle int // How long before reads time out // Default: 500 ms ReadTimeout time.Duration // URL is the protocol, address and database selection concatenated into // a URL format. Inspired by DSN. URL string // Dial is a function that returns an established net.Conn Dial dialFunc // InitialBufSize is the initial buffer size to associate with the // connection, this is also the minimum buffer size allowed when creating // new connections, but if the trimming thread is enabled and the // percentile target returns a higher value, this will be used for // any subsequent connections // Default: 4096 bytes InitialBufSize int // TrimOptions are fine-tuning options for the trimming go routine, this // should usually not be needed TrimOptions *TrimOptions // contains filtered or unexported fields }
PoolOptions is specified to tune the connection pool for the client
type PubSubOpts ¶
type RedisPattern ¶
type RedisPattern string
RedisPattern is a string that contains what is considered a pattern according to the spec here: https://redis.io/commands/KEYS
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result is what is returned from the Redis client if a single response is expected
func (*Result) Scan ¶
Scan on result allows us to read with zero-copy into Scanner and io.Writer implementations as well as into string, int, other []byte slices (but with copy). However since Redis always returns a []byte slice, if you were to implement a scanner you would need to have a value switch that takes []byte slice and does something productive with it. This implementation can be simpler and forego the source switch since it is custom made for Redis.
type Scanner ¶
type Scanner interface {
Scan(dst interface{}) error
}
Scanner is an interface that allows you to implement custom logic with direct control over the byte buffer being used by the connection. Do not modify it and do not return it. As soon as your Scan function exits, the connection will start using the buffer again.
type SubClient ¶
type SubClient interface { Subscriber Client }
type Subscriber ¶
type Subscriber interface { // Subscribe returns a map of channels corresponding to the string value of the topics being subscribed to Subscribe(ctx context.Context, topics ...interface{}) (msgChanMap MessageChanMap, err error) // Unsubscribe closes the subscriptions on the channels given Unsubscribe(ctx context.Context, topics ...interface{}) (err error) }
type TrimOptions ¶
type TrimOptions struct { Interval time.Duration // default is 500 ms BufQuantileTargets []float64 // the targets to track in 0-1 percentiles, if none given, the default is []float{0.8, 1} BufQuantileTarget float64 // The specific target for buf size. If invalid or omitted, it will pick the first (a[0]) percentile from BufQuantileTargets AllowedMargin float64 // this is 0-1 representing a fraction of how far from the lowest percentile a higher one can be so that it shifts to using a higher percentile. To disable it, set it below 0. It can also go higher than 1, but we recommend targeting a higher percentile instead. The default is 0.1 }
TrimOptions represents advanced options to fine-tune the trimming background thread for connections
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
mocks
|
|
mock_driver
Package mock_driver is a generated GoMock package.
|
Package mock_driver is a generated GoMock package. |
mock_greddis
Package mock_greddis is a generated GoMock package.
|
Package mock_greddis is a generated GoMock package. |
mock_io
Package mock_io is a generated GoMock package.
|
Package mock_io is a generated GoMock package. |
mock_net
Package mock_net is a generated GoMock package.
|
Package mock_net is a generated GoMock package. |