db

package
v0.0.0-...-3ed64e7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package db is used for retrieving redis connections, and has helper methods for interacting with the data held within redis

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllQueueNames

func AllQueueNames() []string

AllQueueNames returns a list of all currently active queues

func ClaimedKey

func ClaimedKey(queueName string) string

ClaimedKey returns the key for the list of claimed (QRPOP'd) eventIDs in a queue

func ConsumersKey

func ConsumersKey(queueName string) string

ConsumersKey returns the key for the sorted set of consumer clientIDs QREGISTER'd to consume from a quueue

func GetQueueNameFromKey

func GetQueueNameFromKey(key string) (string, error)

GetQueueNameFromKey takes in any of the above keys produced by this package and returns the queue name used to generate the key

func ItemLockKey

func ItemLockKey(queueName, eventID string) string

ItemLockKey returns the key which is used as a lock when a consumer QRPOPs an event off the unclaimed list. When the lock expires the item is put back in unclaimed if it hasn't been QACK'd already

func ItemsKey

func ItemsKey(queueName string) string

ItemsKey returns the key for the hash of eventID -> event for a queue

func QueueChannelNameKey

func QueueChannelNameKey(queueName string) string

QueueChannelNameKey returns the name of the pubsub channel used to broadcast events for the given queue

func UnclaimedKey

func UnclaimedKey(queueName string) string

UnclaimedKey returns the key for the list of unclaimed eventIDs in a queue

Types

type DBer

type DBer interface {

	// Cmd is a function which will perform the given cmd/args in redis and
	// returns the resp. It automatically handles using redis cluster, if that
	// is enabled
	Cmd(string, ...interface{}) *redis.Resp

	// Pipe runs a set of commands (given by p) one after the other. It is *not*
	// guaranteed that all the commands will be run on the same client. If any
	// commands return an error the pipeline will stop and return that error.
	// Otherwise the Resp from each command is returned in a slice
	//
	//	r, err := db.Pipe(
	//		db.PP("SET", "foo", "bar"),
	//		db.PP("GET", "foo"),
	//	)
	Pipe(...*PipePart) ([]*redis.Resp, error)

	// Scan is a function which returns a channel to which keys matching the
	// given pattern are written to. The channel must be read from until it is
	// closed, which occurs when there are no more keys or when an error has
	// occurred (this error will be logged)
	//
	// This should not be used in any critical paths
	Scan(string) <-chan string

	// Lua performs one of the preloaded Lua scripts that have been built-in.
	// It's *possible* that the script wasn't loaded in initLuaScripts() for
	// some strange reason, this tries to handle that case as well. The integer
	// passed in is the number of keys the command takes in
	//
	// Example:
	//
	//	db.Lua(redisClient, "LREMRPUSH", 2, "foo", "bar", -1, "value")
	Lua(string, int, ...interface{}) *redis.Resp

	// GetAddr returns any valid address of a redis instance. Useful for cases
	// where we want to create redis connections external to this db package
	GetAddr() (string, error)
}

DBer is implemented and used by the rest of okq to interact with whatever backend has been chosen

var Inst DBer

Inst is an instance of DBer which is automatically initialized and which is what should be used by the rest of okq

type PipePart

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

PipePart is a single command to be run in a pipe. See Pipe for an example on usage

func PP

func PP(cmd string, args ...interface{}) *PipePart

PP should be called NewPipePart, but that's pretty verbose. It simple returns a new PipePart, to be used in a call to Pipe

Jump to

Keyboard shortcuts

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