owpengram-server/internal/store/redisstore/redis.go

25 lines
686 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package redisstore 用 Redis 实现高频、易失且可重建的短状态、缓存、计数器与限流。
//
// 职责边界见 docs/persistence-layer.md §1Redis 存「态与计数」,丢失可由 PG/协议恢复。
package redisstore
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
// Open 按地址建立 Redis 连接并 ping 验证。
func Open(ctx context.Context, addr, password string, db int) (*redis.Client, error) {
c := redis.NewClient(&redis.Options{
Addr: addr,
Password: password,
DB: db,
})
if err := c.Ping(ctx).Err(); err != nil {
_ = c.Close()
return nil, fmt.Errorf("redis ping %s: %w", addr, err)
}
return c, nil
}