Documentation
¶
Overview ¶
Package gparedis provides a Redis adapter for the Go Persistence API (GPA)
Package gparedis provides a Redis adapter for the Go Persistence API (GPA)
Index ¶
- Constants
- func GetRepository[T any](p *Provider) gpa.AdvancedKeyValueRepository[T]
- func NewAdvancedKVRepository[T any](provider *Provider, client *redis.Client, keyPrefix string) gpa.AdvancedKeyValueRepository[T]
- type Provider
- func (p *Provider) Client() interface{}
- func (p *Provider) Close() error
- func (p *Provider) Configure(config gpa.Config) error
- func (p *Provider) Delete(ctx context.Context, key string) error
- func (p *Provider) Exists(ctx context.Context, key string) (bool, error)
- func (p *Provider) Expire(ctx context.Context, key string, ttl time.Duration) error
- func (p *Provider) Get(ctx context.Context, key string) (interface{}, error)
- func (p *Provider) Health() error
- func (p *Provider) Keys(ctx context.Context, pattern string) ([]string, error)
- func (p *Provider) ProviderInfo() gpa.ProviderInfo
- func (p *Provider) Repository[T any]() gpa.BasicKeyValueRepository[T]
- func (p *Provider) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (p *Provider) SupportedFeatures() []gpa.Feature
- func (p *Provider) TTL(ctx context.Context, key string) (time.Duration, error)
- type Repository
- func (r *Repository[T]) Close() error
- func (r *Repository[T]) Count(ctx context.Context, opts ...gpa.QueryOption) (int64, error)
- func (r *Repository[T]) Create(ctx context.Context, entity *T) error
- func (r *Repository[T]) CreateBatch(ctx context.Context, entities []*T) error
- func (r *Repository[T]) Decrement(ctx context.Context, key string, delta int64) (int64, error)
- func (r *Repository[T]) Delete(ctx context.Context, id interface{}) error
- func (r *Repository[T]) DeleteByCondition(ctx context.Context, condition gpa.Condition) error
- func (r *Repository[T]) DeleteKey(ctx context.Context, key string) error
- func (r *Repository[T]) Exists(ctx context.Context, opts ...gpa.QueryOption) (bool, error)
- func (r *Repository[T]) Expire(ctx context.Context, key string, ttl time.Duration) error
- func (r *Repository[T]) FindAll(ctx context.Context, opts ...gpa.QueryOption) ([]*T, error)
- func (r *Repository[T]) FindByID(ctx context.Context, id interface{}) (*T, error)
- func (r *Repository[T]) Get(ctx context.Context, key string) (*T, error)
- func (r *Repository[T]) GetEntityInfo() (*gpa.EntityInfo, error)
- func (r *Repository[T]) GetTTL(ctx context.Context, key string) (time.Duration, error)
- func (r *Repository[T]) Increment(ctx context.Context, key string, delta int64) (int64, error)
- func (r *Repository[T]) KeyExists(ctx context.Context, key string) (bool, error)
- func (r *Repository[T]) Keys(ctx context.Context, pattern string) ([]string, error)
- func (r *Repository[T]) MDelete(ctx context.Context, keys []string) (int64, error)
- func (r *Repository[T]) MGet(ctx context.Context, keys []string) (map[string]*T, error)
- func (r *Repository[T]) MSet(ctx context.Context, pairs map[string]*T) error
- func (r *Repository[T]) Query(ctx context.Context, opts ...gpa.QueryOption) ([]*T, error)
- func (r *Repository[T]) QueryOne(ctx context.Context, opts ...gpa.QueryOption) (*T, error)
- func (r *Repository[T]) RawExec(ctx context.Context, query string, args []interface{}) (gpa.Result, error)
- func (r *Repository[T]) RawQuery(ctx context.Context, query string, args []interface{}) ([]*T, error)
- func (r *Repository[T]) RemoveTTL(ctx context.Context, key string) error
- func (r *Repository[T]) Scan(ctx context.Context, cursor uint64, pattern string, count int64) ([]string, uint64, error)
- func (r *Repository[T]) Set(ctx context.Context, key string, value *T) error
- func (r *Repository[T]) SetTTL(ctx context.Context, key string, ttl time.Duration) error
- func (r *Repository[T]) SetWithTTL(ctx context.Context, key string, value *T, ttl time.Duration) error
- func (r *Repository[T]) TTL(ctx context.Context, key string) (time.Duration, error)
- func (r *Repository[T]) Transaction(ctx context.Context, fn gpa.TransactionFunc[T]) error
- func (r *Repository[T]) Update(ctx context.Context, entity *T) error
- func (r *Repository[T]) UpdatePartial(ctx context.Context, id interface{}, updates map[string]interface{}) error
Constants ¶
const DefaultRepositoryKeyPrefix = "gparedis:"
DefaultRepositoryKeyPrefix is used by repositories created through a Provider when no prefix is configured.
Variables ¶
This section is empty.
Functions ¶
func GetRepository ¶
func GetRepository[T any](p *Provider) gpa.AdvancedKeyValueRepository[T]
GetRepository returns a type-safe repository for any entity type T This enables the unified provider API: userRepo := gparedis.GetRepository[User](provider)
func NewAdvancedKVRepository ¶
func NewAdvancedKVRepository[T any](provider *Provider, client *redis.Client, keyPrefix string) gpa.AdvancedKeyValueRepository[T]
NewAdvancedKVRepository creates a new type-safe advanced Redis repository. This repository implements all KV capabilities with compile-time type safety.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements gpa.Provider and gpa.KeyValueProvider using Redis
func NewProvider ¶
NewProvider creates a new Redis provider instance
func (*Provider) Client ¶ added in v0.1.1
func (p *Provider) Client() interface{}
Client returns the underlying Redis client instance
func (*Provider) ProviderInfo ¶
func (p *Provider) ProviderInfo() gpa.ProviderInfo
ProviderInfo returns information about the Redis provider
func (*Provider) Repository ¶ added in v0.1.4
func (p *Provider) Repository[T any]() gpa.BasicKeyValueRepository[T]
Repository creates a type-safe repository from this provider instance.
func (*Provider) SupportedFeatures ¶
SupportedFeatures returns the features supported by Redis
type Repository ¶
type Repository[T any] struct { // contains filtered or unexported fields }
RepositoryG implements type-safe Redis operations using Go generics. Provides compile-time type safety for all key-value operations.
func NewRepository ¶
func NewRepository[T any](provider *Provider, client *redis.Client, keyPrefix string) *Repository[T]
NewRepository creates a new generic Redis repository for type T. Example: userRepo := NewRepository[User](provider, client, "user:")
func (*Repository[T]) Close ¶
func (r *Repository[T]) Close() error
Close closes the repository and releases any resources.
func (*Repository[T]) Count ¶
func (r *Repository[T]) Count(ctx context.Context, opts ...gpa.QueryOption) (int64, error)
Count is not applicable for Redis key-value store
func (*Repository[T]) Create ¶
func (r *Repository[T]) Create(ctx context.Context, entity *T) error
Create is not applicable for Redis key-value store
func (*Repository[T]) CreateBatch ¶
func (r *Repository[T]) CreateBatch(ctx context.Context, entities []*T) error
CreateBatch is not applicable for Redis key-value store
func (*Repository[T]) Delete ¶
func (r *Repository[T]) Delete(ctx context.Context, id interface{}) error
Delete is not applicable for Redis key-value store - use DeleteKey instead
func (*Repository[T]) DeleteByCondition ¶
DeleteByCondition is not applicable for Redis key-value store
func (*Repository[T]) DeleteKey ¶
func (r *Repository[T]) DeleteKey(ctx context.Context, key string) error
DeleteKey removes a key-value pair.
func (*Repository[T]) Exists ¶
func (r *Repository[T]) Exists(ctx context.Context, opts ...gpa.QueryOption) (bool, error)
Exists is not applicable for Redis key-value store - use KeyExists instead
func (*Repository[T]) FindAll ¶
func (r *Repository[T]) FindAll(ctx context.Context, opts ...gpa.QueryOption) ([]*T, error)
FindAll is not applicable for Redis key-value store
func (*Repository[T]) FindByID ¶
func (r *Repository[T]) FindByID(ctx context.Context, id interface{}) (*T, error)
FindByID is not applicable for Redis key-value store - use Get instead
func (*Repository[T]) Get ¶
func (r *Repository[T]) Get(ctx context.Context, key string) (*T, error)
Get retrieves a value by key with compile-time type safety. Returns the value directly without requiring a destination parameter.
func (*Repository[T]) GetEntityInfo ¶
func (r *Repository[T]) GetEntityInfo() (*gpa.EntityInfo, error)
GetEntityInfo returns basic entity information for Redis
func (*Repository[T]) MGet ¶
MGet retrieves multiple values by their keys with compile-time type safety. Returns a slice of pointers to values.
func (*Repository[T]) MSet ¶
func (r *Repository[T]) MSet(ctx context.Context, pairs map[string]*T) error
MSet stores multiple key-value pairs with compile-time type safety.
func (*Repository[T]) Query ¶
func (r *Repository[T]) Query(ctx context.Context, opts ...gpa.QueryOption) ([]*T, error)
Query is not applicable for Redis key-value store
func (*Repository[T]) QueryOne ¶
func (r *Repository[T]) QueryOne(ctx context.Context, opts ...gpa.QueryOption) (*T, error)
QueryOne is not applicable for Redis key-value store
func (*Repository[T]) RawExec ¶
func (r *Repository[T]) RawExec(ctx context.Context, query string, args []interface{}) (gpa.Result, error)
RawExec is not applicable for Redis key-value store
func (*Repository[T]) RawQuery ¶
func (r *Repository[T]) RawQuery(ctx context.Context, query string, args []interface{}) ([]*T, error)
RawQuery is not applicable for Redis key-value store
func (*Repository[T]) RemoveTTL ¶
func (r *Repository[T]) RemoveTTL(ctx context.Context, key string) error
RemoveTTL removes the TTL from a key, making it persistent.
func (*Repository[T]) Scan ¶
func (r *Repository[T]) Scan(ctx context.Context, cursor uint64, pattern string, count int64) ([]string, uint64, error)
Scan iterates through keys matching a pattern using cursor-based pagination.
func (*Repository[T]) Set ¶
func (r *Repository[T]) Set(ctx context.Context, key string, value *T) error
Set stores a value with compile-time type safety. Accepts the value directly without interface{} conversion.
func (*Repository[T]) SetWithTTL ¶
func (r *Repository[T]) SetWithTTL(ctx context.Context, key string, value *T, ttl time.Duration) error
SetWithTTL stores a value with an expiration time and compile-time type safety.
func (*Repository[T]) Transaction ¶
func (r *Repository[T]) Transaction(ctx context.Context, fn gpa.TransactionFunc[T]) error
Transaction is not applicable for Redis key-value store
func (*Repository[T]) Update ¶
func (r *Repository[T]) Update(ctx context.Context, entity *T) error
Update is not applicable for Redis key-value store - use Set instead
func (*Repository[T]) UpdatePartial ¶
func (r *Repository[T]) UpdatePartial(ctx context.Context, id interface{}, updates map[string]interface{}) error
UpdatePartial is not applicable for Redis key-value store