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


Golang redis.ScanSlice函数代码示例

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


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

示例1: GetTagsSubscriptions

// GetTagsSubscriptions returns all subscriptions for given tags list
func (connector *DbConnector) GetTagsSubscriptions(tags []string) ([]SubscriptionData, error) {
	c := connector.Pool.Get()
	defer c.Close()

	log.Debug("Getting tags %v subscriptions", tags)

	tagKeys := make([]interface{}, 0, len(tags))
	for _, tag := range tags {
		tagKeys = append(tagKeys, fmt.Sprintf("moira-tag-subscriptions:%s", tag))
	}
	values, err := redis.Values(c.Do("SUNION", tagKeys...))
	if err != nil {
		return nil, fmt.Errorf("Failed to retrieve subscriptions for tags %v: %s", tags, err.Error())
	}
	var subscriptions []string
	if err := redis.ScanSlice(values, &subscriptions); err != nil {
		return nil, fmt.Errorf("Failed to retrieve subscriptions for tags %v: %s", tags, err.Error())
	}
	if len(subscriptions) == 0 {
		log.Debug("No subscriptions found for tag set %v", tags)
		return make([]SubscriptionData, 0, 0), nil
	}

	var subscriptionsData []SubscriptionData
	for _, id := range subscriptions {
		sub, err := db.GetSubscription(id)
		if err != nil {
			continue
		}
		subscriptionsData = append(subscriptionsData, sub)
	}
	return subscriptionsData, nil
}
开发者ID:tantra35,项目名称:notifier,代码行数:34,代码来源:db.go

示例2: syndicateStatus

// adds a status to a user's follower's timelines
func syndicateStatus(uid, sid, time string, c redis.Conn) (bool, error) {
	defer c.Close()
	// get all the followers user ids sorted by score
	// if this is exceptionally large we may want to do the syndication in stages
	r, err := redis.Values(c.Do("ZRANGEBYSCORE", "followers:"+uid, "-inf",
		"+inf"))

	if err != nil {
		return false, err
	}

	var followerSlice []string
	if err := redis.ScanSlice(r, &followerSlice); err != nil {
		return false, nil
	}
	// push the status in a single transaction
	c.Do("MULTI")
	for i := range followerSlice {
		c.Do("ZADD", "timeline:"+followerSlice[i], time, sid)
	}
	if _, err := c.Do("EXEC"); err != nil {
		return false, err
	}
	return true, nil
}
开发者ID:yungyikim,项目名称:simple,代码行数:26,代码来源:db.go

示例3: FriendCount

func (logger *RedisLogger) FriendCount(userid string) (follows, followers, friends, blacklist int) {
	conn := logger.conn

	conn.Send("MULTI")
	conn.Send("SCARD", redisUserFollowPrefix+userid)
	conn.Send("SCARD", redisUserFollowerPrefix+userid)
	conn.Send("SCARD", redisUserBlacklistPrefix+userid)
	values, err := redis.Values(conn.Do("EXEC"))
	if err != nil {
		log.Println(err)
		return
	}
	counts := make([]int, 3)

	if err := redis.ScanSlice(values, &counts); err != nil {
		log.Println(err)
		return
	}

	follows = counts[0]
	followers = counts[1]
	blacklist = counts[2]
	friends = len(logger.Friends("friend", userid))
	return
}
开发者ID:shevilangle,项目名称:sports,代码行数:25,代码来源:redis.go

示例4: adminHandler

func adminHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	uid := checkToken(r)

	if userCache["root"].Id == uid {
		rc := *(getRC())
		defer rc.Close()

		res, _ := redis.Values(rc.Do("HGETALL", "order"))
		var arr []string
		redis.ScanSlice(res, &arr)

		responseJson := new(bytes.Buffer)
		responseJson.WriteString("[")
		for i := 0; i < len(arr); i += 2 {
			if i != 0 {
				responseJson.WriteString(",")
			}
			responseJson.WriteString(arr[i+1])
		}
		responseJson.WriteString("]")

		response(&w, 200, responseJson.Bytes())
	} else {
		responseInvalidToken(&w)
	}
}
开发者ID:fcjy,项目名称:eleme-hackathon,代码行数:26,代码来源:main.go

示例5: GetList

func (this *User) GetList(request *restful.Request, response *restful.Response) {
	var r resp
	pool := NewPool()
	c := pool.Get()

	keys := "user_list:*"
	var user User_format
	var user_array []User_format

	var list_user []string
	result, err := redis.Values(c.Do("KEYS", keys))

	if result == nil || err != nil {
		r.Status = "fail"
		r.Errmsg = "no user"
		response.WriteEntity(r)
		return
	}

	redis.ScanSlice(result, &list_user)
	for _, value := range list_user {
		data, _ := GetService(value)
		json.Unmarshal(data, &user)
		user_array = append(user_array, user)
	}

	r.Status = "ok"
	r.Data = user_array
	response.WriteEntity(r)
	return
}
开发者ID:w19900227,项目名称:gooauth,代码行数:31,代码来源:main.go

示例6: ExampleScanSlice

func ExampleScanSlice() {
	c, err := dial()
	if err != nil {
		fmt.Println(err)
		return
	}
	defer c.Close()

	c.Send("HMSET", "album:1", "title", "Red", "rating", 5)
	c.Send("HMSET", "album:2", "title", "Earthbound", "rating", 1)
	c.Send("HMSET", "album:3", "title", "Beat", "rating", 4)
	c.Send("LPUSH", "albums", "1")
	c.Send("LPUSH", "albums", "2")
	c.Send("LPUSH", "albums", "3")
	values, err := redis.Values(c.Do("SORT", "albums",
		"BY", "album:*->rating",
		"GET", "album:*->title",
		"GET", "album:*->rating"))
	if err != nil {
		fmt.Println(err)
		return
	}

	var albums []struct {
		Title  string
		Rating int
	}
	if err := redis.ScanSlice(values, &albums); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("%v\n", albums)
	// Output:
	// [{Earthbound 1} {Beat 4} {Red 5}]
}
开发者ID:kpumuk,项目名称:redigo,代码行数:35,代码来源:scan_test.go

示例7: noteIDs

func noteIDs(db redis.Conn) []int64 {
	var ids []int64
	rawIDs, err := redis.Values(db.Do("LRANGE", "notable:notes", 0, -1))
	check(err)

	redis.ScanSlice(rawIDs, &ids)

	return ids
}
开发者ID:joshualcoffee,项目名称:notable,代码行数:9,代码来源:notes.go

示例8: GetDisLB

func (logger *RedisLogger) GetDisLB(start, stop int) []KV {
	values, _ := redis.Values(logger.conn.Do("ZREVRANGE", redisDisLeaderboard, start, stop, "WITHSCORES"))
	var s []KV

	if err := redis.ScanSlice(values, &s); err != nil {
		log.Println(err)
		return nil
	}
	return s
}
开发者ID:shevilangle,项目名称:sports,代码行数:10,代码来源:redis.go

示例9: updateHosts

func updateHosts() {
	values, err := redis.Values(conn.Do("SMEMBERS", "turn/hosts"))
	if err != nil {
		panic(err)
	}
	var hosts []string
	if err := redis.ScanSlice(values, &hosts); err != nil {
		panic(err)
	}
	turn.Hosts = hosts
}
开发者ID:yao2907,项目名称:turnhttp,代码行数:11,代码来源:turnhttp-server.go

示例10: Int64s

func (*RedisStore) Int64s(reply interface{}, err error) ([]int64, error) {
	var ints []int64
	values, err := redis.Values(reply, err)
	if err != nil {
		return ints, err
	}
	if err := redis.ScanSlice(values, &ints); err != nil {
		return ints, err
	}
	return ints, nil
}
开发者ID:cosiner,项目名称:kv,代码行数:11,代码来源:kv_redis.go

示例11: ListSubject

func (a *app) ListSubject() (subs []string, err error) {
	reply, err := redis.Values(a.rpool.Get().Do("PUBSUB", "CHANNELS"))
	if err != nil {
		return
	}
	if len(reply) == 0 {
		return
	}
	if err = redis.ScanSlice(reply, &subs); err != nil {
		return
	}
	return
}
开发者ID:syhlion,项目名称:redisocket,代码行数:13,代码来源:redisocket.go

示例12: int64s

func int64s(reply interface{}, err error) ([]int64, error) {
	if err != nil {
		return nil, slog.Wrap(err)
	}
	ints := []int64{}
	values, err := redis.Values(reply, err)
	if err != nil {
		return ints, slog.Wrap(err)
	}
	if err := redis.ScanSlice(values, &ints); err != nil {
		return ints, slog.Wrap(err)
	}
	return ints, nil
}
开发者ID:nicollet,项目名称:bosun,代码行数:14,代码来源:state_data.go

示例13: zrange

func (logger *RedisLogger) zrange(key string, start, stop int, reverse bool) (kv []KV) {
	cmd := "ZRANGE"
	if reverse {
		cmd = "ZREVRANGE"
	}

	values, _ := redis.Values(logger.conn.Do(cmd, key, start, stop, "WITHSCORES"))

	if err := redis.ScanSlice(values, &kv); err != nil {
		log.Println(err)
		return nil
	}

	return
}
开发者ID:shevilangle,项目名称:sports,代码行数:15,代码来源:redis.go

示例14: ReadLogs

// Returns logs stored in the list specified by logName.
func ReadLogs(conn redis.Conn, logName string, limit int) (logs []string) {
	reply, err := redis.Values(conn.Do("LRANGE", logName, 0, limit))
	if err != nil {
		log.Fatal(err)
	}
	if err := redis.ScanSlice(reply, &logs); err != nil {
		log.Fatal(err)
	}
	// can also use the following code to deal with sring reply
	// 	for len(reply) > 0 {
	// 		var logString string
	// 		reply, err = redis.Scan(reply, &logString)
	// 		log.Println(logString)
	// 	}
	return
}
开发者ID:yanghu,项目名称:go-logger,代码行数:17,代码来源:writer.go

示例15: TestScanSlice

func TestScanSlice(t *testing.T) {
	for _, tt := range scanSliceTests {

		typ := reflect.ValueOf(tt.dest).Type()
		dest := reflect.New(typ)

		err := redis.ScanSlice(tt.src, dest.Interface(), tt.fieldNames...)
		if tt.ok != (err == nil) {
			t.Errorf("ScanSlice(%v, []%s, %v) returned error %v", tt.src, typ, tt.fieldNames, err)
			continue
		}
		if tt.ok && !reflect.DeepEqual(dest.Elem().Interface(), tt.dest) {
			t.Errorf("ScanSlice(src, []%s) returned %#v, want %#v", typ, dest.Elem().Interface(), tt.dest)
		}
	}
}
开发者ID:kpumuk,项目名称:redigo,代码行数:16,代码来源:scan_test.go


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