sky/internal/platform/store/valkey.go
root 6ed55254a0 chore: initial import of sky project
Go + PostgreSQL + Valkey backend (cmd/internal/migrations),
uni-app mobile frontend, PC web (web/), admin console (admin/),
Android WebView container (android_project/).
Build artifacts, node_modules, local env and debug screenshots excluded.
2026-11-09 22:22:44 +08:00

35 lines
818 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 store
import (
"context"
"fmt"
"time"
"github.com/redis/go-redis/v9"
)
// NewValkey 建立 Valkey/Redis 客户端。
// Valkey 与 Redis 协议完全兼容,go-redis 无需区分。
func NewValkey(ctx context.Context, addr, password string, db int) (*redis.Client, error) {
cli := redis.NewClient(&redis.Options{
Addr: addr,
Password: password,
DB: db,
PoolSize: 100,
MinIdleConns: 10,
DialTimeout: 3 * time.Second,
ReadTimeout: 2 * time.Second,
WriteTimeout: 2 * time.Second,
PoolTimeout: 3 * time.Second,
MaxRetries: 2,
})
pingCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
if err := cli.Ping(pingCtx).Err(); err != nil {
_ = cli.Close()
return nil, fmt.Errorf("连接 Valkey 失败: %w", err)
}
return cli, nil
}