• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang redis.Ints函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestCommonUsingDo

//-----------------------------------------------------------------------------
// Test
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//EXPIRE(key, seconds), TTL(key), INFO
//-----------------------------------------------------------------------------
func TestCommonUsingDo(t *testing.T) {
	//tu.SkipLog(t)

	sleepS := 2

	c := GetRedis().Conn

	c.Do("MSET", "key1", 20, "key2", 30)
	c.Do("HMSET", "key3:subkey1", "field1", 1, "field2", 2)
	c.Do("HMSET", "key3:subkey2", "field1", 99, "field2", 100)

	val, err := redis.Int(c.Do("GET", "key1"))
	if err != nil {
		t.Errorf("key1 is 10: value is %v, error is %s", val, err)
	}

	fields, err := redis.Ints(c.Do("HMGET", "key3:subkey1", "field1", "field2"))
	if err != nil {
		t.Errorf("field1 should be 1, field2 should be 1 but result is %#v, error is %s", fields, err)
	}

	//EXPIRE
	c.Do("EXPIRE", "key1", sleepS)
	c.Do("EXPIRE", "key3:subkey1", sleepS)

	//TTL
	s, err := redis.Int(c.Do("TTL", "key1"))
	if err != nil {
		t.Errorf("redis.Int(c.Do(\"TTL\", \"key1\")) error : %s", err)
	}
	lg.Debugf("TTL is %v", s)

	//sleep
	time.Sleep(time.Duration(sleepS+1) * time.Second)

	s, _ = redis.Int(c.Do("TTL", "key1"))
	lg.Debugf("TTL is %v", s)

	//It can't access
	val, err = redis.Int(c.Do("GET", "key1"))
	if err == nil {
		t.Errorf("key1 has already expired: value is %v", val)
	}

	//It can't access
	//TODO:somehow it can access. but value is 0
	fields, err = redis.Ints(c.Do("HMGET", "key3:subkey1", "field1", "field2"))
	//if err == nil {
	if err != nil || fields[0] != 0 || fields[1] != 0 {
		t.Errorf("key3:subkey1 has already expired: value is %+v", fields)
	}

	//It's OK.
	fields, err = redis.Ints(c.Do("HMGET", "key3:subkey2", "field1", "field2"))
	if err != nil {
		//if err != nil || fields[0] != 99 || fields[1] != 100 {
		t.Errorf("field1 should be 99, field2 should be 100 but result is %#v", fields)
	}
}
开发者ID:hiromaily,项目名称:golibs,代码行数:65,代码来源:redis_test.go


示例2: NewOrderFromRedis

// Get order from redis by id.
func NewOrderFromRedis(id string) (Order, error) {
	var order Order
	order.Id = id
	c := pool.Get()
	defer c.Close()
	hashName := fmt.Sprintf("o_%s", id)
	l, err := redis.Ints(c.Do("HGETALL", hashName))
	if err != nil {
		panic(err)
	}
	if len(l) == 0 {
		return order, ErrOrderNil
	}
	order.Items = make([]OrderFoodItem, len(l)/2)
	order.Total = 0
	for i := 0; i < len(l); i += 2 {
		foodId := l[i]
		price := food2Price[foodId]
		count := l[i+1]
		item := OrderFoodItem{FoodId: foodId, Count: count, Price: price}
		order.Items[i] = item
		order.Total = order.Total + count*price
	}
	return order, nil
}
开发者ID:KnowNo,项目名称:hackathon-2015,代码行数:26,代码来源:v.go


示例3: TestStringsUsingSend

//send is faster than do method
func TestStringsUsingSend(t *testing.T) {
	//tu.SkipLog(t)

	GetRedis().ConnectionS(3)

	c := GetRedis().Conn
	c.Send("SET", "key1", 10)
	c.Send("MSET", "key2", 20, "key3", 30)
	c.Flush()
	for i := 0; i < 3; i++ {
		c.Receive() //OK
	}

	//GET
	c.Send("GET", "key1")
	c.Flush()
	val, err := redis.Int(c.Receive())
	if err != nil || val != 10 {
		t.Errorf("key1 should be 10 but result is %d: err is %s", val, err)
	}

	//MGET
	c.Send("MGET", "key2", "key3")
	c.Flush()
	vals, err2 := redis.Ints(c.Receive())
	if err2 != nil || vals[0] != 20 || vals[1] != 30 {
		t.Errorf("key2 should be 20, key2 should be 30, but result is %#v: err is %s", vals, err2)
	}
}
开发者ID:hiromaily,项目名称:golibs,代码行数:30,代码来源:redis_test.go


示例4: TestListsUsingDo

//-----------------------------------------------------------------------------
func TestListsUsingDo(t *testing.T) {
	//tu.SkipLog(t)

	GetRedis().Connection(1)
	//GetRedisInstance().ConnectionS(2)

	c := GetRedis().Conn
	//c := GetRedisInstance().Pool.Get()

	//RPUSH
	for i := 10; i < 101; i++ {
		c.Do("RPUSH", "key-list1", i)
	}
	vals, _ := redis.Ints(c.Do("LRANGE", "key-list1", 0, -1))
	lg.Debugf("key-list1 values is %v", vals)

	//LPUSH
	for i := 9; i > 0; i-- {
		c.Do("LPUSH", "key-list1", i)
	}
	vals, _ = redis.Ints(c.Do("LRANGE", "key-list1", 0, -1))
	lg.Debugf("key-list1 values is %v", vals)

	//LSET(key, index, value)
	c.Do("LSET", "key-list1", 0, 100)
	result, _ := redis.Int(c.Do("LINDEX", "key-list1", 0))
	lg.Debugf("result of LSET is %v", result)

	//LTRIM(key, start, end)   //update list
	c.Do("LTRIM", "key-list1", 0, 9)
	vals, _ = redis.Ints(c.Do("LRANGE", "key-list1", 0, -1))
	//LLEN(key)   //get length of lists
	length, _ := redis.Int(c.Do("LLEN", "key-list1"))
	lg.Debugf("key-list1 value is %v, length is %d", vals, length)
	vals, _ = redis.Ints(c.Do("LRANGE", "key-list1", 0, -1))
	lg.Debugf("key-list1 values is %v", vals)

	//LPOP(key)
	result, _ = redis.Int(c.Do("LPOP", "key-list1"))
	lg.Debugf("result of LPOP is %v", result)
	result, _ = redis.Int(c.Do("RPOP", "key-list1"))
	lg.Debugf("result of RPOP is %v", result)

	vals, _ = redis.Ints(c.Do("LRANGE", "key-list1", 0, -1))
	lg.Debugf("key-list1 values is %v", vals)
}
开发者ID:hiromaily,项目名称:golibs,代码行数:47,代码来源:redis_test.go


示例5: ProbabilityOfLabel

func (dist RedisWordProbabilityDist) ProbabilityOfLabel(label SpamLabel) (float64, error) {
	labelCountKey := dist.label2namespace[label] + dist.textCountSuffix
	totalCountKey := dist.textCountSuffix
	results, err := redis.Ints(dist.conn.Do("MGET", labelCountKey, totalCountKey))
	if err != nil {
		return 0.0, err
	}
	labelCount, totalCount := results[0], results[1]
	return float64(labelCount) / float64(totalCount), nil
}
开发者ID:vroomwaddle,项目名称:spamlab,代码行数:10,代码来源:probability.go


示例6: BenchmarkSetBulkData01

//Bulk
func BenchmarkSetBulkData01(b *testing.B) {
	GetRedis().Connection(0)
	c := GetRedis().Conn

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		c.Do("SET", "key1", 10)
		c.Do("MSET", "key2", 20, "key3", 30)
		c.Do("HMSET", "key:subkey1", "field1", 1, "field2", 2)

		redis.Int(c.Do("GET", "key1"))
		redis.Ints(c.Do("MGET", "key2", "key3"))
		redis.Ints(c.Do("HMGET", "key:subkey1", "field1", "field2"))
	}
	b.StopTimer()

	dropDatabase()
	//220368 ns/op (220ms)
}
开发者ID:hiromaily,项目名称:golibs,代码行数:20,代码来源:redis_test.go


示例7: SetHash

func (a *Alerter) SetHash(key, field string, value []byte) {
	conn := a.pool.Get()
	defer conn.Close()
	// expire the key after 5 minutes
	conn.Send("MULTI")
	conn.Send("HSET", key, field, value)
	conn.Send("EXPIRE", key, 60*30)
	_, err := redis.Ints(conn.Do("EXEC"))
	if err != nil {
		fmt.Printf("ERROR: unable to set redis key %s\n", err.Error())
	}
}
开发者ID:adamliesko,项目名称:platform-ws-services,代码行数:12,代码来源:alerter.go


示例8: ShowOrdersController

func ShowOrdersController(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	r.ParseForm()
	var accessToken string
	if len(r.Form["access_token"]) > 0 {
		accessToken = r.Form["access_token"][0]
	} else {
		accessToken = r.Header.Get("Access-Token")
	}

	if len(accessToken) <= 0 {
		w.WriteHeader(401)
		fmt.Fprintf(w, `{"code": "INVALID_ACCESS_TOKEN", "message": "无效的令牌"}`)
		return
	}

	lua := `local uid = redis.call("get", "u:"..KEYS[1])
		local oid = redis.call("get", "u:o:"..uid)
		if oid then
			local menu = redis.call("hgetall", "o:f:"..oid)
			return {uid, oid, menu}
		end`
	var getScript = redis.NewScript(1, lua)
	c := rp.Get()
	reply, _ := redis.Values(getScript.Do(c, accessToken))

	var json bytes.Buffer
	if len(reply) != 0 {
		var userId, orderId string
		var items []interface{}
		redis.Scan(reply, &userId, &orderId, &items)

		var total int = 0
		var j []string
		v, _ := redis.Ints(items, nil)
		for i := 0; i < len(v); i += 2 {
			fid := v[i]
			cnt := v[i+1]
			total += gfoods[fid].Price * cnt
			j = append(j, fmt.Sprintf(`{"food_id": %d, "count": %d}`, fid, cnt))
		}
		json.WriteString("[{")
		json.WriteString(fmt.Sprintf(`"id": "%s", `, orderId))
		json.WriteString(fmt.Sprintf(`"items": [%s]`, strings.Join(j, ",")))
		json.WriteString(fmt.Sprintf(`,"total": %d`, total))
		json.WriteString("}]")

	} else {
		json.WriteString("{}")
	}

	w.WriteHeader(200)
	fmt.Fprintf(w, json.String())
}
开发者ID:ele828,项目名称:eleme-hackathon,代码行数:53,代码来源:main.go


示例9: ExampleInts

func ExampleInts() {
	c, err := dial()
	if err != nil {
		panic(err)
	}
	defer c.Close()

	c.Do("SADD", "set_with_integers", 4, 5, 6)
	ints, _ := redis.Ints(c.Do("SMEMBERS", "set_with_integers"))
	fmt.Printf("%#v\n", ints)
	// Output:
	// []int{4, 5, 6}
}
开发者ID:cfxks1989,项目名称:redigo,代码行数:13,代码来源:reply_test.go


示例10: GetFrequency

func (rw *RedisWrapper) GetFrequency(req *ParsedRequest, creatives *InventoryCollection) (response []int, err error) {
	conn := rw.redisPool.Get()
	defer conn.Close()
	frIds := make([]interface{}, creatives.Len())
	for index, value := range creatives.Data {
		frIds[index] = fmt.Sprintf("%v%v_%v",
			rw.configure.RedisFrequencyPrefix, req.Cid, value.ModelSign1)
	}
	if response, err = redis.Ints(conn.Do("mget", frIds...)); err != nil {
		rw.logger.Warning("redis error: %v", err.Error())
	}
	return
}
开发者ID:yangzhao28,项目名称:rtblite,代码行数:13,代码来源:redis.go


示例11: BenchmarkSetBulkData02

func BenchmarkSetBulkData02(b *testing.B) {
	GetRedis().ConnectionS(3)
	c := GetRedis().Conn
	c.Flush()
	c.Receive()

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		c.Send("SET", "key1", 10)
		c.Send("MSET", "key2", 20, "key3", 30)
		c.Send("HMSET", "key:subkey1", "field1", 1, "field2", 2)
		c.Flush()
		for i := 0; i < 3; i++ {
			c.Receive() //OK
		}

		//#1
		c.Send("GET", "key1")
		c.Flush()
		redis.Int(c.Receive())

		//#2
		c.Send("MGET", "key2", "key3")
		c.Flush()
		redis.Ints(c.Receive())

		//#3
		c.Send("HMGET", "key:subkey1", "field1", "field2")
		c.Flush()
		redis.Ints(c.Receive())
	}
	b.StopTimer()

	dropDatabase()
	//149114 ns/op (149ms)
}
开发者ID:hiromaily,项目名称:golibs,代码行数:36,代码来源:redis_test.go


示例12: isFinished

// isFinished returns true if the task has finished.
func (r *RedisRTC) isFinished(id string) bool {
	c := r.redisPool.Get()
	defer util.Close(c)

	util.LogErr(c.Send("MULTI"))
	util.LogErr(c.Send("EXISTS", r.key(id)))
	util.LogErr(c.Send("EXISTS", r.errorKey(id)))
	resArr, err := redis.Ints(c.Do("EXEC"))
	if err != nil {
		glog.Errorf("Unable to check if key exits: %s", err)
		return false
	}

	return (resArr[0] + resArr[1]) > 0
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:16,代码来源:rtc.go


示例13: TestHashesUsingDo

func TestHashesUsingDo(t *testing.T) {
	//tu.SkipLog(t)

	c := GetRedis().Conn
	//c := GetRedisInstance().Pool.Get()
	c.Do("HMSET", "key:subkey1", "field1", 1, "field2", 2)

	fields, err := redis.Ints(c.Do("HMGET", "key:subkey1", "field1", "field2"))
	if err != nil || fields[0] != 1 || fields[1] != 2 {
		t.Errorf("field1 should be 1, field2 should be 2 but result is %#v: err is %s", fields, err)
	}

	//HGETALL
	fields2, _ := redis.StringMap(c.Do("HGETALL", "key:subkey1"))
	lg.Debugf("HGETALL: %v, %s, %s", fields2, fields2["field1"], fields2["field2"])
}
开发者ID:hiromaily,项目名称:golibs,代码行数:16,代码来源:redis_test.go


示例14: TestSetsUsingDo

func TestSetsUsingDo(t *testing.T) {
	//tu.SkipLog(t)

	GetRedis().Connection(1)
	//GetRedisInstance().ConnectionS(2)

	c := GetRedis().Conn
	//c := GetRedisInstance().Pool.Get()

	key := "key-set1"

	//RPUSH
	for i := 0; i < 10; i++ {
		c.Do("SADD", key, i)
	}
	vals, _ := redis.Ints(c.Do("SMEMBERS", key))
	lg.Debugf("%s values is %v", key, vals)
}
开发者ID:hiromaily,项目名称:golibs,代码行数:18,代码来源:redis_test.go


示例15: ProbabilityOfTextGivenLabel

func (dist RedisWordProbabilityDist) ProbabilityOfTextGivenLabel(text Text, label SpamLabel) (float64, error) {
	labelWordCountKey := dist.label2namespace[label] + dist.wordCountSuffix
	wordKeys := dist.textToKeys(label, text...)
	allKeys := append([]interface{}{labelWordCountKey}, wordKeys...)
	result, err := redis.Ints(dist.conn.Do("MGET", allKeys...))
	if err != nil {
		return 0.0, err
	}
	nWordsInLabel := float64(result[0])
	prob := 1.0
	for _, wordFreq := range result[1:] {
		if wordFreq == 0 {
			wordFreq = 1 // add-one smoothing
		}
		prob *= float64(wordFreq) / nWordsInLabel
	}
	return prob, nil
}
开发者ID:vroomwaddle,项目名称:spamlab,代码行数:18,代码来源:probability.go


示例16: NumSub

func (this __red) NumSub(messages ...interface{}) []int {
	channels := []interface{}{}
	for _, message := range messages {
		switch message := message.(type) {

		default:
			_ = message
			panic("Unsupported message type")
		}
	}

	conn := this.__.(redis.Conn)
	nrecvs, err := redis.Ints(conn.Do("pubsub numsub", channels...))
	if err != nil {
		panic(err)
	}

	return nrecvs
}
开发者ID:themakers,项目名称:red-go,代码行数:19,代码来源:red.gen.go


示例17: Check

func (s *SBFFrame) Check(conn redis.Conn, element []byte) bool {
	var flag int = 1
	hashes := murmur.Hashes(element, s.SliceCount, s.SliceSize)
	// check bit val
	conn.Send("MULTI")
	for index, h := range hashes {
		pos := uint32(index)*s.SliceSize + s.StartIndex + h + SBF_FRAME_HEADER_SIZE<<3
		conn.Send("GETBIT", s.Refer, pos)
	}
	if data, err := redis.Ints(conn.Do("EXEC")); err == nil {
		for _, f := range data {
			flag = flag & f
			if flag != 1 {
				return false
			}
		}
		return (flag == 1)
	} else {
		return false
	}
}
开发者ID:appwilldev,项目名称:redis_sbf,代码行数:21,代码来源:sbf.go


示例18: TestStringsUsingDo

func TestStringsUsingDo(t *testing.T) {
	//tu.SkipLog(t)

	//GetRedisInstance().Connection(1)
	//GetRedisInstance().ConnectionS(2)

	c := GetRedis().Conn
	//c := GetRedisInstance().Pool.Get()
	c.Do("SET", "key1", 10)
	c.Do("MSET", "key2", 20, "key3", 30)

	val, err := redis.Int(c.Do("GET", "key1"))
	if err != nil || val != 10 {
		t.Errorf("key1 should be 10 but result is %d: err is %s", val, err)
	}

	vals, err2 := redis.Ints(c.Do("MGET", "key2", "key3"))
	if err2 != nil || vals[0] != 20 || vals[1] != 30 {
		t.Errorf("key2 should be 20, key2 should be 30, but result is %#v: err is %s", vals, err2)
	}
}
开发者ID:hiromaily,项目名称:golibs,代码行数:21,代码来源:redis_test.go


示例19: GetSumValue

func (p *RedisCounterStorage) GetSumValue(counterName string, dimensionsGroup [][]string) (sumDimVal int64, err error) {
	if dimensionsGroup == nil {
		return
	}

	conn := p.pool.Get()
	defer conn.Close()

	keyPrefix := p.redisConfig.Prefix + _COUNTER_ + counterName

	keys := []interface{}{}

	for _, dim := range dimensionsGroup {
		dimKey := ""
		if dim != nil {
			dimKey = strings.Join(dim, ":")
		}

		keys = append(keys, keyPrefix+":"+dimKey)
	}

	vals, err := conn.Do("MGET", keys...)

	var intVals []int
	if intVals, err = redis.Ints(vals, err); err != nil {
		return
	}

	sumV := 0
	for _, v := range intVals {
		sumV += v
	}

	sumDimVal = int64(sumV)

	return
}
开发者ID:admpub,项目名称:access_limiter,代码行数:37,代码来源:redis_counter_storage.go


示例20: main

func main() {
	flag.Parse()
	runtime.GOMAXPROCS(runtime.NumCPU())
	var err error

	file, err := os.Open(*configFile)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	decoder := json.NewDecoder(file)
	config := config.Configuration{}
	err = decoder.Decode(&config)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	if config.Host == "" || config.ClientId == "" {
		fmt.Println("Missing Configs", config)
		os.Exit(1)
	}

	if config.MaxWorkers > 0 {
		max_workers = config.MaxWorkers
	}

	c := crawler.New(config)
	defer c.Close()

	crawler := Crawler{c}

	// We are able to get the highest track id on our own.
	max_id, err := crawler.GetHighTrackId()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Handle signals to stop crawling.
	var canCrawl bool = true
	stopCrawler := make(chan os.Signal, 1)
	signal.Notify(stopCrawler, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		<-stopCrawler
		fmt.Println("Exit signal recieved. Will finish up current crawls and exit the program.")
		canCrawl = false
		close(track_ids)
		close(playlist_ids)
	}()

	track_ids = make(chan int, max_workers)
	var trackMonitor sync.WaitGroup
	trackMonitor.Add(max_workers)
	for i := 0; i < max_workers; i++ {
		go crawler.ProcessTracks(&trackMonitor)
	}

	r := c.RedisClient.Get()
	defer r.Close()

	// If we want to restart crawls due to a server crash...
	if *restartTodo == true && *useEmpty == false && canCrawl {
		playlists, _ := redis.Ints(r.Do("SMEMBERS", "crawlPlaylistsTodo"))
		for _, i := range playlists {
			r.Do("SADD", "crawlPlaylists", i)
		}
		tracks, _ := redis.Ints(r.Do("SMEMBERS", "crawlPlaylistsTodo"))
		for _, i := range tracks {
			r.Do("SADD", "crawlTracks", i)
		}
	}

	// Starts a new crawl from scratch...
	if *useEmpty == true && canCrawl {
		r.Do("DEL", "crawlTracks")
		batch_max := int(max_id/1000) + 1
		for i := batch_max; i > 0; i-- {
			nulls := []interface{}{fmt.Sprintf("trackMeta:%d", i)}
			track_id := i * 1000
			for k := 999; k >= 0; k-- {
				nulls = append(nulls, fmt.Sprintf("%d", (track_id+k)), "null")
			}
			r.Do("HMSET", nulls...)
			r.Do("SADD", "crawlTracks", i)
		}
	}

	var hasMoreTracks bool = true
	for hasMoreTracks && canCrawl {
		// Add all of the tracks that are scheduled to be crawled into a channel
		i, err := redis.Int(r.Do("SPOP", "crawlTracks"))
		if err != nil {
			hasMoreTracks = false
		} else {
			r.Do("SADD", "crawlTracksTodo", i)
			track_ids <- i
		}
	}
	close(track_ids)
	// Wait for all of the tracks to be crawled before going onto the playlists
//.........这里部分代码省略.........
开发者ID:Abramovic,项目名称:soundclouder,代码行数:101,代码来源:cli.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang redis.MultiBulk函数代码示例发布时间:2022-05-23
下一篇:
Golang redis.Int64函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap