redisdb/redisdb.go

43 lines
671 B
Go
Raw Permalink Normal View History

2021-08-09 03:36:09 +00:00
package redisdb
import (
"context"
"fmt"
2022-10-29 02:58:04 +00:00
"git.selly.red/Selly-Modules/logger"
2021-08-09 03:36:09 +00:00
"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 {
2022-10-29 02:58:04 +00:00
logger.Error("ping", logger.LogData{
Source: "redisdb.Connect",
Message: err.Error(),
2022-11-24 03:38:56 +00:00
Data: logger.Map{
"uri": uri,
2022-10-29 02:58:04 +00:00
"password": password,
},
})
2021-08-09 03:36:09 +00:00
return err
}
2022-11-24 03:38:56 +00:00
fmt.Printf("⚡️[natsio]: connected to %s \n", uri)
2021-08-09 03:36:09 +00:00
return nil
}