Add run configs. Add redis for cache. Add cache-get in player-list.
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user