You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
771 B

package main
import (
"context"
"fmt"
"github.com/go-redis/redis/v9"
"time"
)
func main() {
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
if err != nil {
panic(err)
}
client := redis.NewClient(opt)
ctx := context.Background()
//ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
fmt.Println("begin")
//defer cancel()
//select {
//case <-ctx.Done():
// fmt.Println(ctx.Err())
//}
_, err = client.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
client.Do(ctx, "HTRRLEN", "KEY", "FIELD")
s1 := pipe.Get(ctx, "key1")
fmt.Println(s1.Result())
time.Sleep(3 * time.Second)
s2 := pipe.Get(ctx, "key2")
fmt.Println(s2.Result())
return nil
})
if err != nil {
fmt.Println(err)
}
}