当前位置: 首页>>代码示例>>Golang>>正文


Golang redis.Client类代码示例

本文整理汇总了Golang中menteslibres/net/gosexy/redis.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: PutRedisClient

func PutRedisClient(client *redis.Client) {
	if RedisClientPool == nil {
		RedisClientPool = make(chan *redis.Client, MAX_POOL_SIZE)
	}
	if len(RedisClientPool) >= MAX_POOL_SIZE {
		client.Quit()
		return
	}
	RedisClientPool <- client
}
开发者ID:panjianbo,项目名称:gosrc,代码行数:10,代码来源:redis_pool.go

示例2: handler

func handler(p *httputil.ReverseProxy, redisClient *redis.Client) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {

		hash := hashKey(r)

		serializableResponse := SerializableResponse{make(map[string][]string), nil}

		s, err := redisClient.Get(hash)
		if err != nil { // The request is not cached
			rec := httptest.NewRecorder()
			log.Println("Non cached: " + hash)

			// Perform the real request and cache it
			p.ServeHTTP(rec, r)

			for k, v := range rec.Header() {
				serializableResponse.Header[k] = v
			}
			serializableResponse.Body = rec.Body.Bytes()

			jsonResponse, err := json.Marshal(serializableResponse)
			if err != nil {
				panic(err)
			}
			redisClient.Set(hash, jsonResponse)
			w.Header().Set("X-Eidetic", "Live request")

		} else { // The request is cached
			log.Println("Cached!: " + hash)

			// Load the cached request
			err = json.Unmarshal([]byte(s), &serializableResponse)
			if err != nil {
				panic(err)
			}

			w.Header().Set("X-Eidetic", "Cached request")

		}

		//Copy the data to the actual ResponseWriter
		// log.Println("\n\n\nResponse Headers:")
		for k, v := range serializableResponse.Header {
			w.Header()[k] = v
			// log.Println(k + ": ")
			// for _, str := range v {
			// 	log.Println("  " + str)
			// }
		}
		w.Write([]byte(serializableResponse.Body))
		// log.Println("\nResponse body:\n" + string(serializableResponse.Body))

	}
}
开发者ID:javiertoledo,项目名称:eidetic,代码行数:54,代码来源:eidetic.go

示例3: spawnConsumer

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

	consumer = redis.New()

	err = consumer.ConnectNonBlock(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("Consumer will read exactly 6 messages before quitting.\n")

	go consumer.Subscribe(rec, "channel")

	var ls []string

	for j := 0; j < 6; j++ {
		ls = <-rec
		log.Printf("Consumer received message[%d]: %v\n", j, strings.Join(ls, ", "))
	}

	log.Printf("Closing consumer...\n")

	consumer.Quit()

	return nil
}
开发者ID:carriercomm,项目名称:redis-3,代码行数:34,代码来源:main.go

示例4: 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
		}
	}
}
开发者ID:Wuyue,项目名称:Gsm,代码行数:22,代码来源:gsm.go

示例5: processSerialData

func (s SerialReader) processSerialData(redisConnection *redis.Client) {
	serialConnection := s.newSerialConnection()
	reader := bufio.NewReader(serialConnection)
	re := regexp.MustCompile("^([^:]+):(.+)$")

	for {
		reply, err := reader.ReadBytes('\n')

		if err != nil {
			log.Printf("processSerialData() #1: %s", err)
			continue
		}

		data := strings.TrimSpace(string(reply))

		if len(data) == 0 {
			continue
		}

		log.Printf("%s", data)
		raw_data := re.FindStringSubmatch(data)

		if len(raw_data) == 0 {
			continue
		}

		metrics := strings.Split(raw_data[2], ",")
		channel := fmt.Sprintf("rpi-moteino-collector:%s", raw_data[1])

		for i := 0; i < len(metrics); i++ {
			metric_key_and_value := strings.Split(metrics[i], ":")

			if len(metric_key_and_value) != 2 {
				continue
			}

			value := fmt.Sprintf("%s,%d,%s", metric_key_and_value[0], uint64(time.Now().Unix()), metric_key_and_value[1])

			_, err := redisConnection.LPush(channel, value)
			if err != nil {
				log.Printf("processSerialData() #2: %s", err)
			}

			_, err = redisConnection.Publish(channel, value)
			if err != nil {
				log.Printf("processSerialData() #3: %s", err)
			}
		}

		_, err = redisConnection.LTrim(channel, 0, 10)
		if err != nil {
			log.Printf("processSerialData() #4: %s", err)
		}
	}
}
开发者ID:ashmckenzie,项目名称:rpi-moteino-collector,代码行数:55,代码来源:main.go

示例6: 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()
}
开发者ID:panjianbo,项目名称:gosrc,代码行数:13,代码来源:redis.go

示例7: 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:carriercomm,项目名称:redis-3,代码行数:30,代码来源:main.go


注:本文中的menteslibres/net/gosexy/redis.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。