32 lines
569 B
Go
32 lines
569 B
Go
// internal/database/redis.go
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
type RedisConfig struct {
|
|
Addr string
|
|
Password string
|
|
DB int
|
|
}
|
|
|
|
func NewRedisConnection(config RedisConfig) (*redis.Client, error) {
|
|
client := redis.NewClient(&redis.Options{
|
|
Addr: config.Addr,
|
|
Password: config.Password,
|
|
DB: config.DB,
|
|
})
|
|
|
|
// Test connection
|
|
ctx := context.Background()
|
|
if err := client.Ping(ctx).Err(); err != nil {
|
|
return nil, fmt.Errorf("failed to connect to redis: %w", err)
|
|
}
|
|
|
|
return client, nil
|
|
}
|