golang整合redis

1、参考实例 https://redis.uptrace.dev/zh/guide/go-redis.html#安装

package redis

import (
    "context"
    "fmt"
    "github.com/garyburd/redigo/redis"
    redis2 "github.com/redis/go-redis/v9"
    "testing"
    "time"
)

func TestQuery(t *testing.T) {
    c, err := redis.Dial("tcp", "xxx:6379")
    if err != nil {
        fmt.Println("conn redis failed,", err)
        return
    }

    fmt.Println("redis conn success")

    defer c.Close()
}

func TestRedisPool(t *testing.T) {
    rdb := redis2.NewClient(&redis2.Options{
        Addr:        "xxx:6379",
        PoolSize:    10,
        PoolTimeout: 5 * time.Second,
    })
    ctx := context.Background()
    val, err := rdb.Get(ctx, "12345").Result()
    fmt.Println(val, err)
}

results matching ""

    No results matching ""