Files
History_Api/pkg/cache/redis.go
2026-03-25 22:29:43 +07:00

33 lines
500 B
Go

package cache
import (
"context"
"fmt"
"history-api/pkg/config"
"github.com/redis/go-redis/v9"
)
var RI *redis.Client
func Connect() error {
connectionURI, err := config.GetConfig("REDIS_CONNECTION_URI")
if err != nil {
return err
}
rdb := redis.NewClient(&redis.Options{
Addr: connectionURI,
Password: "",
DB: 0,
})
if err := rdb.Ping(context.Background()).Err(); err != nil {
return fmt.Errorf("Could not connect to Redis: %v", err)
}
RI = rdb
return nil
}