redis

package module
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2018 License: MIT Imports: 8 Imported by: 0

README

redis

GoDoc Build Status

Abstraction layer to access Redis with repositories and models.

Install
go get github.com/altipla-consulting/redis
Usage

Repository file:

package models

import (
  "fmt"

  "github.com/altipla-consulting/redis"
)

var Repo *MainDatabase

func ConnectRepo() error {
  Repo = &MainDatabase{
    sess: redis.Open("redis:6379", "cells"),
  }

  return nil
}

type MainDatabase struct {
  sess *redis.Database
}

func (repo *MainDatabase) Offers(hotel int64) *redis.ProtoHash {
  return repo.sess.ProtoHash(fmt.Sprintf("hotel:%d", hotel))
}

func (repo *MainDatabase) CloseOffers() *redis.Queue {
  return repo.sess.Queue("close-offers")
}

Usage:

func run() error {
  offers := []*pbmodels.Offer{}
  if err := models.Repo.Offers(in.Hotel).GetMulti(codes, &offers); err != nil {
    return err
  }
}
Contributing

You can make pull requests or create issues in GitHub. Any code you send should be formatted using gofmt.

Running tests

Run the tests

make test
License

MIT License

Documentation

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 = fmt.Errorf("redis: no such entity")
)

Functions

This section is empty.

Types

type BooleanKV added in v1.0.0

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

func (*BooleanKV) Delete added in v1.4.0

func (kv *BooleanKV) Delete() error

func (*BooleanKV) Exists added in v1.0.0

func (kv *BooleanKV) Exists() (bool, error)

func (*BooleanKV) Get added in v1.0.0

func (kv *BooleanKV) Get() (bool, error)

func (*BooleanKV) Set added in v1.0.0

func (kv *BooleanKV) Set(value bool) error

func (*BooleanKV) SetTTL added in v1.1.0

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

type Counter

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

func (*Counter) Decrement

func (c *Counter) Decrement() error

func (*Counter) Get

func (c *Counter) Get() (int64, error)

func (*Counter) Increment

func (c *Counter) Increment() error

func (*Counter) IncrementBy

func (c *Counter) IncrementBy(value int64) error

func (*Counter) Set

func (c *Counter) Set(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 added in v1.0.0

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

func (*Database) Counters

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

func (*Database) DirectClient added in v1.0.0

func (db *Database) DirectClient() *redis.Client

DirectClient returns the underlying client of go-redis to call advanced methods not exposed through this library. Please consider to add the functionality here after it's tested to improve all the users of the library.

func (*Database) FlushAllKeysFromDatabase added in v1.2.0

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

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

func (*Database) Int64KV added in v1.3.0

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

func (*Database) Int64Set added in v1.7.0

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 added in v1.7.0

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

func (*Database) PubSub added in v1.11.0

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 added in v1.9.1

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

func (*Database) StringsSet added in v1.7.0

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

func (*Database) TimeKV added in v1.6.0

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

type Int32KV

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

func (*Int32KV) Delete added in v1.4.0

func (kv *Int32KV) Delete() error

func (*Int32KV) Exists

func (kv *Int32KV) Exists() (bool, error)

func (*Int32KV) Get

func (kv *Int32KV) Get() (int32, error)

func (*Int32KV) Set

func (kv *Int32KV) Set(value int32) error

func (*Int32KV) SetTTL added in v1.1.0

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

type Int64KV added in v1.3.0

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

func (*Int64KV) Delete added in v1.4.0

func (kv *Int64KV) Delete() error

func (*Int64KV) Exists added in v1.3.0

func (kv *Int64KV) Exists() (bool, error)

func (*Int64KV) Get added in v1.3.0

func (kv *Int64KV) Get() (int64, error)

func (*Int64KV) Set added in v1.3.0

func (kv *Int64KV) Set(value int64) error

func (*Int64KV) SetTTL added in v1.3.0

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

type Int64Set added in v1.7.0

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

func (*Int64Set) Add added in v1.7.0

func (set *Int64Set) Add(values ...int64) error

func (*Int64Set) Len added in v1.8.0

func (set *Int64Set) Len() (int64, error)

func (*Int64Set) Members added in v1.7.0

func (set *Int64Set) Members() ([]int64, error)

func (*Int64Set) Remove added in v1.7.0

func (set *Int64Set) Remove(values ...int64) error

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 added in v1.5.0

func (hash *ProtoHash) Delete(key string) error

func (*ProtoHash) Get

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

func (*ProtoHash) GetMulti

func (hash *ProtoHash) GetMulti(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() error

func (*ProtoHashInsert) Set

func (insert *ProtoHashInsert) Set(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 added in v1.4.0

func (kv *ProtoKV) Delete() error

Delete the key.

func (*ProtoKV) Exists

func (kv *ProtoKV) Exists() (bool, error)

Exists checks if the key exists previously.

func (*ProtoKV) Get

func (kv *ProtoKV) Get(value proto.Message) error

Get decodes the value in the provided message.

func (*ProtoKV) Set

func (kv *ProtoKV) Set(value proto.Message) error

Set changes the value of the key.

func (*ProtoKV) SetTTL added in v1.1.0

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

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

type ProtoList added in v1.7.0

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

func (*ProtoList) Add added in v1.7.0

func (list *ProtoList) Add(values ...proto.Message) error

func (*ProtoList) GetAll added in v1.7.0

func (list *ProtoList) GetAll(result interface{}) error

func (*ProtoList) GetRange added in v1.9.0

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

func (*ProtoList) Len added in v1.7.0

func (list *ProtoList) Len() (int64, error)

func (*ProtoList) Remove added in v1.10.0

func (list *ProtoList) Remove(value proto.Message) error

type PubSub added in v1.11.0

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 added in v1.11.0

func (pubsub *PubSub) Publish(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 added in v1.11.0

func (pubsub *PubSub) Subscribe() *PubSubSubscription

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

type PubSubSubscription added in v1.11.0

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

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

func (*PubSubSubscription) Close added in v1.11.0

func (sub *PubSubSubscription) Close()

Close exits the connection.

func (*PubSubSubscription) Next added in v1.11.0

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 added in v1.4.0

func (kv *StringKV) Delete() error

func (*StringKV) Exists

func (kv *StringKV) Exists() (bool, error)

func (*StringKV) Get

func (kv *StringKV) Get() (string, error)

func (*StringKV) Set

func (kv *StringKV) Set(value string) error

func (*StringKV) SetTTL added in v1.1.0

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

type StringsList added in v1.9.0

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

func (*StringsList) Add added in v1.9.0

func (list *StringsList) Add(values []string) error

func (*StringsList) GetAll added in v1.9.0

func (list *StringsList) GetAll() ([]string, error)

func (*StringsList) GetRange added in v1.9.0

func (list *StringsList) GetRange(start, end int64) ([]string, error)

func (*StringsList) Len added in v1.9.0

func (list *StringsList) Len() (int64, error)

func (*StringsList) Remove added in v1.10.0

func (list *StringsList) Remove(value string) error

type StringsSet added in v1.7.0

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

func (*StringsSet) Add added in v1.7.0

func (set *StringsSet) Add(values ...string) error

func (*StringsSet) Len added in v1.8.0

func (set *StringsSet) Len() (int64, error)

func (*StringsSet) Members added in v1.7.0

func (set *StringsSet) Members() ([]string, error)

func (*StringsSet) Remove added in v1.7.0

func (set *StringsSet) Remove(values ...string) error

func (*StringsSet) SortAlpha added in v1.7.0

func (set *StringsSet) SortAlpha() ([]string, error)

type TimeKV added in v1.6.0

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

func (*TimeKV) Delete added in v1.6.0

func (kv *TimeKV) Delete() error

func (*TimeKV) Exists added in v1.6.0

func (kv *TimeKV) Exists() (bool, error)

func (*TimeKV) Get added in v1.6.0

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

func (*TimeKV) Set added in v1.6.0

func (kv *TimeKV) Set(value time.Time) error

func (*TimeKV) SetTTL added in v1.6.0

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

Jump to

Keyboard shortcuts

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