Files
soul-yongping/soul-api/internal/redis/redis.go
Alex-larget 0d12ab1d07 Update project documentation and enhance user interaction features
- Added a new entry for user interaction habit analysis based on agent transcripts, summarizing key insights into communication styles and preferences.
- Updated project indices to reflect the latest developments, including the addition of a wallet balance feature and enhancements to the mini program's user interface for better user experience.
- Improved the handling of loading states in the chapters page, ensuring a smoother user experience during data retrieval.
- Implemented a gift payment sharing feature, allowing users to share payment requests with friends for collaborative purchases.
2026-03-17 11:44:36 +08:00

42 lines
749 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 redis
import (
"context"
"log"
"github.com/redis/go-redis/v9"
)
var client *redis.Client
// Init 初始化 Redis 客户端url 为空或 "disable" 时跳过
func Init(url string) error {
if url == "" || url == "disable" {
return nil
}
opt, err := redis.ParseURL(url)
if err != nil {
return err
}
client = redis.NewClient(opt)
ctx := context.Background()
if err := client.Ping(ctx).Err(); err != nil {
return err
}
log.Printf("redis: connected to %s", opt.Addr)
return nil
}
// Client 返回 Redis 客户端,未初始化时返回 nil
func Client() *redis.Client {
return client
}
// Close 关闭连接(优雅退出时调用)
func Close() error {
if client != nil {
return client.Close()
}
return nil
}