本文整理匯總了Golang中menteslibres/net/gosexy/redis.Client.Connect方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Connect方法的具體用法?Golang Client.Connect怎麽用?Golang Client.Connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類menteslibres/net/gosexy/redis.Client
的用法示例。
在下文中一共展示了Client.Connect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: spawnPublisher
func spawnPublisher() error {
var err error
var publisher *redis.Client
publisher = redis.New()
err = publisher.Connect(host, port)
if err != nil {
log.Fatalf("Publisher failed to connect: %s\n", err.Error())
return err
}
log.Println("Publisher connected to redis-server.")
log.Println("Publishing some messages...")
publisher.Publish("channel", "Hello world!")
publisher.Publish("channel", "Do you know how to count?")
for i := 0; i < 3; i++ {
publisher.Publish("channel", i)
}
log.Printf("Closing publisher...\n")
publisher.Quit()
return nil
}
示例2: main
func main() {
var client *redis.Client
client = redis.New()
client.Connect("localhost", 6379)
s, _ := client.Ping()
fmt.Println(s)
client.Incr("hello")
s, _ = client.Get("hello")
fmt.Println(s)
client.Quit()
}
示例3: Init
//初始化redis連接
//傳入配置參數
func Init(config ...*Config) {
config = checkConfig(config)
for i := 0; i < len(config); i++ {
var client *redis.Client
client = redis.New()
err1 := client.Connect(config[i].Host, config[i].Port)
log.Println(config[i].Host+":"+strconv.Itoa(int(config[i].Port)), "Connect ...")
_, err2 := client.Ping()
if err1 != nil || err2 != nil {
log.Println("ERROR: Redis Connect failed!")
os.Exit(0)
}
redisSlice = append(redisSlice, client)
for j := 0; j < len(config[i].Data); j++ {
structRedis[config[i].Data[j]] = client
}
}
}