connect to redis session
This commit is contained in:
@@ -1,15 +1,37 @@
|
|||||||
package session
|
package session
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"astraltech.xyz/accountmanager/src/logging"
|
"astraltech.xyz/accountmanager/src/logging"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RedisStore struct {
|
type RedisStore struct {
|
||||||
|
client *redis.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRedisStore() *RedisStore {
|
func NewRedisStore() *RedisStore {
|
||||||
logging.Debug("Creating new in redis session store")
|
logging.Debug("Creating new redis session store")
|
||||||
store := &RedisStore{}
|
|
||||||
|
redis_server := "localhost:6379"
|
||||||
|
|
||||||
|
// redis values will need to be loaded from the config file
|
||||||
|
rdb := redis.NewClient(&redis.Options{
|
||||||
|
Addr: redis_server,
|
||||||
|
Password: "",
|
||||||
|
DB: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err := rdb.Ping(context.Background()).Err(); err != nil {
|
||||||
|
logging.Errorf("Failed to connect to redis server %s", redis_server)
|
||||||
|
} else {
|
||||||
|
logging.Infof("Successfully connected to redis server %s", redis_server)
|
||||||
|
}
|
||||||
|
|
||||||
|
store := &RedisStore{
|
||||||
|
client: rdb,
|
||||||
|
}
|
||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user