chore: update session and challenge repo -- using Redis for caching session and challenge verifying -- added api handler docs
This commit is contained in:
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"backend/config"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
type Redis struct {
|
||||
client *redis.Client
|
||||
}
|
||||
|
||||
func NewRedis(cfg config.Redis) (*Redis, error) {
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
|
||||
Password: cfg.Pass,
|
||||
DB: 0,
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
if err := rdb.Ping(ctx).Err(); err != nil {
|
||||
return nil, fmt.Errorf("failed to connect to Redis: %w", err)
|
||||
}
|
||||
|
||||
return &Redis{client: rdb}, nil
|
||||
}
|
||||
|
||||
func (r *Redis) Client() *redis.Client {
|
||||
return r.client
|
||||
}
|
||||
|
||||
func (r *Redis) Close() error {
|
||||
return r.client.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user