feat(auth): Add login, register, session_info and api creation
This commit is contained in:
52
app/cache/redis.go
vendored
Normal file
52
app/cache/redis.go
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.secnex.io/secnex/auth-api/config"
|
||||
"github.com/valkey-io/valkey-go"
|
||||
)
|
||||
|
||||
type RedisConfiguration struct {
|
||||
Host string
|
||||
Port string
|
||||
Password string
|
||||
}
|
||||
|
||||
type RedisCache struct {
|
||||
Client valkey.Client
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
var Cache RedisCache
|
||||
|
||||
func NewRedisConfiguration(host, port, password string) *RedisConfiguration {
|
||||
return &RedisConfiguration{
|
||||
Host: host,
|
||||
Port: port,
|
||||
Password: password,
|
||||
}
|
||||
}
|
||||
|
||||
func NewRedisConfigurationFromConfig(config *config.Config) *RedisConfiguration {
|
||||
return &RedisConfiguration{
|
||||
Host: config.RedisHost,
|
||||
Port: config.RedisPort,
|
||||
Password: config.RedisPassword,
|
||||
}
|
||||
}
|
||||
|
||||
func Connect(config *config.Config) error {
|
||||
client, err := valkey.NewClient(valkey.ClientOption{InitAddress: []string{fmt.Sprintf("%s:%s", config.RedisHost, config.RedisPort)}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx := context.Background()
|
||||
cache := &RedisCache{
|
||||
Client: client,
|
||||
Context: ctx,
|
||||
}
|
||||
Cache = *cache
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user