Documentation ¶
Overview ¶
Package cache provides a Redis client and a set of methods for interacting with Redis.
The cache package abstracts away the details of interacting with Redis, allowing the rest of the application to use a simpler, higher-level API for accessing the data stored in cache. By centralizing Redis access in the cache package, it helps to ensure consistency and maintainability of the cache access layer.
Caching frequently accessed data can improve application performance and reduce database load. Using the cache package simplifies the process of implementing caching in the application.
Index ¶
- func NewClient(config config.Redis) *redis.Client
- type MockSessionCache
- func (s *MockSessionCache) Del(_ context.Context, key string) error
- func (s *MockSessionCache) Get(_ context.Context, key string) (string, error)
- func (s *MockSessionCache) SAdd(_ context.Context, key string, value string) error
- func (s *MockSessionCache) SCard(_ context.Context, key string) (int64, error)
- func (s *MockSessionCache) SMembers(_ context.Context, key string) ([]string, error)
- func (s *MockSessionCache) SRem(_ context.Context, key string, value string) error
- func (s *MockSessionCache) Set(_ context.Context, key string, value string, _ time.Duration) error
- type SessionCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MockSessionCache ¶
type MockSessionCache struct { Sessions map[string]string SessionsSet map[string]map[string]struct{} }
MockSessionCache is a mock implementation of SessionCache.
func (*MockSessionCache) Del ¶
func (s *MockSessionCache) Del(_ context.Context, key string) error
Del deletes a session from the cache.
type SessionCache ¶
type SessionCache interface { Set(ctx context.Context, key string, value string, expiration time.Duration) error Get(ctx context.Context, key string) (string, error) Del(ctx context.Context, key string) error SAdd(ctx context.Context, key string, value string) error SRem(ctx context.Context, key string, value string) error SMembers(ctx context.Context, key string) ([]string, error) SCard(ctx context.Context, key string) (int64, error) }
SessionCache is an interface for interacting with Redis.
func NewSessionCache ¶
func NewSessionCache(c *redis.Client) SessionCache
NewSessionCache returns a new instance of SessionCache.