Add redis driver

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2025-12-25 14:51:45 +08:00
parent 9e51414a13
commit 32a27d974a
9 changed files with 90 additions and 4 deletions

22
data/drivers/redis.go Normal file
View File

@@ -0,0 +1,22 @@
package drivers
import (
"context"
"github.com/redis/go-redis/v9"
)
func Redis(dsn RedisDSN) (*redis.UniversalClient, error) {
// Connect to Redis
rdb := redis.NewUniversalClient(&redis.UniversalOptions{
Addrs: dsn.Hosts,
MasterName: dsn.Master,
Username: dsn.Username,
Password: dsn.Password,
DB: dsn.DB,
})
ctx := context.Background()
// Ping Redis
_, err := rdb.Ping(ctx).Result()
return &rdb, err
}

View File

@@ -11,6 +11,14 @@ type ExternalDSN struct {
Password string
}
type RedisDSN struct {
Hosts []string
Master string
Username string
Password string
DB int
}
type DBClient struct {
*gorm.DB
}