Skip to content

Instantly share code, notes, and snippets.

@Queetinliu
Created November 1, 2022 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Queetinliu/884a0ee8679cb060e6931be203cc7cbc to your computer and use it in GitHub Desktop.
Save Queetinliu/884a0ee8679cb060e6931be203cc7cbc to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"github.com/go-redis/redis/v9"
)
var ctx = context.Background()
func main() {
rdb := redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: "mymaster",
SentinelAddrs: []string{"10.66.0.40:26379", "10.66.0.41:26379",
"10.66.0.42:26379", "10.66.0.44:26379"},
Password: "",
PoolSize: 100,
MaxRetries: 3,
DB: 0,
SentinelPassword: "",
})
i := 0
for true {
key := fmt.Sprintf("key%d", i)
value := fmt.Sprintf("value%d", i)
err := rdb.Set(ctx, key, value, 0).Err()
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("sucessly write %s %s to redis", key, value)
i++
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment