Documentation
¶
Overview ¶
Package redis provides a client for interacting with Redis key-value stores.This package allows creating and managing Redis clients, executing Redis commands, and handling connections to Redis databases.
Package redis is a generated GoMock package.
Index ¶
- func NewPubSub(conf config.Config, logger datasource.Logger, metrics Metrics) pubsub.Client
- type Config
- type Metrics
- type MockMetrics
- type MockMetricsMockRecorder
- type PubSub
- func (ps *PubSub) Close() error
- func (ps *PubSub) CreateTopic(ctx context.Context, name string) error
- func (ps *PubSub) DeleteTopic(ctx context.Context, topic string) error
- func (ps *PubSub) Health() datasource.Health
- func (ps *PubSub) Publish(ctx context.Context, topic string, message []byte) error
- func (ps *PubSub) Query(ctx context.Context, query string, args ...any) ([]byte, error)
- func (ps *PubSub) Subscribe(ctx context.Context, topic string) (*pubsub.Message, error)
- type QueryLog
- type Redis
- type StreamsConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
HostName string
Username string
Password string
Port int
DB int
Options *redis.Options
TLS *tls.Config
// PubSub configuration
PubSubMode string // "pubsub" or "streams"
PubSubStreamsConfig *StreamsConfig
PubSubBufferSize int // Message buffer size for channels (default: 100)
PubSubQueryTimeout time.Duration // Default query timeout (default: 5s)
PubSubQueryLimit int // Default query message limit (default: 10)
}
type MockMetrics ¶
type MockMetrics struct {
// contains filtered or unexported fields
}
MockMetrics is a mock of Metrics interface.
func NewMockMetrics ¶
func NewMockMetrics(ctrl *gomock.Controller) *MockMetrics
NewMockMetrics creates a new mock instance.
func (*MockMetrics) EXPECT ¶
func (m *MockMetrics) EXPECT() *MockMetricsMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockMetrics) IncrementCounter ¶
func (m *MockMetrics) IncrementCounter(ctx context.Context, name string, labels ...string)
IncrementCounter mocks base method.
func (*MockMetrics) RecordHistogram ¶
func (m *MockMetrics) RecordHistogram(ctx context.Context, name string, value float64, labels ...string)
RecordHistogram mocks base method.
type MockMetricsMockRecorder ¶
type MockMetricsMockRecorder struct {
// contains filtered or unexported fields
}
MockMetricsMockRecorder is the mock recorder for MockMetrics.
func (*MockMetricsMockRecorder) IncrementCounter ¶
func (mr *MockMetricsMockRecorder) IncrementCounter(ctx, name any, labels ...any) *gomock.Call
IncrementCounter indicates an expected call of IncrementCounter.
func (*MockMetricsMockRecorder) RecordHistogram ¶
func (mr *MockMetricsMockRecorder) RecordHistogram(ctx, name, value any, labels ...any) *gomock.Call
RecordHistogram indicates an expected call of RecordHistogram.
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
PubSub handles Redis PubSub operations.
func (*PubSub) CreateTopic ¶
CreateTopic is a no-op for Redis PubSub (channels are created on first publish/subscribe). For Redis Streams, it creates the stream and consumer group.
func (*PubSub) DeleteTopic ¶
DeleteTopic unsubscribes all active subscriptions for the given topic/channel.
func (*PubSub) Health ¶
func (ps *PubSub) Health() datasource.Health
Health returns the health status of the Redis PubSub connection.
type QueryLog ¶
type QueryLog struct {
Query string `json:"query"`
Duration int64 `json:"duration"`
Args any `json:"args,omitempty"`
}
QueryLog represents a logged Redis query.
func (*QueryLog) PrettyPrint ¶
type Redis ¶
func NewClient ¶
NewClient returns a Redis client if connection is successful based on Config. Supports both plain and TLS connections. TLS is configured via REDIS_TLS_ENABLED and related environment variables. In case of error, it returns an error as second parameter.
func (*Redis) Close ¶
Close shuts down the Redis client, ensuring the current dataset is saved before exiting.
func (*Redis) HealthCheck ¶
func (r *Redis) HealthCheck() datasource.Health
HealthCheck returns the health status of the Redis connection.
type StreamsConfig ¶
type StreamsConfig struct {
// ConsumerGroup is the name of the consumer group (required for Streams)
ConsumerGroup string
// ConsumerName is the name of the consumer (optional, auto-generated if empty)
ConsumerName string
// MaxLen is the maximum length of the stream (optional)
// If > 0, the stream will be trimmed to this length on publish
MaxLen int64
// Block is the blocking duration for XREADGROUP (optional)
// If > 0, calls will block for this duration waiting for new messages
Block time.Duration
// PELRatio is the ratio of PEL (pending) messages to read (0.0-1.0)
// Default: 0.7 (70% PEL, 30% new messages)
// 0.0 = only new messages, 1.0 = only PEL messages
PELRatio float64
}
StreamsConfig holds configuration for Redis Streams.