Clean public release with: - Go/Gin/PostgreSQL/Redis architecture - Multi-tenant support - JWT authentication - Docker Compose deployment - Environment-based configuration
25 lines
423 B
Go
25 lines
423 B
Go
package cache
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"mengstack/internal/config"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
func NewRedis(cfg config.RedisConfig) (*redis.Client, error) {
|
|
rdb := redis.NewClient(&redis.Options{
|
|
Addr: cfg.Addr,
|
|
Password: cfg.Password,
|
|
DB: cfg.DB,
|
|
})
|
|
|
|
if err := rdb.Ping(context.Background()).Err(); err != nil {
|
|
return nil, fmt.Errorf("connect to Redis: %w", err)
|
|
}
|
|
|
|
return rdb, nil
|
|
}
|