redis

package
v1.2.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PingError          error
	DoError            error
	SetError           error
	HSetError          error
	PExpireError       error
	ExistsError        error
	ExistsValue        int64
	GetError           error
	GetValue           string
	HGetAllError       error
	HGetAllMap         map[string]string
	SubscribePubSub    *redis.PubSub
	PubSubReceiveError error
	PublishError       error
)

Functions

func InitializeContext

func InitializeContext(ctx context.Context) context.Context

InitializeContext adds the redis session to the context. The new context is returned because context is immutable.

Types

type ClientFunctions added in v0.16.0

type ClientFunctions interface {
	Ping(ctx context.Context, client *redis.Client) error
	Do(ctx context.Context, client *redis.Client, op string, db int) error
	Set(
		ctx context.Context,
		client *redis.Client,
		key string,
		value interface{},
		expiration time.Duration,
	) error
	HSet(
		ctx context.Context,
		client *redis.Client,
		key string,
		values ...interface{},
	) error
	PExpire(
		ctx context.Context,
		client *redis.Client,
		key string,
		expiration time.Duration,
	) error
	Exists(
		ctx context.Context,
		client *redis.Client,
		keys ...string,
	) (int64, error)
	Get(
		ctx context.Context,
		client *redis.Client,
		key string,
	) (string, error)
	HGetAll(
		ctx context.Context,
		client *redis.Client,
		key string,
	) (map[string]string, error)
	Subscribe(
		ctx context.Context,
		client *redis.Client,
		channels ...string,
	) *redis.PubSub
	PubSubReceive(
		ctx context.Context,
		pubSub *redis.PubSub,
	) (interface{}, error)
	PubSubChannel(
		pubSub *redis.PubSub,
	) <-chan *redis.Message
	Publish(ctx context.Context,
		client *redis.Client,
		channel string,
		message interface{},
	) error
	PubSubClose(pubSub *redis.PubSub) error
}

type ClientService added in v0.16.0

type ClientService struct{}

func NewRedisClientService added in v0.16.0

func NewRedisClientService() *ClientService

func (ClientService) Do added in v0.16.0

func (c ClientService) Do(ctx context.Context, client *redis.Client, op string, db int) error

func (ClientService) Exists added in v0.16.0

func (c ClientService) Exists(ctx context.Context,
	client *redis.Client,
	keys ...string,
) (int64, error)

func (ClientService) Get added in v0.16.0

func (c ClientService) Get(
	ctx context.Context,
	client *redis.Client,
	key string,
) (string, error)

func (ClientService) HGetAll added in v0.16.0

func (c ClientService) HGetAll(
	ctx context.Context,
	client *redis.Client,
	key string,
) (map[string]string, error)

func (ClientService) HSet added in v0.16.0

func (c ClientService) HSet(
	ctx context.Context,
	client *redis.Client,
	key string,
	values ...interface{},
) error

func (ClientService) PExpire added in v0.16.0

func (c ClientService) PExpire(
	ctx context.Context,
	client *redis.Client,
	key string,
	expiration time.Duration,
) error

func (ClientService) Ping added in v0.16.0

func (c ClientService) Ping(ctx context.Context, client *redis.Client) error

func (ClientService) PubSubChannel added in v0.16.0

func (c ClientService) PubSubChannel(
	pubSub *redis.PubSub,
) <-chan *redis.Message

func (ClientService) PubSubClose added in v0.16.0

func (c ClientService) PubSubClose(pubSub *redis.PubSub) error

func (ClientService) PubSubReceive added in v0.16.0

func (c ClientService) PubSubReceive(
	ctx context.Context,
	pubSub *redis.PubSub,
) (interface{}, error)

func (ClientService) Publish added in v0.16.0

func (c ClientService) Publish(ctx context.Context,
	client *redis.Client,
	channel string,
	message interface{},
) error

func (ClientService) Set added in v0.16.0

func (c ClientService) Set(
	ctx context.Context,
	client *redis.Client,
	key string,
	value interface{},
	expiration time.Duration,
) error

func (ClientService) Subscribe added in v0.16.0

func (c ClientService) Subscribe(
	ctx context.Context,
	client *redis.Client,
	channels ...string,
) *redis.PubSub

type ClientServiceFuncMock added in v0.16.0

type ClientServiceFuncMock struct{}

func (ClientServiceFuncMock) Do added in v0.16.0

func (c ClientServiceFuncMock) Do(
	ctx context.Context,
	client *redis.Client, op string,
	db int,
) error

func (ClientServiceFuncMock) Exists added in v0.16.0

func (c ClientServiceFuncMock) Exists(
	ctx context.Context,
	client *redis.Client,
	keys ...string,
) (int64, error)

func (ClientServiceFuncMock) Get added in v0.16.0

func (c ClientServiceFuncMock) Get(
	ctx context.Context,
	client *redis.Client,
	key string,
) (string, error)

func (ClientServiceFuncMock) HGetAll added in v0.16.0

func (c ClientServiceFuncMock) HGetAll(
	ctx context.Context,
	client *redis.Client,
	key string,
) (map[string]string, error)

func (ClientServiceFuncMock) HSet added in v0.16.0

func (c ClientServiceFuncMock) HSet(
	ctx context.Context,
	client *redis.Client,
	key string,
	values ...interface{},
) error

func (ClientServiceFuncMock) PExpire added in v0.16.0

func (c ClientServiceFuncMock) PExpire(
	ctx context.Context,
	client *redis.Client,
	key string,
	expiration time.Duration,
) error

func (ClientServiceFuncMock) Ping added in v0.16.0

func (c ClientServiceFuncMock) Ping(ctx context.Context, client *redis.Client) error

func (ClientServiceFuncMock) PubSubChannel added in v0.16.0

func (c ClientServiceFuncMock) PubSubChannel(
	pubSub *redis.PubSub,
) <-chan *redis.Message

func (ClientServiceFuncMock) PubSubClose added in v0.16.0

func (c ClientServiceFuncMock) PubSubClose(pubSub *redis.PubSub) error

func (ClientServiceFuncMock) PubSubReceive added in v0.16.0

func (c ClientServiceFuncMock) PubSubReceive(
	ctx context.Context,
	pubSub *redis.PubSub,
) (interface{}, error)

func (ClientServiceFuncMock) Publish added in v0.16.0

func (c ClientServiceFuncMock) Publish(ctx context.Context,
	client *redis.Client,
	channel string,
	message interface{},
) error

func (ClientServiceFuncMock) Set added in v0.16.0

func (c ClientServiceFuncMock) Set(
	ctx context.Context,
	client *redis.Client,
	key string,
	value interface{},
	expiration time.Duration,
) error

func (ClientServiceFuncMock) Subscribe added in v0.16.0

func (c ClientServiceFuncMock) Subscribe(
	ctx context.Context,
	client *redis.Client,
	channels ...string,
) *redis.PubSub

type ContextKey

type ContextKey string

ContextKey defines a type to store the redis session in context.Context.

type Logger

type Logger struct {
	Log *golium.Logger
}

Logger logs in a configurable file.

func GetLogger

func GetLogger() *Logger

GetLogger returns the logger for HTTP requests and responses. If the logger is not created yet, it creates a new instance of Logger.

func (Logger) LogExistsKey

func (l Logger) LogExistsKey(key string, exits int, corr string)

LogExistsKey logs a redis EXISTS command.

func (Logger) LogGetKey

func (l Logger) LogGetKey(key, value, corr string)

LogGetKey logs a redis GET command.

func (Logger) LogHGetKey

func (l Logger) LogHGetKey(key string, value interface{}, corr string)

LogHGetKey logs a redis HGET command.

func (Logger) LogHSetKey

func (l Logger) LogHSetKey(key string, value interface{}, corr string)

LogHSetKey logs a redis HSET command.

func (Logger) LogPublishedMessage

func (l Logger) LogPublishedMessage(msg, topic, corr string)

LogPublishedMessage logs a redis message published to a topic.

func (Logger) LogReceivedMessage

func (l Logger) LogReceivedMessage(msg, topic, corr string)

LogReceivedMessage logs a redis message received from a topic.

func (Logger) LogSetKey

func (l Logger) LogSetKey(key, value, corr string)

LogSetKey logs a redis SET command.

type Session

type Session struct {
	Client *redis.Client
	// Messages received from the publish/subscribe channel
	Messages []string
	// Correlator is used to correlate the messages for a specific session
	Correlator string
	// Time to live (in milliseconds). If 0, there is no TTL configured for new records
	TTL int

	RedisClientService ClientFunctions
	// contains filtered or unexported fields
}

Session contains the information of a redis session.

func GetSession

func GetSession(ctx context.Context) *Session

GetSession returns the redis session stored in context. Note that the context should be previously initialized with InitializeContext function.

func (*Session) ConfigureClient

func (s *Session) ConfigureClient(ctx context.Context, options *redis.Options) error

ConfigureClient creates a redis client based on the configuration in options.

func (*Session) ConfigureTTL

func (s *Session) ConfigureTTL(ctx context.Context, ttl int)

ConfigureTTL saves TTL (in milliseconds) to apply when setting a value in redis.

func (*Session) PublishJSONMessage

func (s *Session) PublishJSONMessage(
	ctx context.Context,
	topic string,
	props map[string]interface{},
) error

PublishJSONMessage publishes a JSON message in a redis topic.

func (*Session) PublishTextMessage

func (s *Session) PublishTextMessage(ctx context.Context, topic, message string) error

PublishTextMessage publishes a text message in a redis topic.

func (*Session) SelectDatabase

func (s *Session) SelectDatabase(ctx context.Context, db int) error

SelectDatabase select redis database for current connection

func (*Session) SetHashValue

func (s *Session) SetHashValue(
	ctx context.Context,
	key string, value map[string]interface{},
) error

SetHashValue sets a redis key with a mapped value. It uses session TTL to establish an expiration time (no expiration if TTL is 0).

func (*Session) SetJSONValue

func (s *Session) SetJSONValue(
	ctx context.Context,
	key string, props map[string]interface{},
) error

SetJSONValue sets a redis key with a JSON document extracted from a table of properties.

func (*Session) SetTextValue

func (s *Session) SetTextValue(ctx context.Context, key, value string) error

SetTextValue sets a redis key with a text value. It uses session TTL to establish an expiration time (no expiration if TTL is 0).

func (*Session) SubscribeTopic

func (s *Session) SubscribeTopic(ctx context.Context, topic string) error

SubscribeTopic subscribes to a redis topic to receive messages via a channel.

func (*Session) UnsubscribeTopic

func (s *Session) UnsubscribeTopic(ctx context.Context, topic string) error

UnsubscribeTopic unsubscribes from a redis topic to stop receiving messages via a channel. The channel is closed. If this method is not invoked, then the goroutine created with SubscribeTopic is never closed and will permanently process messages from the topic until the program is finished.

func (*Session) ValidateHashValue

func (s *Session) ValidateHashValue(
	ctx context.Context,
	key string,
	props map[string]interface{},
) error

ValidateHashValue checks if the mapped value for a redis key equals the expected value. It uses session TTL to establish an expiration time (no expiration if TTL is 0).

func (*Session) ValidateJSONValue

func (s *Session) ValidateJSONValue(
	ctx context.Context,
	key string,
	props map[string]interface{},
) error

ValidateJSONValue checks if the JSON value for a redis key complies with the table of properties.

func (*Session) ValidateNonExistantKey

func (s *Session) ValidateNonExistantKey(ctx context.Context, key string) error

ValidateNonExistantKey checks if the redis key has not value.

func (*Session) ValidateTextValue

func (s *Session) ValidateTextValue(ctx context.Context, key, expectedValue string) error

ValidateTextValue checks if the text value for a redis key equals the expected value. It uses session TTL to establish an expiration time (no expiration if TTL is 0).

func (*Session) WaitForJSONMessageWithProperties

func (s *Session) WaitForJSONMessageWithProperties(
	ctx context.Context,
	timeout time.Duration,
	props map[string]interface{},
) error

WaitForJSONMessageWithProperties waits 1 second and verifies if there is a message received in the topic with the requested properties.

func (*Session) WaitForTextMessage

func (s *Session) WaitForTextMessage(
	ctx context.Context,
	timeout time.Duration,
	expectedMsg string,
) error

WaitForTextMessage waits up to timeout till the expected message is found in the received messages for this session.

type Steps

type Steps struct {
}

Steps to initialize common steps.

func (Steps) InitializeSteps

func (cs Steps) InitializeSteps(ctx context.Context, scenCtx *godog.ScenarioContext) context.Context

InitializeSteps initializes all the steps.

Jump to

Keyboard shortcuts

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