1234567891011121314151617181920212223242526 |
- package rdb
- import (
- "context"
- "github.com/go-redis/redis/v8"
- "github.com/spf13/viper"
- "time"
- )
- func NewRedis(conf *viper.Viper) error {
- rdb := redis.NewClient(&redis.Options{
- Addr: conf.GetString("data.redis.addr"),
- Password: conf.GetString("data.redis.password"),
- DB: conf.GetInt("data.redis.db"),
- })
- ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
- defer cancel()
- _, err := rdb.Ping(ctx).Result()
- if err != nil {
- return err
- }
- return nil
- }
|