cache

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cache provides Redis client wrapper for caching operations.

Index

Constants

View Source
const (
	KeyUserAvailability  = "user:availability:%d"   // user:availability:{gitlab_id}
	KeyUserReviewCount   = "user:review_count:%d"   // user:review_count:{gitlab_id}
	KeyUserRecentReviews = "user:recent_reviews:%d" // user:recent_reviews:{gitlab_id}
	KeyPendingMRs        = "mr:pending"             // set of "project_id:mr_iid"
	KeyConfigTeams       = "config:teams"           // JSON of team configuration
)

Cache key constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache wraps Redis client.

func NewCache

func NewCache(cfg *config.RedisConfig, log *logger.Logger) (*Cache, error)

NewCache creates a new Redis cache client.

func (*Cache) Close

func (c *Cache) Close() error

Close closes the Redis connection.

func (*Cache) Decr

func (c *Cache) Decr(ctx context.Context, key string) (int64, error)

Decr decrements a key's value.

func (*Cache) Del

func (c *Cache) Del(ctx context.Context, keys ...string) error

Del deletes a key from cache.

func (*Cache) Exists

func (c *Cache) Exists(ctx context.Context, keys ...string) (int64, error)

Exists checks if a key exists.

func (*Cache) Expire

func (c *Cache) Expire(ctx context.Context, key string, expiration time.Duration) error

Expire sets an expiration on a key.

func (*Cache) Get

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

Get retrieves a value from cache.

func (*Cache) Health

func (c *Cache) Health(ctx context.Context) error

Health checks if Redis is healthy.

func (*Cache) Incr

func (c *Cache) Incr(ctx context.Context, key string) (int64, error)

Incr increments a key's value.

func (*Cache) SAdd

func (c *Cache) SAdd(ctx context.Context, key string, members ...interface{}) error

SAdd adds members to a set.

func (*Cache) SIsMember

func (c *Cache) SIsMember(ctx context.Context, key string, member interface{}) (bool, error)

SIsMember checks if a member exists in a set.

func (*Cache) SMembers

func (c *Cache) SMembers(ctx context.Context, key string) ([]string, error)

SMembers returns all members of a set.

func (*Cache) SRem

func (c *Cache) SRem(ctx context.Context, key string, members ...interface{}) error

SRem removes members from a set.

func (*Cache) Set

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

Set stores a value in cache with expiration.

func (*Cache) SetNX

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

SetNX sets a key only if it doesn't exist (for distributed locking).

Jump to

Keyboard shortcuts

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