modulepackage
0.0.0-20241127091020-4b0f828ba994
Repository: https://github.com/gopi-frame/redis.git
Documentation: pkg.go.dev
# README
Overview
Package redis provides a redis connection client.
This package is based on go-redis
Installation
go get -u github.com/gopi-frame/redis
Import
import "github.com/gopi-frame/redis"
Quick Start
package main
import (
"context"
"fmt"
"github.com/gopi-frame/redis"
"time"
)
func main() {
client, err := redis.Open("standalone", nil)
if err != nil {
panic(err)
}
client.Set(context.Background(), "key", "value", 10*time.Second)
value := client.Get(context.Background(), "key")
fmt.Println(value)
}
Redis Cluster Client
package main
import (
"context"
"fmt"
"github.com/gopi-frame/redis"
"time"
)
func main() {
client, err := redis.Open("cluster", map[string]any{
"addrs": []string{
":6379",
":6380",
":6381",
},
})
if err != nil {
panic(err)
}
if err := client.Set(context.Background(), "key", "value", 10*time.Second).Err(); err != nil {
panic(err)
}
value := client.Get(context.Background(), "key")
fmt.Println(value)
}
Redis Sentinel Client
package main
import (
"context"
"fmt"
"github.com/gopi-frame/redis"
"time"
)
func main() {
client, err := redis.Open("sentinel", map[string]any{
"masterName": "master",
"sentinelAddrs": []string{":6379", ":6380", ":6381"},
})
if err != nil {
panic(err)
}
if err := client.Set(context.Background(), "key", "value", 10*time.Second).Err(); err != nil {
panic(err)
}
value := client.Get(context.Background(), "key")
fmt.Println(value)
}
Redis Ring Client
package main
import (
"context"
"fmt"
"github.com/gopi-frame/redis"
"time"
)
func main() {
client, err := redis.Open("ring", map[string]any{
"addrs": map[string]string{
"shard1": ":7000",
"shard2": ":7001",
"shard3": ":7002",
},
})
if err != nil {
panic(err)
}
if err := client.Set(context.Background(), "key", "value", 10*time.Second).Err(); err != nil {
panic(err)
}
value := client.Get(context.Background(), "key")
fmt.Println(value)
}
Options
This package uses github.com/go-viper/mapstructure/v2 to convert the options to the underlying client.
For more information about the options, please see the go-redis documentation.
# Packages
No description provided by the author
# Functions
Drivers list registered drivers.
No description provided by the author
No description provided by the author
Open opens redis client.
Register register driver.
# Structs
No description provided by the author
No description provided by the author