43 lines
670 B
Go
43 lines
670 B
Go
package redisdb
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.selly.red/Selly-Modules/logger"
|
|
"github.com/go-redis/redis/v8"
|
|
)
|
|
|
|
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.Printf("⚡️[redis]: connected to %s \n", uri)
|
|
|
|
return nil
|
|
}
|