shad-go/lectures/07-sql/redis/redis.go

32 lines
472 B
Go
Raw Normal View History

2020-04-09 13:00:41 +00:00
package redis
import (
"log"
"time"
"github.com/go-redis/redis"
)
func Example() {
rdb := redis.NewUniversalClient(&redis.UniversalOptions{
MasterName: "master",
Addrs: []string{":26379"},
})
defer rdb.Close()
if err := rdb.Ping(); err != nil {
log.Fatal(err)
}
if err := rdb.Set("key", "value", time.Hour).Err(); err != nil {
log.Fatal(err)
}
value, err := rdb.Get("key").Result()
if err != nil {
log.Fatal(err)
}
log.Println(value)
}