goredis8

package module
v2.0.0-rc8 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package goredis8 is an implementation of trm.Transaction interface by Transaction for redis.UniversalClient.

Index

Constants

View Source
const (
	// DefaultMulti is a default value for Settings.IsMulti.
	DefaultMulti = true
)

Variables

DefaultCtxGetter is the CtxGetter with settings.DefaultCtxKey.

Functions

func NewDefaultFactory

func NewDefaultFactory(db redis.UniversalClient) trm.TrFactory

NewDefaultFactory creates default trm.Transaction(redis.UniversalClient).

Types

type Cmdable

type Cmdable interface {
	redis.Cmdable
	Watch
}

Cmdable is an experimental interface to Watch and Unwatch keys in Transaction.

func ReadOnlyFuncWithoutTxDecorator

func ReadOnlyFuncWithoutTxDecorator(write Cmdable, readOnly redis.Cmdable) Cmdable

ReadOnlyFuncWithoutTxDecorator is decorator, which calls readonly commands outside of the Transaction.

type CtxGetter

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

CtxGetter gets goredis8.Pipeliner from trm.СtxManager by casting trm.Transaction to redis.UniversalClient.

func NewCtxGetter

func NewCtxGetter(c trm.СtxManager) *CtxGetter

NewCtxGetter returns *CtxGetter to get Cmdable from context.Context.

func (*CtxGetter) DefaultTrOrDB

func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db redis.Cmdable) redis.Cmdable

DefaultTrOrDB returns Cmdable from context.Context or DB(goredis8.Cmdable) otherwise.

func (*CtxGetter) TrOrDB

func (c *CtxGetter) TrOrDB(ctx context.Context, key trm.CtxKey, db redis.Cmdable) redis.Cmdable

TrOrDB returns Cmdable from context.Context by trm.CtxKey or DB(goredis8.Cmdable) otherwise.

type Opt

type Opt func(*Settings) error

Opt is a type to configure Settings.

func WithMulti

func WithMulti(isMulti bool) Opt

WithMulti sets up sql.TxOptions for the Settings.

func WithRet

func WithRet(in *[]redis.Cmder) Opt

WithRet sets link on []redis.Cmder to get responses of commands in Transaction WARNING: Responses don't clean automatically, use WithRet only with DoWithSettings of trm.Manager.

func WithTxDecorator

func WithTxDecorator(in TxDecorator) Opt

WithTxDecorator sets TxDecorator to change behavior of Transaction.

func WithWatchKeys

func WithWatchKeys(keys ...string) Opt

WithWatchKeys sets WATCH keys in Transaction.

type Settings

type Settings struct {
	trm.Settings
	// contains filtered or unexported fields
}

Settings contains settings for redis.Transaction.

func MustSettings

func MustSettings(trms trm.Settings, oo ...Opt) Settings

MustSettings returns Settings if err is nil and panics otherwise.

func NewSettings

func NewSettings(trms trm.Settings, oo ...Opt) (Settings, error)

NewSettings creates Settings.

func (Settings) EnrichBy

func (s Settings) EnrichBy(in trm.Settings) trm.Settings

EnrichBy fills nil properties from external Settings.

func (Settings) IsMulti

func (s Settings) IsMulti() bool

IsMulti - true uses redis MULTI cmd.

func (Settings) IsMultiOrNil

func (s Settings) IsMultiOrNil() *bool

IsMultiOrNil returns IsMulti or nil.

func (Settings) Return

func (s Settings) Return() *[]redis.Cmder

Return returns []redis.Cmder from Transaction.

func (Settings) SetIsMulti

func (s Settings) SetIsMulti(in *bool) Settings

SetIsMulti set using or not Multi for transaction, see https://redis.uptrace.dev/guide/go-redis-pipelines.html#transactions.

func (Settings) SetReturn

func (s Settings) SetReturn(in *[]redis.Cmder) Settings

SetReturn sets link to save []redis.Cmder from Transaction.

func (Settings) SetTxDecorators

func (s Settings) SetTxDecorators(in ...TxDecorator) Settings

SetTxDecorators sets TxDecorator decorators.

func (Settings) SetWatchKeys

func (s Settings) SetWatchKeys(in []string) Settings

SetWatchKeys sets keys for watching, see https://redis.uptrace.dev/guide/go-redis-pipelines.html#watch.

func (Settings) TxDecorators

func (s Settings) TxDecorators() []TxDecorator

TxDecorators returns TxDecorator decorators.

func (Settings) WatchKeys

func (s Settings) WatchKeys() []string

WatchKeys returns keys for watching.

type Transaction

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

Transaction is trm.Transaction for sqlx.Tx.

func NewTransaction

func NewTransaction(
	ctx context.Context,
	db redis.UniversalClient,
	s Settings,
) (context.Context, *Transaction, error)

NewTransaction creates trm.Transaction for sqlx.Tx.

func (*Transaction) Commit

func (t *Transaction) Commit(_ context.Context) error

Commit closes the trm.Transaction.

func (*Transaction) IsActive

func (t *Transaction) IsActive() bool

IsActive returns true if the transaction started but not committed or rolled back.

func (*Transaction) Rollback

func (t *Transaction) Rollback(_ context.Context) error

Rollback the trm.Transaction.

func (*Transaction) Transaction

func (t *Transaction) Transaction() interface{}

Transaction returns the real transaction sqlx.Tx. trm.NestedTrFactory returns IsActive as true while trm.Transaction is opened.

type TxDecorator

type TxDecorator func(tx Cmdable, db redis.Cmdable) Cmdable

TxDecorator is an interface for Transaction.tx decoration.

type Watch

type Watch interface {
	Watch(ctx context.Context, keys ...string) *redis.StatusCmd
	Unwatch(ctx context.Context, keys ...string) *redis.StatusCmd
}

Watch is experimental functional for watching updated keys. See redis_test.Example_watch for example.

Jump to

Keyboard shortcuts

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