Documentation
¶
Overview ¶
Package redis provides a Redis-backed distributed stats cache for mailbox.
Index ¶
- type Cache
- func (c *Cache) Get(ctx context.Context, ownerID string) (*store.MailboxStats, error)
- func (c *Cache) IncrBy(ctx context.Context, ownerID string, field string, delta int64) error
- func (c *Cache) Invalidate(ctx context.Context, ownerID string) error
- func (c *Cache) Set(ctx context.Context, ownerID string, stats *store.MailboxStats, ...) error
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a Redis Hash-backed distributed stats cache.
Each user's stats are stored as a Redis Hash at key "{prefix}:{userID}". Hash fields: "total", "unread", "draft", and per-folder "folder:{folderID}:total" / "folder:{folderID}:unread" entries.
HINCRBY keeps individual counters consistent without a read-modify-write cycle. HGETALL deserializes the full stats on a cache miss.
func New ¶
func New(client redis.UniversalClient, opts ...Option) *Cache
New creates a new Redis stats cache.
func (*Cache) IncrBy ¶
IncrBy atomically increments a named field for a user. If the key does not exist (cache miss), the increment is skipped rather than seeding partial data — the next Get will miss and trigger a full store fetch.
func (*Cache) Invalidate ¶
Invalidate removes cached stats for a user.
type Option ¶
type Option func(*options)
Option configures the Redis stats cache.
func WithPrefix ¶
WithPrefix sets the Redis key prefix. Default is "mailbox:stats".