owpengram-server/internal/store/redisstore/redis.go
2026-06-04 01:37:39 +08:00

25 lines
680 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 实现高频易失态的存储接口第一阶段SessionStore
//
// 职责边界见 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
}