redis

package
v1.64.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package redis is an abstraction layer to access Redis with repositories and models.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoSuchEntity is returned from a Get operation when there is not a model
	// that matches the query
	ErrNoSuchEntity = errors.New("no such entity")

	ErrDone = errors.New("done")
)

Functions

func Mask added in v1.1.0

func Mask(cols ...string) []string

Types

type BooleanKV

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

func (*BooleanKV) Delete

func (kv *BooleanKV) Delete(ctx context.Context) error

func (*BooleanKV) Exists

func (kv *BooleanKV) Exists(ctx context.Context) (bool, error)

func (*BooleanKV) Get

func (kv *BooleanKV) Get(ctx context.Context) (bool, error)

func (*BooleanKV) Set

func (kv *BooleanKV) Set(ctx context.Context, value bool) error

func (*BooleanKV) SetTTL

func (kv *BooleanKV) SetTTL(ctx context.Context, value bool, ttl time.Duration) error

type Counter

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

func (*Counter) Decrement

func (c *Counter) Decrement(ctx context.Context) (int64, error)

func (*Counter) Get

func (c *Counter) Get(ctx context.Context) (int64, error)

func (*Counter) Increment

func (c *Counter) Increment(ctx context.Context) (int64, error)

func (*Counter) IncrementBy

func (c *Counter) IncrementBy(ctx context.Context, value int64) (int64, error)

func (*Counter) Set

func (c *Counter) Set(ctx context.Context, value int64) error

type Counters

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

func (*Counters) Key

func (counters *Counters) Key(key string) *Counter

type Database

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

Database keeps a connection to a Redis server.

func Open

func Open(hostname, applicationName string) *Database

Open a new database connection to the remote Redis server.

func (*Database) BooleanKV

func (db *Database) BooleanKV(key string) *BooleanKV

func (*Database) Close added in v1.1.0

func (db *Database) Close() error

Close the connection to the remote database.

func (*Database) Cmdable added in v1.40.0

func (db *Database) Cmdable(ctx context.Context) redis.Cmdable

Cmdable returns a reference to the direct Redis database connection. If context is inside a transaction it will return the Tx object instead. Both objects has the same Cmdable interface of the third party library.

func (*Database) Counters

func (db *Database) Counters(key string) *Counters

func (*Database) FlushAllKeysFromDatabase

func (db *Database) FlushAllKeysFromDatabase() error

FlushAllKeysFromDatabase is exposed as a simple way for tests to reset the local database. It is not intended to be run in production. It will clean up all the keys of the whole database and leav an empty canvas to fill again.

func (*Database) Hash added in v1.1.0

func (db *Database) Hash(name string, model Model) *Hash

Hash returns a hash instance that stores full models as individual hash keys.

func (*Database) Int32KV

func (db *Database) Int32KV(key string) *Int32KV

func (*Database) Int64KV

func (db *Database) Int64KV(key string) *Int64KV

func (*Database) Int64Set

func (db *Database) Int64Set(key string) *Int64Set

func (*Database) ProtoHash

func (db *Database) ProtoHash(key string) *ProtoHash

func (*Database) ProtoKV

func (db *Database) ProtoKV(key string) *ProtoKV

func (*Database) ProtoList

func (db *Database) ProtoList(key string) *ProtoList

func (*Database) PubSub

func (db *Database) PubSub(name string) *PubSub

PubSub returns an entrypoint to a PubSub queue in redisIt can be used to publish and receive protobuf messages.

func (*Database) StringKV

func (db *Database) StringKV(key string) *StringKV

func (*Database) StringsList

func (db *Database) StringsList(key string) *StringsList

func (*Database) StringsSet

func (db *Database) StringsSet(key string) *StringsSet

func (*Database) TimeKV

func (db *Database) TimeKV(key string) *TimeKV

func (*Database) Transaction added in v1.40.0

func (db *Database) Transaction(ctx context.Context, fn TransactionFn) error

Transaction runs fn inside a transaction. You have to use the new context for every operation, otherwise they won't be transactional.

type Hash added in v1.1.0

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

func (*Hash) Delete added in v1.2.0

func (hash *Hash) Delete(ctx context.Context, key string) error

Delete inmediately removes the key from the hash.

func (*Hash) ExpireAt added in v1.3.0

func (hash *Hash) ExpireAt(ctx context.Context, key string, t time.Time) error

ExpireAt sets the expiration of a key of this hash.

func (*Hash) Get added in v1.1.0

func (hash *Hash) Get(ctx context.Context, key string, instance Model, masks ...MaskOpt) error

func (*Hash) Put added in v1.1.0

func (hash *Hash) Put(ctx context.Context, key string, instance Model, masks ...MaskOpt) error

type Int32KV

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

func (*Int32KV) Delete

func (kv *Int32KV) Delete(ctx context.Context) error

func (*Int32KV) Exists

func (kv *Int32KV) Exists(ctx context.Context) (bool, error)

func (*Int32KV) Get

func (kv *Int32KV) Get(ctx context.Context) (int32, error)

func (*Int32KV) Set

func (kv *Int32KV) Set(ctx context.Context, value int32) error

func (*Int32KV) SetTTL

func (kv *Int32KV) SetTTL(ctx context.Context, value int32, ttl time.Duration) error

type Int64KV

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

func (*Int64KV) Delete

func (kv *Int64KV) Delete(ctx context.Context) error

func (*Int64KV) Exists

func (kv *Int64KV) Exists(ctx context.Context) (bool, error)

func (*Int64KV) Get

func (kv *Int64KV) Get(ctx context.Context) (int64, error)

func (*Int64KV) Set

func (kv *Int64KV) Set(ctx context.Context, value int64) error

func (*Int64KV) SetTTL

func (kv *Int64KV) SetTTL(ctx context.Context, value int64, ttl time.Duration) error

type Int64Set

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

func (*Int64Set) Add

func (set *Int64Set) Add(ctx context.Context, values ...int64) error

func (*Int64Set) Contains added in v1.29.0

func (set *Int64Set) Contains(ctx context.Context, value int64) (bool, error)

func (*Int64Set) Len

func (set *Int64Set) Len(ctx context.Context) (int64, error)

func (*Int64Set) Members

func (set *Int64Set) Members(ctx context.Context) ([]int64, error)

func (*Int64Set) Remove

func (set *Int64Set) Remove(ctx context.Context, values ...int64) error

type MaskOpt added in v1.1.0

type MaskOpt []string

type Model added in v1.1.0

type Model interface {
	// IsRedisModel should always return true.
	IsRedisModel() bool
}

Model should be implemented by any model that want to be serializable to redis keys.

type MultiError

type MultiError []error

MultiError is returned from batch operations with the error of each operation. If a batch operation does not fails this will be nil too.

func (MultiError) Error

func (merr MultiError) Error() string

Error returns the composed error message with all the individual ones.

func (MultiError) HasError

func (merr MultiError) HasError() bool

HasError checks if there is really an error on the list or all of them are empty.

type ProtoHash

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

func (*ProtoHash) Delete

func (hash *ProtoHash) Delete(ctx context.Context, key string) error

func (*ProtoHash) Get

func (hash *ProtoHash) Get(ctx context.Context, key string, model proto.Message) error

func (*ProtoHash) GetMulti

func (hash *ProtoHash) GetMulti(ctx context.Context, keys []string, result interface{}) error

GetMulti fetchs a list of keys from the hash. Result should be a slice of proto.Message that will be filled with the results in the same order as the keys.

func (*ProtoHash) PrepareInsert

func (hash *ProtoHash) PrepareInsert() *ProtoHashInsert

type ProtoHashInsert

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

func (*ProtoHashInsert) Commit

func (insert *ProtoHashInsert) Commit(ctx context.Context) error

func (*ProtoHashInsert) Set

func (insert *ProtoHashInsert) Set(ctx context.Context, key string, value proto.Message) error

type ProtoKV

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

ProtoKV interacts with a protobuf value key.

func (*ProtoKV) Delete

func (kv *ProtoKV) Delete(ctx context.Context) error

Delete the key.

func (*ProtoKV) Exists

func (kv *ProtoKV) Exists(ctx context.Context) (bool, error)

Exists checks if the key exists previously.

func (*ProtoKV) Get

func (kv *ProtoKV) Get(ctx context.Context, value proto.Message) error

Get decodes the value in the provided message.

func (*ProtoKV) Set

func (kv *ProtoKV) Set(ctx context.Context, value proto.Message) error

Set changes the value of the key.

func (*ProtoKV) SetTTL

func (kv *ProtoKV) SetTTL(ctx context.Context, value proto.Message, ttl time.Duration) error

SetTTL changes the value of the key with a Time-To-Live.

type ProtoList

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

func (*ProtoList) Add

func (list *ProtoList) Add(ctx context.Context, values ...proto.Message) error

func (*ProtoList) GetAll

func (list *ProtoList) GetAll(ctx context.Context, result interface{}) error

func (*ProtoList) GetRange

func (list *ProtoList) GetRange(ctx context.Context, start, end int64, result interface{}) error

func (*ProtoList) Len

func (list *ProtoList) Len(ctx context.Context) (int64, error)

func (*ProtoList) Remove

func (list *ProtoList) Remove(ctx context.Context, value proto.Message) error

type PubSub

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

PubSub represents a connection to a redis PubSub. It can be used to publish and receive protobuf messages.

func (*PubSub) Publish

func (pubsub *PubSub) Publish(ctx context.Context, msg proto.Message) error

Publish sends a new message to the server. Only subscription connected at the same time will receive the message.

func (*PubSub) Subscribe

func (pubsub *PubSub) Subscribe(ctx context.Context) *PubSubSubscription

Subscribe opens a new connection to the server and starts downloading messages.

type PubSubSubscription

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

PubSubSubscription stores the state of an active connection to the server.

func (*PubSubSubscription) Close

func (sub *PubSubSubscription) Close()

Close exits the connection.

func (*PubSubSubscription) Next

func (sub *PubSubSubscription) Next(dest proto.Message) error

Next waits for the next message and decodes it in the destination.

type StringKV

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

func (*StringKV) Delete

func (kv *StringKV) Delete(ctx context.Context) error

func (*StringKV) Exists

func (kv *StringKV) Exists(ctx context.Context) (bool, error)

func (*StringKV) Get

func (kv *StringKV) Get(ctx context.Context) (string, error)

func (*StringKV) Set

func (kv *StringKV) Set(ctx context.Context, value string) error

func (*StringKV) SetTTL

func (kv *StringKV) SetTTL(ctx context.Context, value string, ttl time.Duration) error

type StringsList

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

func (*StringsList) Add

func (list *StringsList) Add(ctx context.Context, values []string) error

func (*StringsList) GetAll

func (list *StringsList) GetAll(ctx context.Context) ([]string, error)

func (*StringsList) GetRange

func (list *StringsList) GetRange(ctx context.Context, start, end int64) ([]string, error)

func (*StringsList) Len

func (list *StringsList) Len(ctx context.Context) (int64, error)

func (*StringsList) Remove

func (list *StringsList) Remove(ctx context.Context, value string) error

type StringsSet

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

func (*StringsSet) Add

func (set *StringsSet) Add(ctx context.Context, values ...string) error

func (*StringsSet) Contains added in v1.29.0

func (set *StringsSet) Contains(ctx context.Context, value string) (bool, error)

func (*StringsSet) Len

func (set *StringsSet) Len(ctx context.Context) (int64, error)

func (*StringsSet) Members

func (set *StringsSet) Members(ctx context.Context) ([]string, error)

func (*StringsSet) Remove

func (set *StringsSet) Remove(ctx context.Context, values ...string) error

func (*StringsSet) SortAlpha

func (set *StringsSet) SortAlpha(ctx context.Context) ([]string, error)

type TimeKV

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

func (*TimeKV) Delete

func (kv *TimeKV) Delete(ctx context.Context) error

func (*TimeKV) Exists

func (kv *TimeKV) Exists(ctx context.Context) (bool, error)

func (*TimeKV) Get

func (kv *TimeKV) Get(ctx context.Context) (time.Time, error)

func (*TimeKV) Set

func (kv *TimeKV) Set(ctx context.Context, value time.Time) error

func (*TimeKV) SetTTL

func (kv *TimeKV) SetTTL(ctx context.Context, value time.Time, ttl time.Duration) error

type TransactionFn added in v1.40.0

type TransactionFn func(ctx context.Context) error

TransactionFn is a callback for transactions.

Jump to

Keyboard shortcuts

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