redisx

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NilRedis string = "redis: nil"

NilRedis ...

Functions

This section is empty.

Types

type Client

type Client struct {
	*redis.Client
}

Client is the internal Redis Client

type ClientAPI

type ClientAPI interface {
	Ping() *redis.StatusCmd
	Close() error
	HDel(string, ...string) *redis.IntCmd
	Get(string) *redis.StringCmd
	HGet(string, string) *redis.StringCmd
	HGetAll(string) *redis.StringStringMapCmd
	Keys(string) *redis.StringSliceCmd
	Scan(uint64, string, int64) *redis.ScanCmd
	Incr(string) *redis.IntCmd
	Set(string, interface{}, time.Duration) *redis.StatusCmd
	HSet(string, ...interface{}) *redis.IntCmd
}

ClientAPI is the internal Client API interface

func GetClient

func GetClient(ctx context.Context, r *RedisDB) ClientAPI

GetClient return the redis client recorded or create a new instance

type MockClient

type MockClient struct {
	ClientAPI
	PingErr      error
	HDelErr      error
	GetValue     string
	GetErr       error
	HGetValue    string
	HGetErr      error
	HGetAllValue map[string]string
	HGetAllErr   error
	KeysValue    []string
	KeysErr      error
	ScanValue    []string
	ScanCursor   uint64
	ScanErr      error
	IncrValue    int64
	IncrErr      error
	SetValue     string
	SetErr       error
	HSetValue    int64
	HSetErr      error
}

MockClient is the internal mock client

func (*MockClient) Close

func (r *MockClient) Close() error

Close is an internal mock method

func (*MockClient) Get

func (r *MockClient) Get(key string) *redis.StringCmd

Get is an internal mock method

func (*MockClient) HDel

func (r *MockClient) HDel(key string, fields ...string) *redis.IntCmd

HDel is an internal mock method

func (*MockClient) HGet

func (r *MockClient) HGet(key string, field string) *redis.StringCmd

HGet is an internal mock method

func (*MockClient) HGetAll

func (r *MockClient) HGetAll(key string) *redis.StringStringMapCmd

HGetAll is an internal mock method

func (*MockClient) HSet

func (r *MockClient) HSet(key string, values ...interface{}) *redis.IntCmd

HSet is an internal mock method

func (*MockClient) Incr

func (r *MockClient) Incr(key string) *redis.IntCmd

Incr is an internal mock method

func (*MockClient) Keys

func (r *MockClient) Keys(pattern string) *redis.StringSliceCmd

Keys is an internal mock method

func (*MockClient) Ping

func (r *MockClient) Ping() *redis.StatusCmd

Ping is an internal mock method

func (*MockClient) Scan

func (r *MockClient) Scan(cursor uint64, match string, count int64) *redis.ScanCmd

Scan is an internal mock method

func (*MockClient) Set

func (r *MockClient) Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd

Set is an internal mock method

type Redis

type Redis struct {
	AddressSvc string `mapstructure:"address"`
	Port       string `mapstructure:"port"`
	Password   string `mapstructure:"password"`
	DB         int    `mapstructure:"db"`
}

Redis connexion struct

func (*Redis) New

func (cfg *Redis) New() RedisAPI

New return a redis instance

type RedisAPI

type RedisAPI interface {
	Connect() error
	// Set set a key/value with an expiry duration, after this duration the key/value is deleted from redis
	Set(ctx context.Context, key string, expiry time.Duration, data interface{}) error
	// HSet ...
	HSet(ctx context.Context, key string, field string, data interface{}) error
	// HDel ...
	HDel(ctx context.Context, key string, fields ...string) error
	// Get ...
	Get(ctx context.Context, key string) (string, error)
	// HGet ...
	HGet(ctx context.Context, key string, field string, response interface{}) error
	// HGetAll ...
	HGetAll(ctx context.Context, key string) (map[string]string, error)
	// Keys return all keys from redis if the pattern is set to "*", not safe, use Scan instead
	Keys(ctx context.Context, pattern string) ([]string, error)
	// Scan returns every keys from a redis database safely
	Scan(ctx context.Context, match string, count int) (map[string]string, error)
	// Incr ...
	Incr(ctx context.Context, key string) (int64, error)
}

RedisAPI is the public Redis API interface

type RedisDB

type RedisDB struct {
	ClientAPI
	// contains filtered or unexported fields
}

RedisDB is the public Redis Instance

func (*RedisDB) Connect

func (r *RedisDB) Connect() error

Connect public client to the internal client

func (*RedisDB) Get

func (r *RedisDB) Get(ctx context.Context, key string) (string, error)

Get ...

func (*RedisDB) HDel

func (r *RedisDB) HDel(ctx context.Context, key string, fields ...string) error

HDel ...

func (*RedisDB) HGet

func (r *RedisDB) HGet(ctx context.Context, key string, field string, response interface{}) error

HGet ...

func (*RedisDB) HGetAll

func (r *RedisDB) HGetAll(ctx context.Context, key string) (map[string]string, error)

HGetAll ...

func (*RedisDB) HSet

func (r *RedisDB) HSet(ctx context.Context, key string, field string, data interface{}) error

HSet ...

func (*RedisDB) Incr

func (r *RedisDB) Incr(ctx context.Context, key string) (int64, error)

Incr ...

func (*RedisDB) Keys

func (r *RedisDB) Keys(ctx context.Context, pattern string) ([]string, error)

Keys return all keys from redis if the pattern is set to "*", not safe, use Scan instead

func (*RedisDB) Scan

func (r *RedisDB) Scan(ctx context.Context, match string, count int) (map[string]string, error)

Scan returns every keys from a redis database safely

func (*RedisDB) Set

func (r *RedisDB) Set(ctx context.Context, key string, expiry time.Duration, data interface{}) error

Set set a key/value with an expiry duration, after this duration the key/value is deleted from redis

Jump to

Keyboard shortcuts

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