redisdb/redisdb.go

50 lines
714 B
Go

package redisdb
import (
"context"
"fmt"
"git.selly.red/Selly-Modules/logger"
"github.com/go-redis/redis/v8"
"github.com/logrusorgru/aurora"
)
var (
rdb *redis.Client
)
// Connect ...
func Connect(uri, password string) error {
ctx := context.Background()
rdb = redis.NewClient(&redis.Options{
Addr: uri,
Password: password,
DB: 0, // use default DB
})
// Ping
_, err := rdb.Ping(ctx).Result()
if err != nil {
logger.Error("ping", logger.LogData{
Source: "redisdb.Connect",
Message: err.Error(),
Data: logger.Map{
"uri": uri,
"password": password,
},
})
return err
}
fmt.Println(aurora.Green("*** CONNECTED TO REDIS: " + uri))
return nil
}