Documentation ¶
Overview ¶
Package redis is an abstraction layer to access Redis with repositories and models.
Index ¶
- Variables
- func Mask(cols ...string) []string
- type BooleanKV
- func (kv *BooleanKV) Delete(ctx context.Context) error
- func (kv *BooleanKV) Exists(ctx context.Context) (bool, error)
- func (kv *BooleanKV) Get(ctx context.Context) (bool, error)
- func (kv *BooleanKV) Set(ctx context.Context, value bool) error
- func (kv *BooleanKV) SetTTL(ctx context.Context, value bool, ttl time.Duration) error
- type Counter
- func (c *Counter) Decrement(ctx context.Context) (int64, error)
- func (c *Counter) Get(ctx context.Context) (int64, error)
- func (c *Counter) Increment(ctx context.Context) (int64, error)
- func (c *Counter) IncrementBy(ctx context.Context, value int64) (int64, error)
- func (c *Counter) Set(ctx context.Context, value int64) error
- type Counters
- type Database
- func (db *Database) BooleanKV(key string) *BooleanKV
- func (db *Database) Close() error
- func (db *Database) Cmdable(ctx context.Context) redis.Cmdable
- func (db *Database) Counters(key string) *Counters
- func (db *Database) FlushAllKeysFromDatabase() error
- func (db *Database) Hash(name string, model Model) *Hash
- func (db *Database) Int32KV(key string) *Int32KV
- func (db *Database) Int64KV(key string) *Int64KV
- func (db *Database) Int64Set(key string) *Int64Set
- func (db *Database) ProtoHash(key string) *ProtoHash
- func (db *Database) ProtoKV(key string) *ProtoKV
- func (db *Database) ProtoList(key string) *ProtoList
- func (db *Database) PubSub(name string) *PubSub
- func (db *Database) StringKV(key string) *StringKV
- func (db *Database) StringsList(key string) *StringsList
- func (db *Database) StringsSet(key string) *StringsSet
- func (db *Database) TimeKV(key string) *TimeKV
- func (db *Database) Transaction(ctx context.Context, fn TransactionFn) error
- type Hash
- func (hash *Hash) Delete(ctx context.Context, key string) error
- func (hash *Hash) ExpireAt(ctx context.Context, key string, t time.Time) error
- func (hash *Hash) Get(ctx context.Context, key string, instance Model, masks ...MaskOpt) error
- func (hash *Hash) Put(ctx context.Context, key string, instance Model, masks ...MaskOpt) error
- type Int32KV
- func (kv *Int32KV) Delete(ctx context.Context) error
- func (kv *Int32KV) Exists(ctx context.Context) (bool, error)
- func (kv *Int32KV) Get(ctx context.Context) (int32, error)
- func (kv *Int32KV) Set(ctx context.Context, value int32) error
- func (kv *Int32KV) SetTTL(ctx context.Context, value int32, ttl time.Duration) error
- type Int64KV
- func (kv *Int64KV) Delete(ctx context.Context) error
- func (kv *Int64KV) Exists(ctx context.Context) (bool, error)
- func (kv *Int64KV) Get(ctx context.Context) (int64, error)
- func (kv *Int64KV) Set(ctx context.Context, value int64) error
- func (kv *Int64KV) SetTTL(ctx context.Context, value int64, ttl time.Duration) error
- type Int64Set
- func (set *Int64Set) Add(ctx context.Context, values ...int64) error
- func (set *Int64Set) Contains(ctx context.Context, value int64) (bool, error)
- func (set *Int64Set) Len(ctx context.Context) (int64, error)
- func (set *Int64Set) Members(ctx context.Context) ([]int64, error)
- func (set *Int64Set) Remove(ctx context.Context, values ...int64) error
- type MaskOpt
- type Model
- type MultiError
- type ProtoHash
- func (hash *ProtoHash) Delete(ctx context.Context, key string) error
- func (hash *ProtoHash) Get(ctx context.Context, key string, model proto.Message) error
- func (hash *ProtoHash) GetMulti(ctx context.Context, keys []string, result interface{}) error
- func (hash *ProtoHash) PrepareInsert() *ProtoHashInsert
- type ProtoHashInsert
- type ProtoKV
- func (kv *ProtoKV) Delete(ctx context.Context) error
- func (kv *ProtoKV) Exists(ctx context.Context) (bool, error)
- func (kv *ProtoKV) Get(ctx context.Context, value proto.Message) error
- func (kv *ProtoKV) Set(ctx context.Context, value proto.Message) error
- func (kv *ProtoKV) SetTTL(ctx context.Context, value proto.Message, ttl time.Duration) error
- type ProtoList
- func (list *ProtoList) Add(ctx context.Context, values ...proto.Message) error
- func (list *ProtoList) GetAll(ctx context.Context, result interface{}) error
- func (list *ProtoList) GetRange(ctx context.Context, start, end int64, result interface{}) error
- func (list *ProtoList) Len(ctx context.Context) (int64, error)
- func (list *ProtoList) Remove(ctx context.Context, value proto.Message) error
- type PubSub
- type PubSubSubscription
- type StringKV
- func (kv *StringKV) Delete(ctx context.Context) error
- func (kv *StringKV) Exists(ctx context.Context) (bool, error)
- func (kv *StringKV) Get(ctx context.Context) (string, error)
- func (kv *StringKV) Set(ctx context.Context, value string) error
- func (kv *StringKV) SetTTL(ctx context.Context, value string, ttl time.Duration) error
- type StringsList
- func (list *StringsList) Add(ctx context.Context, values []string) error
- func (list *StringsList) GetAll(ctx context.Context) ([]string, error)
- func (list *StringsList) GetRange(ctx context.Context, start, end int64) ([]string, error)
- func (list *StringsList) Len(ctx context.Context) (int64, error)
- func (list *StringsList) Remove(ctx context.Context, value string) error
- type StringsSet
- func (set *StringsSet) Add(ctx context.Context, values ...string) error
- func (set *StringsSet) Contains(ctx context.Context, value string) (bool, error)
- func (set *StringsSet) Len(ctx context.Context) (int64, error)
- func (set *StringsSet) Members(ctx context.Context) ([]string, error)
- func (set *StringsSet) Remove(ctx context.Context, values ...string) error
- func (set *StringsSet) SortAlpha(ctx context.Context) ([]string, error)
- type TimeKV
- func (kv *TimeKV) Delete(ctx context.Context) error
- func (kv *TimeKV) Exists(ctx context.Context) (bool, error)
- func (kv *TimeKV) Get(ctx context.Context) (time.Time, error)
- func (kv *TimeKV) Set(ctx context.Context, value time.Time) error
- func (kv *TimeKV) SetTTL(ctx context.Context, value time.Time, ttl time.Duration) error
- type TransactionFn
Constants ¶
This section is empty.
Variables ¶
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 ¶
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
func (*Counter) IncrementBy ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database keeps a connection to a Redis server.
func (*Database) Cmdable ¶ added in v1.40.0
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) FlushAllKeysFromDatabase ¶
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
Hash returns a hash instance that stores full models as individual hash keys.
func (*Database) PubSub ¶
PubSub returns an entrypoint to a PubSub queue in redisIt can be used to publish and receive protobuf messages.
func (*Database) StringsList ¶
func (db *Database) StringsList(key string) *StringsList
func (*Database) StringsSet ¶
func (db *Database) StringsSet(key string) *StringsSet
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
}
type Int64Set ¶
type Int64Set struct {
// contains filtered or unexported fields
}
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) GetMulti ¶
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
}
type ProtoKV ¶
type ProtoKV struct {
// contains filtered or unexported fields
}
ProtoKV interacts with a protobuf value key.
type ProtoList ¶
type ProtoList struct {
// contains filtered or unexported fields
}
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.
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.
type StringsList ¶
type StringsList struct {
// contains filtered or unexported fields
}
type StringsSet ¶
type StringsSet struct {
// contains filtered or unexported fields
}
type TransactionFn ¶ added in v1.40.0
TransactionFn is a callback for transactions.