redis

package
v0.0.0-...-58a1804 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTTL           = 1 * time.Hour
	EmbeddingCacheTTL    = 24 * time.Hour
	DocumentCacheTTL     = 6 * time.Hour
	SearchResultCacheTTL = 30 * time.Minute
	Doc2XCacheTTL        = 7 * 24 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheService

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

func NewCacheService

func NewCacheService(client *Client) *CacheService

func (*CacheService) CacheDoc2XResponse

func (s *CacheService) CacheDoc2XResponse(ctx context.Context, md5Hash string, response interface{}) error

Doc2X helpers

func (*CacheService) CacheDocument

func (s *CacheService) CacheDocument(ctx context.Context, docID string, document interface{}) error

func (*CacheService) CacheEmbedding

func (s *CacheService) CacheEmbedding(ctx context.Context, text string, embedding []float32) error

func (*CacheService) CacheSearchResults

func (s *CacheService) CacheSearchResults(ctx context.Context, query string, results interface{}) error

func (*CacheService) ClearCache

func (s *CacheService) ClearCache(ctx context.Context, _ string) error

func (*CacheService) DeleteSession

func (s *CacheService) DeleteSession(ctx context.Context, sessionID string) error

func (*CacheService) GetCounter

func (s *CacheService) GetCounter(ctx context.Context, name string) (int64, error)

func (*CacheService) GetDoc2XResponse

func (s *CacheService) GetDoc2XResponse(ctx context.Context, md5Hash string, dest interface{}) error

func (*CacheService) GetDocument

func (s *CacheService) GetDocument(ctx context.Context, docID string, dest interface{}) error

func (*CacheService) GetEmbedding

func (s *CacheService) GetEmbedding(ctx context.Context, text string) ([]float32, error)

func (*CacheService) GetSearchResults

func (s *CacheService) GetSearchResults(ctx context.Context, query string, dest interface{}) error

func (*CacheService) GetSession

func (s *CacheService) GetSession(ctx context.Context, sessionID string, dest interface{}) error

func (*CacheService) GetUserData

func (s *CacheService) GetUserData(ctx context.Context, userID string, field string, dest interface{}) error

func (*CacheService) IncrementCounter

func (s *CacheService) IncrementCounter(ctx context.Context, name string, ttl time.Duration) (int64, error)

func (*CacheService) InvalidateDocument

func (s *CacheService) InvalidateDocument(ctx context.Context, docID string) error

func (*CacheService) InvalidateUserData

func (s *CacheService) InvalidateUserData(ctx context.Context, userID string, fields ...string) error

func (*CacheService) SetCounter

func (s *CacheService) SetCounter(ctx context.Context, name string, value int64, ttl time.Duration) error

func (*CacheService) SetSession

func (s *CacheService) SetSession(ctx context.Context, sessionID string, data interface{}, ttl time.Duration) error

func (*CacheService) SetUserData

func (s *CacheService) SetUserData(ctx context.Context, userID string, field string, value interface{}, ttl time.Duration) error

type Client

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

Client implements RedisClient using rueidis.

func NewClient

func NewClient(opts ClientOptions) (*Client, error)

func NewClientFromConfig

func NewClientFromConfig(cfg config.Config) (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, keys ...string) error

func (*Client) DeleteHashFields

func (c *Client) DeleteHashFields(ctx context.Context, key string, fields ...string) error

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, key string) (bool, error)

func (*Client) FlushDB

func (c *Client) FlushDB(ctx context.Context) error

func (*Client) Get

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

func (*Client) GetHash

func (c *Client) GetHash(ctx context.Context, key string) (map[string]string, error)

func (*Client) GetHashField

func (c *Client) GetHashField(ctx context.Context, key, field string) (string, error)

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, key string, dest interface{}) error

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

func (*Client) Set

func (c *Client) Set(ctx context.Context, key string, value string, expiration time.Duration) error

func (*Client) SetHash

func (c *Client) SetHash(ctx context.Context, key string, fields map[string]string, expiration time.Duration) error

Hash helpers

func (*Client) SetJSON

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

JSON helpers

type ClientOptions

type ClientOptions struct {
	Host     string `validate:"required"`
	Port     int    `validate:"min=1,max=65535"`
	Password string // optional
	DB       int    `validate:"min=0,max=15"`
}

ClientOptions holds configuration for Redis client creation.

type RedisClient

type RedisClient interface {
	// Basic operations
	Set(ctx context.Context, key string, value string, expiration time.Duration) error
	Get(ctx context.Context, key string) (string, error)
	Delete(ctx context.Context, keys ...string) error
	Exists(ctx context.Context, key string) (bool, error)

	// JSON operations
	SetJSON(ctx context.Context, key string, value interface{}, expiration time.Duration) error
	GetJSON(ctx context.Context, key string, dest interface{}) error

	// Hash operations
	SetHash(ctx context.Context, key string, fields map[string]string, expiration time.Duration) error
	GetHash(ctx context.Context, key string) (map[string]string, error)
	GetHashField(ctx context.Context, key, field string) (string, error)
	DeleteHashFields(ctx context.Context, key string, fields ...string) error

	// Utility operations
	Ping(ctx context.Context) error
	FlushDB(ctx context.Context) error
	Close()
}

RedisClient defines the interface for Redis operations. This interface enables easier testing and potential implementation swapping.

Jump to

Keyboard shortcuts

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