redis

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Addrs    []string
	Login    string
	Password string
	DBName   int
}

type DB

type DB struct {
	Exec redis.Cmdable
	// contains filtered or unexported fields
}

func New

func New(conf Config) (*DB, error)

New creates a new DB connection

func NewMock added in v0.0.15

func NewMock() (*DB, *redismock.ClientMock, error)

New creates a new mock client.

func (*DB) CacheGet added in v0.0.15

func (d *DB) CacheGet(ctx context.Context, key string, value interface{}) error

CacheGet gets a cached value Example:

var wanted Object
if err := mycache.Get(ctx, key, &wanted); err == nil {
    fmt.Println(wanted)
}

func (*DB) CacheOnce

func (d *DB) CacheOnce(cacheItem *cache.Item) error

CacheOnceItem makes a cache Once gets the item.Object for the given item.Key from the cache or executes, caches, and returns the results of the given item.Func, making sure that only one execution is in-flight for a given item.Key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results. Example:

CacheOnceItem(&cache.Item{
	Key:   "mykey",
	Value: obj, // destination
	Do: func(*cache.Item) (interface{}, error) {
		return &Object{
			Str: "mystring",
			Num: 42,
		}, nil
	},
})

func (*DB) CacheSet added in v0.0.15

func (d *DB) CacheSet(cacheItem *cache.Item) error

CacheSet sets a cache Example:

ctx := context.Background()
key := "mykey"
obj := &Object{
    Str: "mystring",
    Num: 42,
}

if err := mycache.Set(&cache.Item{
    Ctx:   ctx,
    Key:   key,
    Value: obj,
    TTL:   time.Hour,
}); err != nil {
    panic(err)
}

func (*DB) CacheStats added in v0.0.15

func (d *DB) CacheStats() *cache.Stats

func (*DB) Close

func (d *DB) Close() error

Close closes a client

func (*DB) DB

func (d *DB) DB() redis.Cmdable

DB returns an object for execution commands

type IDB

type IDB interface {
	DB() redis.Cmdable
	Close() error
	CacheSet(cacheItem *cache.Item) error
	CacheOnce(cacheItem *cache.Item) error
	CacheGet(ctx context.Context, key string, value interface{}) error
	CacheStats() *cache.Stats
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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