當前位置: 首頁>>代碼示例>>Golang>>正文


Golang redis.Client類代碼示例

本文整理匯總了Golang中github.com/gosexy/redis.Client的典型用法代碼示例。如果您正苦於以下問題:Golang Client類的具體用法?Golang Client怎麽用?Golang Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Client類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: testConn

func (this *redisPool) testConn(conn *redis.Client) error {
	if _, err := conn.Ping(); err != nil {
		conn.Quit()
		return err
	}

	return nil
}
開發者ID:jmcarbo,項目名稱:smtpd-1,代碼行數:8,代碼來源:redis_store.go

示例2: Close

func (this *redisPool) Close(conn *redis.Client) {
	select {
	case this.connections <- conn:
		return
	default:
		conn.Quit()
	}
}
開發者ID:jmcarbo,項目名稱:smtpd-1,代碼行數:8,代碼來源:redis_store.go

示例3: spawnConsumer

func spawnConsumer() error {
	var err error
	var consumer *redis.Client

	consumer = redis.New()

	err = consumer.Connect(host, port)

	if err != nil {
		log.Fatalf("Consumer failed to connect: %s\n", err.Error())
		return err
	}

	log.Println("Consumer connected to redis-server.")

	rec := make(chan []string)

	log.Printf("Waiting for rec channel. Ctrl + C to quit.\n")
	go consumer.Subscribe(rec, "channel")

	var ls []string

	for {
		ls = <-rec
		log.Printf("Consumer received: %v\n", strings.Join(ls, ", "))
	}

	consumer.Quit()

	return nil
}
開發者ID:22morph,項目名稱:redis,代碼行數:31,代碼來源:main.go

示例4: redisGetHandler

func redisGetHandler(w http.ResponseWriter, r *http.Request) {
	var client *redis.Client
	var err error
	client = redis.New()
	err = client.Connect("localhost", 6379)
	if err != nil {
		fmt.Fprintf(w, "/connect fail/")
		return
	}
	defer client.Quit()

	key := r.FormValue("key")

	s, err := client.Get(key)

	if err != nil {
		fmt.Fprintf(w, "/values: is empty%s/", s)
		return
	}

	fmt.Fprintf(w, "/values:%s/", s)
}
開發者ID:redage,項目名稱:apps,代碼行數:22,代碼來源:test.go

示例5: redisSetHandler

func redisSetHandler(w http.ResponseWriter, r *http.Request) {
	value := r.FormValue("value")
	key := r.FormValue("key")
	fmt.Fprintf(w, "/set key:%s,value:%s/", key, value)
	var err error
	var client *redis.Client
	client = redis.New()
	err = client.Connect("localhost", 6379)
	if err != nil {
		fmt.Fprintf(w, "/connect fail/")
		return
	}
	defer client.Quit()

	client.Set(key, value)

	if err != nil {
		fmt.Fprintf(w, "/set values: is empty%s/")
		return
	}

	fmt.Fprintf(w, "/set key:%s,value:%s/", key, value)
}
開發者ID:redage,項目名稱:apps,代碼行數:23,代碼來源:test.go

示例6: 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
}
開發者ID:22morph,項目名稱:redis,代碼行數:30,代碼來源:main.go


注:本文中的github.com/gosexy/redis.Client類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。