redisdb/redisdb.go

35 lines
529 B
Go

package redisdb
import (
"context"
"fmt"
"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 {
fmt.Printf("[redisdb] connect to %s error: %s \n", uri, err.Error())
return err
}
fmt.Printf("⚡️[redis]: connected to %s \n", uri)
return nil
}