redisutils

package
v0.0.0-...-48c6f6e Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package redisutils is a generated GoMock package.

Index

Constants

View Source
const MAX_RETRIES = 5

Maximum number of retries for a transaction.

Variables

View Source
var ErrMaxRetryReachedOut = errors.New("max retries reached out")

Functions

func ComposeKey

func ComposeKey(keys ...string) string

ComposeKey concatenates multiple strings into a single Redis key, using ":" as a separator.

func WithTx

func WithTx(ctx context.Context, client RedisClient, fn func(pipe redis.Pipeliner) error) error

WithTx executes a Redis transaction with retry logic, allowing for concurrent-safe operations.

Types

type MockRedisClient

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

MockRedisClient is a mock of RedisClient interface.

func NewMockRedisClient

func NewMockRedisClient(ctrl *gomock.Controller) *MockRedisClient

NewMockRedisClient creates a new mock instance.

func (*MockRedisClient) Close

func (m *MockRedisClient) Close() error

Close mocks base method.

func (*MockRedisClient) Del

func (m *MockRedisClient) Del(ctx context.Context, keys ...string) *redis.IntCmd

Del mocks base method.

func (*MockRedisClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockRedisClient) Get

Get mocks base method.

func (*MockRedisClient) Ping

Ping mocks base method.

func (*MockRedisClient) Scan

func (m *MockRedisClient) Scan(ctx context.Context, cursor uint64, match string, count int64) *redis.ScanCmd

Scan mocks base method.

func (*MockRedisClient) Set

func (m *MockRedisClient) Set(ctx context.Context, key string, value any, expiration time.Duration) *redis.StatusCmd

Set mocks base method.

func (*MockRedisClient) TxPipelined

func (m *MockRedisClient) TxPipelined(ctx context.Context, fn func(redis.Pipeliner) error) ([]redis.Cmder, error)

TxPipelined mocks base method.

func (*MockRedisClient) Watch

func (m *MockRedisClient) Watch(ctx context.Context, fn func(*redis.Tx) error, keys ...string) error

Watch mocks base method.

type MockRedisClientMockRecorder

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

MockRedisClientMockRecorder is the mock recorder for MockRedisClient.

func (*MockRedisClientMockRecorder) Close

Close indicates an expected call of Close.

func (*MockRedisClientMockRecorder) Del

func (mr *MockRedisClientMockRecorder) Del(ctx any, keys ...any) *gomock.Call

Del indicates an expected call of Del.

func (*MockRedisClientMockRecorder) Get

func (mr *MockRedisClientMockRecorder) Get(ctx, key any) *gomock.Call

Get indicates an expected call of Get.

func (*MockRedisClientMockRecorder) Ping

func (mr *MockRedisClientMockRecorder) Ping(ctx any) *gomock.Call

Ping indicates an expected call of Ping.

func (*MockRedisClientMockRecorder) Scan

func (mr *MockRedisClientMockRecorder) Scan(ctx, cursor, match, count any) *gomock.Call

Scan indicates an expected call of Scan.

func (*MockRedisClientMockRecorder) Set

func (mr *MockRedisClientMockRecorder) Set(ctx, key, value, expiration any) *gomock.Call

Set indicates an expected call of Set.

func (*MockRedisClientMockRecorder) TxPipelined

func (mr *MockRedisClientMockRecorder) TxPipelined(ctx, fn any) *gomock.Call

TxPipelined indicates an expected call of TxPipelined.

func (*MockRedisClientMockRecorder) Watch

func (mr *MockRedisClientMockRecorder) Watch(ctx, fn any, keys ...any) *gomock.Call

Watch indicates an expected call of Watch.

type RedisClient

type RedisClient interface {
	Del(ctx context.Context, keys ...string) *redis.IntCmd
	Get(ctx context.Context, key string) *redis.StringCmd
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
	Scan(ctx context.Context, cursor uint64, match string, count int64) *redis.ScanCmd
	Watch(ctx context.Context, fn func(*redis.Tx) error, keys ...string) error
	Ping(ctx context.Context) *redis.StatusCmd
	TxPipelined(ctx context.Context, fn func(redis.Pipeliner) error) ([]redis.Cmder, error)
	Close() error
}

RedisClient defines an interface for interacting with a Redis database. It abstracts common Redis operations to allow flexibility in implementation.

type Storage

type Storage struct {
	Client  RedisClient
	Client2 *redis.Client
}

Storage encapsulates a Redis client, providing methods for initialization and cleanup.

func New

func New(client RedisClient) (*Storage, error)

New initializes a new Storage instance with the given Redis client and verifies the connection.

func (*Storage) Cleanup

func (s *Storage) Cleanup() error

Cleanup closes the Redis client connection, releasing any allocated resources.

Jump to

Keyboard shortcuts

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