cache

package
v0.0.0-...-9067f3d Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(config config.Redis) *redis.Client

NewClient creates a new redis client

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.

func (*MockSessionCache) Get

func (s *MockSessionCache) Get(_ context.Context, key string) (string, error)

Get gets a session from the cache.

func (*MockSessionCache) SAdd

func (s *MockSessionCache) SAdd(_ context.Context, key string, value string) error

SAdd adds a session to the user's sessions set.

func (*MockSessionCache) SCard

func (s *MockSessionCache) SCard(_ context.Context, key string) (int64, error)

SCard returns the number of sessions for a user.

func (*MockSessionCache) SMembers

func (s *MockSessionCache) SMembers(_ context.Context, key string) ([]string, error)

SMembers returns all sessions for a user.

func (*MockSessionCache) SRem

func (s *MockSessionCache) SRem(_ context.Context, key string, value string) error

SRem removes a session from the user's sessions set.

func (*MockSessionCache) Set

func (s *MockSessionCache) Set(_ context.Context, key string, value string, _ time.Duration) error

Set sets a session in 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.

Jump to

Keyboard shortcuts

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