Documentation
¶
Overview ¶
Package redis provides Redis connection and key-value helpers.
New code should use explicit connection ownership and core-owned command shapes:
import "github.com/InsideGallery/core/db/redis" store := redis.NewConnectionStore(redis.NewRedisClient(config)) conn, err := store.Get()
Prefer KeyValueStore with GetOptions, SetOptions, StringResult, and CommandResult for application-facing code.
Compatibility: package-level Set, Get, and Default remain available for existing consumers. Prefer NewRedisClient or ConnectionStore.GetOrCreate with explicit configuration in new code.
Index ¶
- Constants
- Variables
- func Set(r *Connection)deprecated
- type Client
- type CommandResult
- type Connectiondeprecated
- func Default() (*Connection, error)deprecated
- func Get() (*Connection, error)deprecated
- func NewRedisClient(config *ConnectionConfig) *Connectiondeprecated
- func (c Connection) Get(ctx context.Context, key string) (string, bool, error)
- func (c Connection) GetValue(ctx context.Context, options GetOptions) (StringResult, error)
- func (c Connection) Set(ctx context.Context, key, value string, expiration time.Duration) error
- func (c Connection) SetValue(ctx context.Context, options SetOptions) (CommandResult, error)
- func (c Connection) Stop() error
- type ConnectionConfig
- type ConnectionStore
- type GetOptions
- type KeyValueStore
- type SetOptions
- type StringResult
Constants ¶
const EnvPrefix = "REDIS"
Variables ¶
var ErrConnectionIsNotSet = errors.New("connection is not set")
Functions ¶
func Set
deprecated
Types ¶
type CommandResult ¶ added in v1.1.0
type CommandResult struct {
Key string
}
CommandResult is the core-owned result for Redis commands.
type Connection
deprecated
Connection is the legacy Redis SDK wrapper.
Deprecated: use KeyValueStore and core-owned option/result types for new code.
func Default
deprecated
func Default() (*Connection, error)
Default return default client
Deprecated: use NewRedisClient or ConnectionStore.GetOrCreate with explicit config.
func Get
deprecated
func Get() (*Connection, error)
Get return redis client
Deprecated: use ConnectionStore.Get on an explicit store.
func NewRedisClient
deprecated
func NewRedisClient(config *ConnectionConfig) *Connection
NewRedisClient creates the legacy Redis SDK wrapper.
Deprecated: use KeyValueStore methods on Connection for new code.
func (Connection) GetValue ¶ added in v1.1.0
func (c Connection) GetValue(ctx context.Context, options GetOptions) (StringResult, error)
GetValue reads a Redis string value with core-owned options.
func (Connection) SetValue ¶ added in v1.1.0
func (c Connection) SetValue(ctx context.Context, options SetOptions) (CommandResult, error)
SetValue writes a Redis string value with core-owned options.
func (Connection) Stop ¶
func (c Connection) Stop() error
type ConnectionConfig ¶
type ConnectionConfig struct {
Host string `env:"_HOST" envDefault:"localhost"`
Port string `env:"_PORT" envDefault:"6379"`
User string `env:"_USER" envDefault:""`
Pass string `env:"_PASS" envDefault:""`
Database int `env:"_DATABASE" envDefault:"0"`
}
func GetConnectionConfigFromEnv ¶
func GetConnectionConfigFromEnv() (*ConnectionConfig, error)
type ConnectionStore ¶ added in v1.1.0
type ConnectionStore struct {
// contains filtered or unexported fields
}
ConnectionStore owns a Redis client for explicit application composition.
func NewConnectionStore ¶ added in v1.1.0
func NewConnectionStore(client *Connection) *ConnectionStore
NewConnectionStore creates a Redis connection store with an optional existing client.
func (*ConnectionStore) Close ¶ added in v1.1.0
func (s *ConnectionStore) Close() error
Close closes the stored Redis connection and clears this store.
func (*ConnectionStore) Get ¶ added in v1.1.0
func (s *ConnectionStore) Get() (*Connection, error)
Get returns the Redis connection from this store.
func (*ConnectionStore) GetOrCreate ¶ added in v1.1.0
func (s *ConnectionStore) GetOrCreate(config *ConnectionConfig) (*Connection, error)
GetOrCreate returns or creates a Redis connection from explicit config.
func (*ConnectionStore) Set ¶ added in v1.1.0
func (s *ConnectionStore) Set(client *Connection)
Set stores a Redis connection in this store.
type GetOptions ¶ added in v1.1.0
type GetOptions struct {
Key string
}
GetOptions is the core-owned input for reading a Redis string value.
type KeyValueStore ¶ added in v1.1.0
type KeyValueStore interface {
GetValue(ctx context.Context, options GetOptions) (StringResult, error)
SetValue(ctx context.Context, options SetOptions) (CommandResult, error)
Stop() error
}
KeyValueStore is the core-owned Redis contract for new consumers.
type SetOptions ¶ added in v1.1.0
SetOptions is the core-owned input for writing a Redis string value.
type StringResult ¶ added in v1.1.0
StringResult is the core-owned result for Redis string reads.