redisdb/redisdb.go

42 lines
559 B
Go
Raw Permalink Normal View History

2021-08-09 03:36:09 +00:00
package redisdb
import (
"context"
"fmt"
"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 {
fmt.Println("Error when connect to Redis", uri, err)
return err
}
fmt.Println(aurora.Green("*** CONNECTED TO REDIS: " + uri))
return nil
}