Add run configs. Add redis for cache. Add cache-get in player-list.

This commit is contained in:
MaxJa4
2024-01-20 17:47:39 +01:00
parent 9e3e2723d3
commit 069d76520e
10 changed files with 124 additions and 9 deletions

View File

@@ -2,6 +2,8 @@ package models
import (
"InfantrySkillCalculator/utils"
"context"
"github.com/redis/go-redis/v9"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
@@ -9,6 +11,8 @@ import (
)
var DB *gorm.DB
var ctx = context.Background()
var Cache *redis.Client
func ConnectDatabase() {
database, err := gorm.Open(sqlite.Open("isc_data.db"), &gorm.Config{
@@ -71,3 +75,17 @@ func ConnectDatabase() {
DB = database
}
func ConnectCache() {
Cache = redis.NewClient(&redis.Options{
Addr: "127.0.0.1:6379",
Password: "",
DB: 0,
})
_, err := Cache.Ping(ctx).Result()
if err != nil {
Cache = nil
log.Fatal("Failed to connect to Redis! " + err.Error())
}
}