本文整理匯總了Golang中github.com/garyburd/redigo/redis.Values函數的典型用法代碼示例。如果您正苦於以下問題:Golang Values函數的具體用法?Golang Values怎麽用?Golang Values使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Values函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestHashMget
func TestHashMget(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := redis.Dial("tcp", s.Addr())
ok(t, err)
s.HSet("wim", "zus", "jet")
s.HSet("wim", "teun", "vuur")
s.HSet("wim", "gijs", "lam")
s.HSet("wim", "kees", "bok")
v, err := redis.Values(c.Do("HMGET", "wim", "zus", "nosuch", "kees"))
ok(t, err)
equals(t, 3, len(v))
equals(t, "jet", string(v[0].([]byte)))
equals(t, nil, v[1])
equals(t, "bok", string(v[2].([]byte)))
v, err = redis.Values(c.Do("HMGET", "nosuch", "zus", "kees"))
ok(t, err)
equals(t, 2, len(v))
equals(t, nil, v[0])
equals(t, nil, v[1])
// Wrong key type
s.Set("foo", "bar")
_, err = redis.Int(c.Do("HMGET", "foo", "bar"))
assert(t, err != nil, "no HMGET error")
}
示例2: QPeek
func (c *client) QPeek(queueName string, count int) ([]job, error) {
conn, err := c.get()
if err != nil {
return nil, err
}
reply, err := redis.Values(conn.Do("QPEEK", queueName, count))
if err != nil {
return nil, err
}
result := make([]job, 0, len(reply))
for _, v := range reply {
if value, err := redis.Values(v, nil); err != nil {
return nil, err
} else {
queueName, err := redis.String(value[0], nil)
id, err := redis.String(value[1], err)
data, err := redis.Bytes(value[2], err)
if err != nil {
return nil, err
}
result = append(result, job{QueueName: queueName, Id: id, Body: data})
}
}
return result, nil
}
示例3: decode
func (mapDec *mapDecoder) decode(node RMNode, data interface{}, v reflect.Value) {
values, err := redis.Values(node.Value(), nil)
if err != nil {
panic(err)
}
size := len(values) / 2
vals, err := redis.Values(node.Value(), nil)
if err != nil {
panic(err)
}
v.Set(reflect.MakeMap(v.Type()))
for i := 0; i < size; i++ {
mKey, err := redis.String(values[i*2], nil)
if err != nil {
panic(err)
}
elemV := newValueForType(v.Type().Elem())
if i < node.Size() {
mapDec.elemFunc(node.Child(i), vals[i*2+1], elemV)
} else {
mapDec.elemFunc(node, vals[i*2+1], elemV)
}
v.SetMapIndex(reflect.ValueOf(mKey), elemV)
}
}
示例4: SlotsInfo
func SlotsInfo(addr, passwd string, fromSlot, toSlot int) (map[int]int, error) {
c, err := DialTo(addr, passwd)
if err != nil {
return nil, err
}
defer c.Close()
infos, err := redis.Values(c.Do("SLOTSINFO", fromSlot, toSlot-fromSlot+1))
if err != nil {
return nil, errors.Trace(err)
}
slots := make(map[int]int)
if infos != nil {
for i := 0; i < len(infos); i++ {
info, err := redis.Values(infos[i], nil)
if err != nil {
return nil, errors.Trace(err)
}
var slotid, slotsize int
if _, err := redis.Scan(info, &slotid, &slotsize); err != nil {
return nil, errors.Trace(err)
} else {
slots[slotid] = slotsize
}
}
}
return slots, nil
}
示例5: TestMget
func TestMget(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := redis.Dial("tcp", s.Addr())
ok(t, err)
s.Set("zus", "jet")
s.Set("teun", "vuur")
s.Set("gijs", "lam")
s.Set("kees", "bok")
{
v, err := redis.Values(c.Do("MGET", "zus", "nosuch", "kees"))
ok(t, err)
equals(t, 3, len(v))
equals(t, "jet", string(v[0].([]byte)))
equals(t, nil, v[1])
equals(t, "bok", string(v[2].([]byte)))
}
// Wrong key type returns nil
{
s.HSet("aap", "foo", "bar")
v, err := redis.Values(c.Do("MGET", "aap"))
ok(t, err)
equals(t, 1, len(v))
equals(t, nil, v[0])
}
}
示例6: ListKeys
// offset From where to scan.
// prefix The prefix string to scan.
//
// Return: (offset, keys, error), if the offset is 0, means the scan is over.
func ListKeys(offset int64, prefix *string) (int64, []string, error) {
if prefix == nil {
return 0, nil, errors.New("Prefix can't be nil.")
}
conn, err := getConn()
if err != nil {
return 0, nil, err
}
defer (*conn).Close()
var v []interface{}
v, err = redis.Values((*conn).Do("SCAN", offset, *prefix))
if err != nil {
return 0, nil, err
}
var newOffset int64
newOffsetS := string(v[0].([]byte))
newOffset, err = strconv.ParseInt(newOffsetS, 10, 64)
if err != nil {
return 0, nil, err
}
keys := make([]string, 0)
sv, _ := redis.Values(v[1], nil)
for _, value := range sv {
key := string(value.([]byte))
keys = append(keys, key)
}
return newOffset, keys, nil
}
示例7: ZRangeByScore
func (r *RedisCache) ZRangeByScore(v interface{}, set string, dir bool, limit int64) ([]int64, error) {
var values []interface{}
var err error
t := GetBaseType(v)
// Using LIMIT offset for pagination has bad performance
// so always use 0 offset and implement elsewhere
if dir == HIGH_TO_LOW {
values, err = redis.Values(r.C.Do(
"ZREVRANGEBYSCORE",
"set"+r.Sep+r.GetTypePrefix(t)+r.Sep+set,
"+inf",
"-inf",
"WITHSCORES",
"LIMIT",
"0",
strconv.FormatInt(limit, 10)))
} else {
// LOW_TO_HIGH
values, err = redis.Values(r.C.Do(
"ZRANGEBYSCORE",
"set"+r.Sep+r.GetTypePrefix(t)+r.Sep+set,
"-inf",
"+inf",
"WITHSCORES",
"LIMIT",
"0",
strconv.FormatInt(limit, 10)))
}
if err != nil {
return nil, err
}
val := reflect.ValueOf(v)
switch val.Kind() {
case reflect.Ptr:
val = reflect.Indirect(val)
}
reply_len := len(values) / 2
list := reflect.MakeSlice(val.Type(), reply_len, reply_len)
scores := make([]int64, reply_len)
for i := 0; i < reply_len; i++ {
scores[i], err = redis.Int64(values[(i*2)+1], nil)
if err != nil {
return nil, err
}
b, err := redis.Bytes(values[i*2], nil)
if err != nil {
return nil, err
}
r.S.Unmarshal(b, list.Index(i).Addr().Interface())
}
val.Set(list)
return scores, nil
}
示例8: SendOfflineMsg
func SendOfflineMsg(client *Client, appid string) {
// connect to Redis
redisConn, err := redis.Dial("tcp", ":6379")
if err != nil {
log.Printf("Dial redix error: %s", err.Error())
return
}
// get the timestamp
var reply []interface{}
reply, err = redis.Values(redisConn.Do("TIME"))
if err != nil {
log.Printf("Error on TIME: %s", err.Error())
return
}
var current_time int64
_, err = redis.Scan(reply, ¤t_time)
// get offline message for each App on this device
key := "broadcast_msg:" + appid
reply, err = redis.Values(redisConn.Do("ZRANGE", key, 0, -1))
if err != nil {
log.Printf("Error on ZRANGE: %s", err.Error())
goto Out
}
for len(reply) > 0 {
var msg_id int64
reply, err = redis.Scan(reply, &msg_id)
if err != nil {
log.Printf("Error on Scan ZRANGE reply: %s", err.Error())
goto Out
}
log.Printf("offline msg_id: %d", msg_id)
key = "msg:" + strconv.FormatInt(msg_id, 10)
var reply_msg []interface{}
reply_msg, err = redis.Values(redisConn.Do("HMGET", key, "msg", "expire_time"))
if err != nil {
log.Printf("Error on HMGET: %s", err.Error())
goto Out
}
var msg string
var expire_time int64
_, err = redis.Scan(reply_msg, &msg, &expire_time)
if err != nil {
log.Printf("Error on Scan HMGET reply: %s", err.Error())
goto Out
}
//log.Printf("expire_time: %d, msg: %s", expire_time, msg)
if expire_time > current_time {
// message hasn't expired, need to send it
client.SendMsg(msg, appid)
}
}
Out:
redisConn.Close()
}
示例9: main
func main() {
m := martini.Classic()
// Handle the "/results" API method
m.Get("/results/:check_id", func(params martini.Params, res http.ResponseWriter, req *http.Request) string {
conn := redisPool.Get()
// Parse the url to get the query paramenter named "limit" and convert to int
limit, _ := strconv.ParseInt(req.URL.Query().Get("limit"), 10, 64)
// Query redis for the last "limit" results for the given "check_id"
reply, err := redis.Values(conn.Do("LRANGE", "results:"+params["check_id"], -limit, -1))
for {
if err == nil {
break
} else {
log.Printf("Redis error in LRANGE results: %s\n", err)
reply, err = redis.Values(conn.Do("LRANGE", "results:"+params["check_id"], -limit, -1))
}
}
conn.Close()
return string(getJsonResults(reply))
})
// Handle the "/checks" API method
m.Get("/checks", func(params martini.Params) string {
conn := redisPool.Get()
// Query redis all the available "checks"
reply, err := redis.Values(conn.Do("LRANGE", "checks", 0, -1))
for {
if err == nil {
break
} else {
log.Printf("Redis error in LRANGE checks: %s\n", err)
reply, err = redis.Values(conn.Do("LRANGE", "checks", 0, -1))
}
}
conn.Close()
return string(getJsonChecks(reply))
})
fmt.Printf("[martini] Listening on port 5000\n")
err := http.ListenAndServe("0.0.0.0:5000", m)
if err != nil {
fmt.Printf("Error: %s", err)
}
}
示例10: LoadUserAccessToken
func LoadUserAccessToken(token string) (int64, int64, string, error) {
conn := redis_pool.Get()
defer conn.Close()
key := fmt.Sprintf("access_token_%s", token)
var uid int64
var appid int64
var uname string
exists, err := redis.Bool(conn.Do("EXISTS", key))
if err != nil {
return 0, 0, "", err
}
if !exists {
return 0, 0, "", errors.New("token non exists")
}
reply, err := redis.Values(conn.Do("HMGET", key, "user_id", "app_id", "user_name"))
if err != nil {
log.Info("hmget error:", err)
return 0, 0, "", err
}
_, err = redis.Scan(reply, &uid, &appid, &uname)
if err != nil {
log.Warning("scan error:", err)
return 0, 0, "", err
}
return appid, uid, uname, nil
}
示例11: mgetResults
func (oper *MultiOperator) mgetResults(mop *MulOp) ([]byte, error) {
slotmap := getSlotMap(mop.keys)
results := make([]interface{}, len(mop.keys))
conn := oper.pool.Get()
defer conn.Close()
for _, vec := range slotmap {
req := make([]interface{}, 0, len(vec))
for _, p := range vec {
req = append(req, p.key)
}
replys, err := redis.Values(conn.Do("mget", req...))
if err != nil {
return nil, errors.Trace(err)
}
for i, reply := range replys {
if reply != nil {
results[vec[i].pos] = reply
} else {
results[vec[i].pos] = nil
}
}
}
b, err := respcoding.Marshal(results)
return b, errors.Trace(err)
}
示例12: GetAndDeleteSet
func (r *RedisStorageManager) GetAndDeleteSet(keyName string) []interface{} {
db := r.pool.Get()
defer db.Close()
log.Debug("Getting raw gkey set: ", keyName)
if db == nil {
log.Warning("Connection dropped, connecting..")
r.Connect()
r.GetAndDeleteSet(keyName)
} else {
log.Debug("keyName is: ", keyName)
fixedKey := r.fixKey(keyName)
log.Debug("Fixed keyname is: ", fixedKey)
db.Send("MULTI")
// Get all the elements
db.Send("LRANGE", fixedKey, 0, -1)
// Trim it to zero
db.Send("DEL", fixedKey)
// Execute
r, err := redis.Values(db.Do("EXEC"))
vals := r[0].([]interface{})
log.Debug("Returned: ", vals)
if err != nil {
log.Error("Multi command failed: ", err)
}
return vals
}
return []interface{}{}
}
示例13: TestBlankCommmand
func TestBlankCommmand(t *testing.T) {
c, err := redis.DialTestDB()
if err != nil {
t.Fatalf("error connection to database, %v", err)
}
defer c.Close()
for _, cmd := range testCommands {
if err := c.Send(cmd.args[0].(string), cmd.args[1:]...); err != nil {
t.Fatalf("Send(%v) returned error %v", cmd.args, err)
}
}
reply, err := redis.Values(c.Do(""))
if err != nil {
t.Fatalf("Do() returned error %v", err)
}
if len(reply) != len(testCommands) {
t.Fatalf("len(reply)=%d, want %d", len(reply), len(testCommands))
}
for i, cmd := range testCommands {
actual := reply[i]
if !reflect.DeepEqual(actual, cmd.expected) {
t.Errorf("Receive(%v) = %v, want %v", cmd.args, actual, cmd.expected)
}
}
}
示例14: Next
func (iter *RedisIterator) Next() bool {
iter.cursor += 1
if len(iter.cacheJob) > 0 && len(iter.cacheJob) > iter.cursor {
return true
}
start := iter.start
stop := iter.start + iter.limit - 1
iter.start = iter.start + iter.limit
var err error
var conn = iter.r.pool.Get()
defer conn.Close()
var key string
if iter.Func == nil {
key = REDIS_PREFIX + "ID"
} else {
key = REDIS_PREFIX + string(iter.Func) + ":name"
}
reply, err := redis.Values(conn.Do("ZRANGE", key, start, stop, "WITHSCORES"))
if err != nil || len(reply) == 0 {
return false
}
var jobId int64
jobs := make([]driver.Job, len(reply)/2)
for k, v := range reply {
if k%2 == 1 {
jobId, _ = strconv.ParseInt(string(v.([]byte)), 10, 0)
jobs[(k-1)/2], _ = iter.r.get(jobId)
}
}
iter.cacheJob = jobs
iter.cursor = 0
return true
}
示例15: checkZrange
func (self *SortedSetGenerator) checkZrange(conn redis.Conn, req_num int32, range_data int32, mytime *time.Timer) {
var pos int32 = 0
for ; pos < req_num; pos++ {
select {
case <-mytime.C:
return
default:
value := self.data_list[pos%ZRANGE_ALL]
reporter.Resultdata.AddSendQuantity()
reply, err := redis.Values(conn.Do("ZRANGE", value.key, 0, range_data))
//log.Info("redis operating: zrange %d 0 %d", value.key, range_data)
if err != nil {
log.Info("redis operating: zrange %d 0 %d error %v", value.key, range_data, err)
reporter.Resultdata.AddFailQuantity()
} else {
//log.Info(" zrange %d 0 %d ret:%v", value.key, range_data, reply)
/*type IntArrayChecker struct {
myuid []int64
youruid []interface{}
}*/
datacheck := &reporter.IntArrayChecker{Myuid: value.sortedlist, Youruid: reply}
reporter.Datasummer.AddChecker(datacheck)
}
}
}
}