Documentation ¶
Index ¶
- Constants
- Variables
- type Batch
- type CompoundIndex
- func (i *CompoundIndex) Find(filters query.Filters, offset, limit int, order query.Ordering) ([]schema.Key, int, error)
- func (i *CompoundIndex) Matches(filters query.Filters, order query.Ordering) (bool, float32)
- func (i *CompoundIndex) MatchesProperties(properties ...string) bool
- func (i *CompoundIndex) Pipeline(tx *Transaction) (chan<- *entityDiff, <-chan error)
- func (i *CompoundIndex) Properties() []string
- func (i CompoundIndex) RawEntries(chunk int) (<-chan string, chan<- bool)
- func (i *CompoundIndex) RedisKey() string
- func (i CompoundIndex) RemoveEntry(entry string) error
- func (i CompoundIndex) Scan(chunk int) (<-chan schema.Key, chan<- bool)
- func (i *CompoundIndex) String() string
- type Config
- type Decoder
- type Driver
- func (r *Driver) Delete(q query.DelQuery) *query.DelResponse
- func (r *Driver) Dump(table string) (<-chan schema.Entity, <-chan error, chan<- bool, error)
- func (r *Driver) Get(q query.GetQuery) *query.GetResponse
- func (r *Driver) Init(sp schema.SchemaProvider, config interface{}) error
- func (r *Driver) Put(q query.PutQuery) *query.PutResponse
- func (r *Driver) Stats() (*driver.Stats, error)
- func (r *Driver) Status() error
- func (r *Driver) Update(q query.UpdateQuery) *query.UpdateResponse
- type Encoder
- type Promise
- type Transaction
Examples ¶
Constants ¶
const ( IntPrefix = 'i' UintPrefix = 'u' FloatPrefix = 'f' TextPrefix = 'x' CompressedTextPrefix = 'z' CompressedTextPrefixSnappy = 'Z' BoolPrefix = 'b' TimestampPrefix = 't' BinaryPrefix = 'r' SetPrefix = 's' ListPrefix = 'l' NilPrefix = 'N' MapPrefix = 'm' )
const MinRepairFrequency = 10 //ms
The minimal frequency for the repair loop. We do this because we don't want to take up too much CPU time on repair loops
const SampleSize = 100
Variables ¶
var DefaultConfig = Config{ Network: "tcp", Addr: "localhost:6379", Timeout: 1000, Master: true, RepairEnabled: false, RepairFrequency: 50, TextCompressThreshold: 2048, DeleteChunkSize: 100, }
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch struct {
// contains filtered or unexported fields
}
Batch represents a set of batched results, either a transaction or just send/receive.
It has two key features:
1. Automating the send/flush/receive logic, and replacing it with a single Execute() call that takes care of retrieving the right number of values
2. To ease the extraction of return values, it returns a "promise" from each Send call. After Execute() is called, these promises are filled with the return value of executing the queued command
Example ¶
return conn, e := redis.Dial("tcp", srv.Addr()) if e != nil { panic(e) } // create a new batch from the connection b := NewBatch(conn) // send a SET command if _, e := b.Send("SET", "foo", "BAR"); e != nil { panic(e) } // Send a GET command and keep a promise that will contain its value after execution promise, e := b.Send("GET", "foo") if e != nil { panic(e) } // execute also returns the promises, but we're not interested in this right now if _, e := b.Execute(); e != nil { panic(e) } s, _ := redis.String(promise.Reply()) fmt.Println(s) // Outpux: BAR
Output:
func (*Batch) Abort ¶
func (b *Batch) Abort()
Abort drains the receive buffer and closes the connection. It doesn't return an error as it is meant to be a deferred call
type CompoundIndex ¶
type CompoundIndex struct {
// contains filtered or unexported fields
}
CompoundIndex is an index that can index just one column, regardless of its type
func NewCompoundIndex ¶
func NewCompoundIndex(idx schema.Index, table string) *CompoundIndex
NewCompoundIndex creates a new compound index using a descriptor, for the given table name
func (*CompoundIndex) Find ¶
func (i *CompoundIndex) Find(filters query.Filters, offset, limit int, order query.Ordering) ([]schema.Key, int, error)
Find returns ids from the query's filters. The query should have exactly 1 filter. We assume matching of the index to the query has been checked before
func (*CompoundIndex) Matches ¶
Matches returns true if a query can be searched by this index. It matches if the filter set's properties are a *prefix* of this index's properties, AND the ordering, if there is one, is the last or sole property of the index
i.e if we index P1,P2,P3 and:
- the filter map is for P1 - we match
- the filter map is for P1,P2 - we match
- the filter map is for P2,P3 - we do not match
- the filter map is for P1,P3 - we do not match
func (*CompoundIndex) MatchesProperties ¶
func (i *CompoundIndex) MatchesProperties(properties ...string) bool
MatchesProperties tells us whether the properties are a subset of our own property
func (*CompoundIndex) Pipeline ¶
func (i *CompoundIndex) Pipeline(tx *Transaction) (chan<- *entityDiff, <-chan error)
Pipeline is the main indexing utility, that allows concurrent and bulk indexing of entities on a single transaction.
It returns a channel the caller sends entity diffs down, and a channel that eventually sends errors in indexing back. The caller needs to close the entity diff channel, and then wait for an error on the error channel, before executing the transaction.
func (*CompoundIndex) Properties ¶
func (i *CompoundIndex) Properties() []string
Properties returns the list of properties this index indexes
func (CompoundIndex) RawEntries ¶
func (i CompoundIndex) RawEntries(chunk int) (<-chan string, chan<- bool)
func (*CompoundIndex) RedisKey ¶
func (i *CompoundIndex) RedisKey() string
redisKey generates the desired redis key for this index
func (CompoundIndex) RemoveEntry ¶
func (i CompoundIndex) RemoveEntry(entry string) error
func (*CompoundIndex) String ¶
func (i *CompoundIndex) String() string
type Config ¶
type Config struct { Network string `yaml:"net"` Addr string `yaml:"addr"` Timeout int64 `yaml:"timeout_ms"` Master bool `yaml:"master"` RepairEnabled bool `yaml:"repair_enabled"` RepairFrequency int `yaml:"repair_freq_ms"` TextCompressThreshold int `yaml:"text_compress_threshold"` DeleteChunkSize int `yaml:"del_chunk_size"` }
Config represents the configurations for the redis driver
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is the driver implementation over a redis data store
func (*Driver) Delete ¶
func (r *Driver) Delete(q query.DelQuery) *query.DelResponse
Delete executes a DEL query on the driver, deleting entities based on filter criteria
func (*Driver) Dump ¶
Dump a specific table's records as a stream of entities.
The function also returns a channel for erros that may occur, and a bool channel allowing its caller to stop it if an error has happened upstream
func (*Driver) Get ¶
func (r *Driver) Get(q query.GetQuery) *query.GetResponse
Get executes a GET query on the driver, selecting any number of entities
func (*Driver) Init ¶
func (r *Driver) Init(sp schema.SchemaProvider, config interface{}) error
Init initializes and configures the redis driver
func (*Driver) Put ¶
func (r *Driver) Put(q query.PutQuery) *query.PutResponse
Put executes a PUT query on the driver, inserting/updating one or more entities
func (*Driver) Status ¶
Status returns an error if the driver is not properly running and has at least one schema active
func (*Driver) Update ¶
func (r *Driver) Update(q query.UpdateQuery) *query.UpdateResponse
Update executes an UPDATE query on the driver, performing a series of changes on entities specified by a set of filters
type Promise ¶
type Promise struct {
Value interface{}
}
Promise represents the future return value of a queued commmand in a batch.
Each call to Send returns a promise that will be filled with the result of executing the sent command after Execute is called.
type Transaction ¶
type Transaction struct { *Batch // contains filtered or unexported fields }
A transaction is similar to a Batch, but has MULTI/EXEC/DISCARD
func NewTransaction ¶
func NewTransaction(conn redis.Conn) *Transaction
NewBatchTransaction creates a new transactional batch object
func (*Transaction) Abort ¶
func (b *Transaction) Abort() error
Abort aborts a transaction batch by calling redis ABORT. Note that it will keep all promises empty and reset the transaction automatically
func (*Transaction) Execute ¶
func (t *Transaction) Execute() ([]*Promise, error)
Execute a transaction