本文整理匯總了Golang中github.com/garyburd/redigo/redis.MultiBulk函數的典型用法代碼示例。如果您正苦於以下問題:Golang MultiBulk函數的具體用法?Golang MultiBulk怎麽用?Golang MultiBulk使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了MultiBulk函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: DeleteScanMatch
// DeleteKeys will remove a group of keys in bulk
func (r *RedisClusterStorageManager) DeleteScanMatch(pattern string) bool {
if GetRelevantClusterReference(r.IsCache) == nil {
log.Info("Connection dropped, connecting..")
r.Connect()
return r.DeleteScanMatch(pattern)
}
log.Debug("Deleting: ", pattern)
// here we'll store our iterator value
iter := "0"
// this will store the keys of each iteration
var keys []string
for {
// we scan with our iter offset, starting at 0
arr, err := redis.MultiBulk(GetRelevantClusterReference(r.IsCache).Do("SCAN", iter, "MATCH", pattern))
if err != nil {
log.Error("SCAN Token Get Failure: ", err)
return false
}
// now we get the iter and the keys from the multi-bulk reply
iter, _ = redis.String(arr[0], nil)
theseKeys, _ := redis.Strings(arr[1], nil)
keys = append(keys, theseKeys...)
// check if we need to stop...
if iter == "0" {
break
}
}
if len(keys) > 0 {
for _, v := range keys {
name := "" + v
log.Info("Deleting: ", name)
_, err := GetRelevantClusterReference(r.IsCache).Do("DEL", name)
if err != nil {
log.Error("Error trying to delete key: ", v, " - ", err)
}
}
log.Info("Deleted: ", len(keys), " records")
} else {
log.Debug("RedisClusterStorageManager called DEL - Nothing to delete")
}
return true
}
示例2: TestHashM
func TestHashM(t *testing.T) {
startTestApp()
c := getTestConn()
defer c.Close()
key := []byte("b")
if ok, err := redis.String(c.Do("hmset", key, 1, 1, 2, 2, 3, 3)); err != nil {
t.Fatal(err)
} else if ok != OK {
t.Fatal(ok)
}
if n, err := redis.Int(c.Do("hlen", key)); err != nil {
t.Fatal(err)
} else if n != 3 {
t.Fatal(n)
}
if v, err := redis.MultiBulk(c.Do("hmget", key, 1, 2, 3, 4)); err != nil {
t.Fatal(err)
} else {
if err := testHashArray(v, 1, 2, 3, 0); err != nil {
t.Fatal(err)
}
}
if n, err := redis.Int(c.Do("hdel", key, 1, 2, 3, 4)); err != nil {
t.Fatal(err)
} else if n != 3 {
t.Fatal(n)
}
if n, err := redis.Int(c.Do("hlen", key)); err != nil {
t.Fatal(err)
} else if n != 0 {
t.Fatal(n)
}
if v, err := redis.MultiBulk(c.Do("hmget", key, 1, 2, 3, 4)); err != nil {
t.Fatal(err)
} else {
if err := testHashArray(v, 0, 0, 0, 0); err != nil {
t.Fatal(err)
}
}
if n, err := redis.Int(c.Do("hlen", key)); err != nil {
t.Fatal(err)
} else if n != 0 {
t.Fatal(n)
}
}
示例3: TestHashGetAll
func TestHashGetAll(t *testing.T) {
startTestApp()
c := getTestConn()
defer c.Close()
key := []byte("d")
if ok, err := redis.String(c.Do("hmset", key, 1, 1, 2, 2, 3, 3)); err != nil {
t.Fatal(err)
} else if ok != OK {
t.Fatal(ok)
}
if v, err := redis.MultiBulk(c.Do("hgetall", key)); err != nil {
t.Fatal(err)
} else {
if err := testHashArray(v, 1, 1, 2, 2, 3, 3); err != nil {
t.Fatal(err)
}
}
if v, err := redis.MultiBulk(c.Do("hkeys", key)); err != nil {
t.Fatal(err)
} else {
if err := testHashArray(v, 1, 2, 3); err != nil {
t.Fatal(err)
}
}
if v, err := redis.MultiBulk(c.Do("hvals", key)); err != nil {
t.Fatal(err)
} else {
if err := testHashArray(v, 1, 2, 3); err != nil {
t.Fatal(err)
}
}
if n, err := redis.Int(c.Do("hclear", key)); err != nil {
t.Fatal(err)
} else if n != 3 {
t.Fatal(n)
}
if n, err := redis.Int(c.Do("hlen", key)); err != nil {
t.Fatal(err)
} else if n != 0 {
t.Fatal(n)
}
}
示例4: TestKVM
func TestKVM(t *testing.T) {
c := getTestConn()
defer c.Close()
if ok, err := redis.String(c.Do("mset", "a", "1", "b", "2")); err != nil {
t.Fatal(err)
} else if ok != OK {
t.Fatal(ok)
}
if v, err := redis.MultiBulk(c.Do("mget", "a", "b", "c")); err != nil {
t.Fatal(err)
} else if len(v) != 3 {
t.Fatal(len(v))
} else {
if vv, ok := v[0].([]byte); !ok || string(vv) != "1" {
t.Fatal("not 1")
}
if vv, ok := v[1].([]byte); !ok || string(vv) != "2" {
t.Fatal("not 2")
}
if v[2] != nil {
t.Fatal("must nil")
}
}
}
示例5: testListRange
func testListRange(key []byte, start int64, stop int64, checkValues ...int) error {
c := getTestConn()
defer c.Close()
vs, err := redis.MultiBulk(c.Do("lrange", key, start, stop))
if err != nil {
return err
}
if len(vs) != len(checkValues) {
return fmt.Errorf("invalid return number %d != %d", len(vs), len(checkValues))
}
var n int
for i, v := range vs {
if d, ok := v.([]byte); ok {
n, err = strconv.Atoi(string(d))
if err != nil {
return err
} else if n != checkValues[i] {
return fmt.Errorf("invalid data %d: %d != %d", i, n, checkValues[i])
}
} else {
return fmt.Errorf("invalid data %v %T", v, v)
}
}
return nil
}
示例6: popMessage
func popMessage(conn redis.Conn, key string) (*Message, error) {
reply, err := redis.MultiBulk(conn.Do("BLPOP", key, DEFAULTTIMEOUT))
if err != nil {
return nil, err
}
return parseMessage(reply)
}
示例7: GetFields
func (this *RedisClient) GetFields(PK interface{}, fields []string) (map[string]string, error) {
key := fmt.Sprintf("PK:%v", PK)
//var value string
var comm []interface{}
comm = append(comm, key)
for _, v := range fields {
comm = append(comm, v)
}
//fmt.Printf("Comm : %v \n",comm)
conn := this.pool.Get()
defer conn.Close()
reply, err := redis.MultiBulk(conn.Do("HMGET", comm...))
if err != nil {
return nil, err
}
//var list = make([]string, 0)
var res = make(map[string]string)
for index, v := range reply {
s, err := redis.String(v, nil)
if err != nil {
return nil, err
}
s = strings.Trim(s, "\"")
res[fields[index]] = s
// list = append(list, s)
}
//fmt.Printf("\n ALL REDIS RESULT :: %v\n", res)
return res, nil
}
示例8: sendRedisMigrateCmd
// return: success_count, remain_count, error
// slotsmgrt host port timeout slotnum count
func (m *migrater) sendRedisMigrateCmd(c redis.Conn, slotId int, toAddr string) (bool, error) {
addrParts := strings.Split(toAddr, ":")
if len(addrParts) != 2 {
return false, ErrInvalidAddr
}
//use scan and migrate
reply, err := redis.MultiBulk(c.Do("scan", 0))
if err != nil {
return false, err
}
var next string
var keys []interface{}
if _, err := redis.Scan(reply, &next, &keys); err != nil {
return false, err
}
for _, key := range keys {
if _, err := c.Do("migrate", addrParts[0], addrParts[1], key, slotId, MIGRATE_TIMEOUT); err != nil {
//todo, try del if key exists
return false, err
}
}
return next != "0", nil
}
示例9: Start
func (j *Job) Start() error {
Debugf("Starting job: %d", j.Id)
client := j.client
// Send job arguments
if len(j.Args) > 0 {
args := append([]interface{}{fmt.Sprintf("%s/args", j.key())}, asInterfaceSlice(j.Args)...)
if _, err := client.send("RPUSH", args...); err != nil {
return err
}
}
// Send environment vars
if len(j.Env) > 0 {
env := append([]interface{}{fmt.Sprintf("%s/env", j.key())}, asInterfaceSlice(splitEnv(j.Env))...)
if _, err := client.send("HMSET", env...); err != nil {
return err
}
}
j.exitFailure, j.exitSuccess = make(chan bool), make(chan bool)
// Start waiting for exit
go func() {
Debugf("Waiting for job: %d", j.Id)
reply, err := redis.MultiBulk(client.send("BLPOP", fmt.Sprintf("%s/wait", j.key()), DEFAULTTIMEOUT))
Debugf("Job complete: %d", j.Id)
if err != nil {
j.exitError = err
j.exitFailure <- true
return
}
status := reply[1].([]byte)
// Status will be empty for success
if len(status) == 0 {
j.exitSuccess <- true
return
}
buffer := bytes.NewBuffer(status)
code, err := strconv.Atoi(buffer.String())
if err != nil {
j.exitError = err
j.exitFailure <- true
return
}
j.ExitStatus = code
j.exitFailure <- true
}()
// Send start job
if _, err := client.send("RPUSH", fmt.Sprintf("/jobs/start"), j.Id); err != nil {
return err
}
return nil
}
示例10: GetDistribution
func GetDistribution(distribution string) ([]interface{}, error) {
rdb := redisServer.GetConnection()
rdb.Send("MULTI")
rdb.Send("GET", fmt.Sprintf("%s.%s", distribution, "_T"))
rdb.Send("ZRANGE", distribution, 0, -1, "WITHSCORES")
data, err := redis.MultiBulk(rdb.Do("EXEC"))
return data, err
}
示例11: GetNMostProbable
func GetNMostProbable(distribution string, N int) ([]interface{}, error) {
rdb := redisServer.GetConnection()
rdb.Send("MULTI")
rdb.Send("ZREVRANGEBYSCORE", distribution, "+INF", "-INF", "WITHSCORES", "LIMIT", 0, N)
rdb.Send("GET", fmt.Sprintf("%s.%s", distribution, "_Z"))
rdb.Send("GET", fmt.Sprintf("%s.%s", distribution, "_T"))
data, err := redis.MultiBulk(rdb.Do("EXEC"))
return data, err
}
示例12: GetField
func GetField(distribution, field string) ([]interface{}, error) {
rdb := redisServer.GetConnection()
rdb.Send("MULTI")
rdb.Send("ZSCORE", distribution, field)
rdb.Send("GET", fmt.Sprintf("%s.%s", distribution, "_Z"))
rdb.Send("GET", fmt.Sprintf("%s.%s", distribution, "_T"))
data, err := redis.MultiBulk(rdb.Do("EXEC"))
return data, err
}
示例13: GetFields
func (this *RedisClient) GetFields(PK interface{}, fields []string) (map[string]string, error) {
key := fmt.Sprintf("PK:%v", PK)
//var value string
var comm []interface{}
comm = append(comm, key)
for _, v := range fields {
comm = append(comm, v)
}
//fmt.Printf("Comm : %v \n",comm)
conn := this.pool.Get()
defer conn.Close()
reply, err := redis.MultiBulk(conn.Do("HMGET", comm...))
if err != nil {
return nil, err
}
//var list = make([]string, 0)
var res = make(map[string]string)
for index, v := range reply {
s, err := redis.String(v, nil)
if err != nil {
return nil, err
}
s = strings.Trim(s, "\"")
res[fields[index]] = s
// list = append(list, s)
}
//fmt.Printf("\n ALL REDIS RESULT :: %v\n", res)
return res, nil
/*
res, err := redis.Values(conn.Do("HMGET", comm...))
if err != nil {
this.logger.Error("REDIS ERROR : %v ", err)
return nil,err
}
fmt.Printf("\n ALL REDIS RESULT :: %v\n", res)
values :=make([]string,len(fields))
if _, err := redis.Scan(res, values...); err != nil {
// handle error
return nil,err
}
fmt.Printf("REDISE STRING :: ")
for _,v:=range values{
fmt.Printf(" %v ",v)
}
fmt.Printf("\n")
*/
return nil, err
}
示例14: Scan
func Scan(cursor int) (results ScanResults, err error) {
client := pool.Get()
data, err := redis.MultiBulk(client.Do("SCAN", cursor, "COUNT", "1000"))
if err != nil {
return results, err
}
results.Iterator, _ = redis.Int(data[0], nil)
results.Keys, _ = redis.Strings(data[1], nil)
return results, err
}
示例15: GetField
func GetField(distribution string, fields ...string) ([]interface{}, error) {
rdb := redisServer.GetConnection()
defer rdb.Close()
rdb.Send("MULTI")
for _, field := range fields {
rdb.Send("ZSCORE", distribution, field)
}
rdb.Send("ZCARD", distribution)
rdb.Send("GET", fmt.Sprintf("%s.%s", distribution, "_Z"))
rdb.Send("GET", fmt.Sprintf("%s.%s", distribution, "_T"))
data, err := redis.MultiBulk(rdb.Do("EXEC"))
return data, err
}