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


Golang redis.Client類代碼示例

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


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

示例1: ReceiveScanEvent

func ReceiveScanEvent(content string) string {
	var this ScanEvent
	fmt.Println(content)
	err := xml.Unmarshal([]byte(content), &this)
	if err != nil {
		return ""
	}
	data := "請聯係係統管理員進行身份認證"
	if "101" == this.EventKey &&
		"oecJ3jhN5usPBQMIXqc9bVP0toi4" == this.Ticket {
		data = "吼吼吼"
		var redcli redis.Client
		redcli.Addr = beego.AppConfig.String("redis_addr")
		redcli.Hset(this.Ticket, "scan", []byte("true"))
	}
	fmt.Println(data)
	rcontent := `<xml>
<ToUserName><![CDATA[` + this.FromUserName + `]]></ToUserName>
<FromUserName><![CDATA[` + this.ToUserName + `]]></FromUserName>
<CreateTime>` + fmt.Sprint((time.Now().Unix())) + `</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[` + data + `]]></Content>
</xml>`
	return rcontent
}
開發者ID:wcgh,項目名稱:beewechat,代碼行數:25,代碼來源:scan.go

示例2: getArticle

func getArticle(client redis.Client, page int, order string) []map[string]string {
	if order == "" {
		order = "score:"
	}

	start := (page - 1) * ARTICLES_PER_PAGE
	end := start + ARTICLES_PER_PAGE - 1

	ids, err := client.Zrevrange(order, start, end)
	if err != nil {
		log.Fatal("Zrevrange エラーだよ", err.Error())
	}

	articles := make([]map[string]string, 0)
	for _, id := range ids {

		articleData := make(map[string]string, 0)
		if err := client.Hgetall(string(id), articleData); err != nil {
			log.Fatal("Hgetall エラーだよ", err.Error())
		}
		articleData["id"] = string(id)

		articles = append(articles, articleData)
	}

	return articles
}
開發者ID:kyokomi-sandbox,項目名稱:sandbox,代碼行數:27,代碼來源:main_hoisie_redis.go

示例3: main

func main() {

	// 創建一個redis客戶端
	var client redis.Client
	// 嘗試從緩存中拿數據
	val, err := client.Get("Dog")

	// 檢查緩存命中
	if err != nil {
		fmt.Println("Error fetching from", err)
	} else {
		fmt.Println("Cache hit")

		dog, err := DecodeData(val)
		if err != nil {
			fmt.Println("Error decoding data from memcache", err)
		} else {
			fmt.Println("Dog name is: ", dog.Name)
		}
	}

	// 創建對象實例
	spot := Dog{Name: "Spot", Color: "brown"}

	err = client.Set("Dog", EncodeData(spot))
	if err != nil {
		fmt.Println("Error setting memcache item", err)
	}

}
開發者ID:jackerloong,項目名稱:working-with-go-zh-cn,代碼行數:30,代碼來源:21-memcache-objects.go

示例4: alreadyBeingHandled

func alreadyBeingHandled(input string) bool {

	c := redis.Client{Addr: addr, Password: pass}
	c.Auth(pass)
	check, _ := c.Exists(input)
	return check

}
開發者ID:postfix,項目名稱:spamdetector,代碼行數:8,代碼來源:spamdetect.go

示例5: GetUserListInfo

/// 獲取用戶信息列表
func GetUserListInfo() {
	var redcli redis.Client
	redcli.Addr = beego.AppConfig.String("redis_addr")
	key := "wx_UserList"
	b, _ := redcli.Lrange(key, 0, -1)
	for _, v := range b {
		GetUserInfo(fmt.Sprintf("%s", v))
	}
}
開發者ID:wcgh,項目名稱:beewechat,代碼行數:10,代碼來源:wx_user.go

示例6: Index

func (c App) Index(call string) revel.Result {
	var client redis.Client
	// c.Response.ContentType = "application/json"
	callsign, _ := client.Get("callsign:" + strings.ToUpper(call))
	log.Printf(string(callsign))
	// log.Printf(json.Marshal(callsign))
	callsign_data := string(callsign)
	return c.Render(call, callsign_data)
}
開發者ID:hamli,項目名稱:search-go,代碼行數:9,代碼來源:app.go

示例7: GetUserList

///	獲取用戶列表並報錯到redis數據庫中 KEY=wx_UserList
func GetUserList() {
	url := "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + GetAccessToken()
	key := "wx_UserList"
	var v WXUserList
	c, status := global.HttpGet(url)
	if status >= 0 {
		dec := json.NewDecoder(strings.NewReader(c))
		for {
			if err := dec.Decode(&v); err == io.EOF {
				break
			} else if err != nil {
				log.Fatal(err)
			}
		}

		var redcli redis.Client
		redcli.Addr = beego.AppConfig.String("redis_addr")

		if ok, err := redcli.Exists(key); err != nil {
			log.Println(err.Error())
		} else {
			if ok {
				redcli.Del(key)
			}
		}
		for _, value := range v.Data.Openid {
			redcli.Rpush(key, []byte(value))
		}
		log.Println("Successful: Add Userlist ")
	}
}
開發者ID:wcgh,項目名稱:beewechat,代碼行數:32,代碼來源:wx_user.go

示例8: addRemoveGroups

func addRemoveGroups(client redis.Client, articleID int, toAdd, toRemove []string) {

	article := "article:" + strconv.Itoa(articleID)

	for _, group := range toAdd {
		if _, err := client.Sadd("group:"+group, []byte(article)); err != nil {
			log.Fatal("Sadd エラーだよ", err.Error())
		}
	}

	for _, group := range toRemove {
		if _, err := client.Srem("group:"+group, []byte(article)); err != nil {
			log.Fatal("Srem エラーだよ", err.Error())
		}
	}
}
開發者ID:kyokomi-sandbox,項目名稱:sandbox,代碼行數:16,代碼來源:main_hoisie_redis.go

示例9: checkLearningDB

func checkLearningDB(msg string) bool {
	/*set up redis client*/
	c := redis.Client{Addr: addr, Password: pass}
	c.Auth(pass)

	// hash the message
	hash := md5hash(msg) // check databse
	check, _ := c.Exists(hash)

	if check == true {
		return true
	} else {

		return false
	}

}
開發者ID:postfix,項目名稱:spamdetector,代碼行數:17,代碼來源:spamdetect.go

示例10: getGroupArticle

func getGroupArticle(client redis.Client, group string, page int) []map[string]string {
	order := "score:"

	key := order + group

	if ok, err := client.Exists(key); err != nil {
		log.Fatal("Exists エラーだよ", err.Error())
	} else if !ok {
		//if _, err := client.Zinterstore(key, "group:" + group, order); err != nil {
		//	log.Fatal("Zinterstore エラーだよ", err.Error())
		//}

		if _, err := client.Expire(key, 60); err != nil {
			log.Fatal("Expire エラーだよ", err.Error())
		}
	}

	return getArticle(client, page, key)
}
開發者ID:kyokomi-sandbox,項目名稱:sandbox,代碼行數:19,代碼來源:main_hoisie_redis.go

示例11: setToBeHandled

func setToBeHandled(input string) {

	c := redis.Client{Addr: addr, Password: pass}
	c.Auth(pass)

	c.Set(input, "1")
	c.Expire(input, EXPIRETIME)

}
開發者ID:postfix,項目名稱:spamdetector,代碼行數:9,代碼來源:spamdetect.go

示例12: articleVote

func articleVote(client redis.Client, user, article string) {

	cutoff := time.Now().Add(ONE_WEEK_DAY * time.Second)

	// 記事チェック
	if hit, err := client.Exists("time:"); err != nil {
		log.Fatal("Existsエラーだよ", err.Error())
	} else if !hit {
		log.Fatal("記事がないよ ")
	}

	// 期限チェック
	if score, err := client.Zscore("time:", []byte(article)); err != nil {
		log.Fatal("Zscoreエラーだよ", err.Error())
	} else {
		if cutoff.After(time.Unix(int64(score), 0)) {
			fmt.Println("Afterだった ", cutoff.Unix(), " ", int64(score))
			return
		}
	}

	articleID := strings.TrimPrefix(article, "article:")
	fmt.Println("articleID", articleID)

	ok, err := client.Sadd("voted:"+articleID, []byte(user))
	if err != nil {
		log.Fatal("Saddエラーだよ", err.Error())
	}

	if ok {
		if _, err := client.Zincrby("score:", []byte(article), VOTE_SCORE); err != nil {
			log.Fatal("Zincrbyエラーだよ", err.Error())
		}
		if _, err := client.Hincrby(article, "votes", 1); err != nil {
			log.Fatal("Hincrbyエラーだよ", err.Error())
		}
	}
}
開發者ID:kyokomi-sandbox,項目名稱:sandbox,代碼行數:38,代碼來源:main_hoisie_redis.go

示例13: Poll

/*
 * Poll the worker's job queue
 * jobHandlers - a reference to the clients map of available job handlers
 */
func (this Worker) Poll(jobHandlers map[string]reflect.Type) {
	for {
		// Pop a job off the queue
		var client redis.Client
		_, message, err := client.Blpop([]string{this.Queue}, 1)

		if err != nil {
			fmt.Println(fmt.Sprintf("ERROR: %s\n", err))
		} else if len(message) > 0 {
			// Basic debugging information
			// fmt.Println(this.Name + ": Yay Work Work Work!")
			// fmt.Println(string(message))

			// Parse the message
			name, params, err := this.parseMessage(message)

			if err != nil {
				fmt.Println(fmt.Sprintf("ERROR: %s\n", err))
			} else {
				// Construct the handler and call the execute() function
				jobHandler := reflect.New(jobHandlers[name])
				executeMethod := jobHandler.MethodByName("Execute")
				if executeMethod.IsValid() {
					executeMethod.Call([]reflect.Value{0: reflect.ValueOf(params)})
				} else {
					fmt.Println(fmt.Sprintf("ERROR: Invalid job handler"))
				}
			}
		} else {
			// fmt.Println(this.Name + ": Nothing to do :(\n")
		}

		// Sleep for 2 seconds before polling the queue again
		time.Sleep(2 * time.Second)
	}
}
開發者ID:backstitch,項目名稱:go-to-work,代碼行數:40,代碼來源:worker.go

示例14: main

func main() {
	client := redis.Client{Addr: "192.168.1.101:6379"}
	// client.Addr = "127.0.0.1:6379"

	client.Hmset("h1", map[string]string{"Key3": "abc", "Key4": "sdfs",
		"key1": "abc", "key2": "sdfs"})

	m := make(map[string]string)
	client.Hgetall("h1", m)
	log.Println(m)

	a := AA{}
	client.Hgetall("h1", &a)
	log.Println(a)
}
開發者ID:aimeiyan,項目名稱:gocode,代碼行數:15,代碼來源:redis2.go

示例15: GetTempTicket

func GetTempTicket(expire_seconds int, scene_id int, scene_str string) string {
	url := `https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=` + GetAccessToken()
	data := `{"expire_seconds": ` + strconv.Itoa(expire_seconds) +
		`, "action_name": "QR_SCENE", ` +
		`"action_info": {"scene": {"scene_id": ` + strconv.Itoa(scene_id) +
		`,"scene_str":"` + scene_str + `"}}}`
	if ticket := getTicket(url, data); len(ticket) < 1 {
		return ""
	} else {
		var redcli redis.Client
		redcli.Addr = beego.AppConfig.String("redis_addr")
		redcli.Hset(ticket, "scene_id", []byte(strconv.Itoa(scene_id)))
		redcli.Expire(ticket, 120)
		return ticket
	}
}
開發者ID:yankaics,項目名稱:beewechat,代碼行數:16,代碼來源:wx_qr.go


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