redis

package
v0.0.0-...-d65df50 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2016 License: BSD-2-Clause Imports: 28 Imported by: 1

Documentation

Index

Examples

Constants

View Source
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'
)
View Source
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

View Source
const SampleSize = 100

Variables

View Source
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 NewBatch

func NewBatch(conn redis.Conn) *Batch

NewBatch create a new non-transactional batch object

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

func (*Batch) Execute

func (b *Batch) Execute() ([]*Promise, error)

Execute flushes the connection and executes the batch if it's a transaction, and automatically receives all the return values, setting them in the previously returned promises.

We also return all the promises in order if you're just interested in them after execution

func (*Batch) Send

func (b *Batch) Send(commandName string, args ...interface{}) (*Promise, error)

Send enqueues a single command in the batch, and returns a promise that will contain the return value of executing this command when Execute is called.

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

func (i *CompoundIndex) Matches(filters query.Filters, order query.Ordering) (bool, float32)

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:

  1. the filter map is for P1 - we match
  2. the filter map is for P1,P2 - we match
  3. the filter map is for P2,P3 - we do not match
  4. 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) Scan

func (i CompoundIndex) Scan(chunk int) (<-chan schema.Key, chan<- bool)

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 Decoder

type Decoder struct {
}

func (Decoder) Decode

func (d Decoder) Decode(data []byte, t schema.ColumnType) (interface{}, error)

type Driver

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

Driver is the driver implementation over a redis data store

func NewDriver

func NewDriver() *Driver

NewDriver creates a new redis driver instance

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

func (r *Driver) Dump(table string) (<-chan schema.Entity, <-chan error, chan<- bool, error)

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) Stats

func (r *Driver) Stats() (*driver.Stats, error)

func (*Driver) Status

func (r *Driver) Status() error

Status returns an error if the driver is not properly running and has at least one schema active

func (*Driver) Update

Update executes an UPDATE query on the driver, performing a series of changes on entities specified by a set of filters

type Encoder

type Encoder struct {
	TextCompressThreshold int
}

func NewEncoder

func NewEncoder(compressThreshold int) Encoder

func (Encoder) Encode

func (c Encoder) Encode(v interface{}) ([]byte, error)

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.

func (*Promise) Reply

func (p *Promise) Reply() (interface{}, error)

Reply returns the underlying reply value of this promise, after executing the batch. It is nil before that. We also return a nil error to be able to use redigo's automatic conversion utility functions. If you just need the value you can access it directly

func (*Promise) String

func (p *Promise) String() string

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

func (*Transaction) Send

func (b *Transaction) Send(commandName string, args ...interface{}) (*Promise, error)

Send enqueues a single command in the batch, and returns a promise that will contain the return value of executing this command when Execute is called.

Jump to

Keyboard shortcuts

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