本文整理匯總了Golang中github.com/garyburd/redigo/redis.StringMap函數的典型用法代碼示例。如果您正苦於以下問題:Golang StringMap函數的具體用法?Golang StringMap怎麽用?Golang StringMap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了StringMap函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Work
func (subscriber *Subscriber) Work(queueName string, concurrency int, fn Worker) {
subscriber.isRunning = true
subscriber.workChannel = make(chan string)
for i := 0; i < concurrency; i++ {
subscriber.wg.Add(1)
go subscriber.doWork(fn)
}
go func() {
for subscriber.isRunning {
connection := subscriber.connectionPool.Get()
data, err := connection.Do("BRPOP", "ceausescu:"+queueName, 0)
if err != nil {
log.Println(err)
continue
}
connection.Close()
result, err := redis.StringMap(data, nil)
if err != nil {
log.Println(err)
continue
}
subscriber.workChannel <- result["ceausescu:"+queueName]
}
}()
}
示例2: instanceIsMaster
func instanceIsMaster(pool *redis.Pool, port string) {
c := pool.Get()
defer c.Close()
for {
master, err := redis.StringMap(c.Do("CONFIG", "GET", "slaveof"))
if err != nil {
// Retry connection to Redis until it is back.
//log.Println(err)
defer c.Close()
time.Sleep(time.Second * time.Duration(connectionLostInterval))
c = pool.Get()
continue
}
for _, value := range master {
if value != "" {
// Instance is now a slave, notify.
if fetchPossible[port] {
c.Do("PUBLISH", "redis-scouter", "stop")
fetchPossible[port] = false
log.Printf("[instance-check-%s] became a slave", port)
}
} else {
// Re-enable metrics.
if !fetchPossible[port] {
fetchPossible[port] = true
log.Printf("[instance-check-%s] became a master", port)
}
}
}
time.Sleep(time.Second * time.Duration(masterCheckInterval))
}
}
示例3: GetRedisSlaves
func GetRedisSlaves(node *HANodeSt) {
redisConn := gRedisPool.Get()
defer redisConn.Close()
//values, err := redis.Strings(redisConn.Do("SENTINEL", "slaves", "mymaster" ))
//values, err := redisConn.Do("SENTINEL", "slaves", "mymaster" )
//values, err := redisConn.Do("get", "hello1" )
values, err := redis.Values(redisConn.Do("SENTINEL", "slaves", node.Name))
if err != nil {
log.Errorf("get master error:%s", err.Error())
}
slaveNo := len(values)
slaveList := list.New()
for i := 0; i < slaveNo; i++ {
smap, _ := redis.StringMap(values[i], nil)
host := smap["ip"]
port := smap["port"]
flag := smap["flags"]
if flag != "slave" {
continue
}
slaveList.PushBack(host + ":" + port)
}
node.Slaves = slaveList
//gHANodeMap[item] = node
}
示例4: GetJobs
//GetJobs returns all the command jobs
func (client *clientImpl) GetJobs(ID string, timeout int) ([]*Job, error) {
db := client.redis.Get()
defer db.Close()
queue := fmt.Sprintf(cmdQueueCmdQueued, ID)
data, err := db.Do("BRPOPLPUSH", queue, queue, timeout)
if err != nil {
return nil, err
}
if data == nil {
return nil, TIMEOUT
}
resultQueue := fmt.Sprintf(hashCmdResults, ID)
jobsdata, err := redis.StringMap(db.Do("HGETALL", resultQueue))
if err != nil {
return nil, err
}
results := make([]*Job, 0, 10)
for _, jobdata := range jobsdata {
result := &Job{}
if err := json.Unmarshal([]byte(jobdata), result); err != nil {
return nil, err
}
result.redis = client.redis
results = append(results, result)
}
return results, nil
}
示例5: Expired
// Expired implements the `func Expired` defined on the Strategy interface. It
// scans iteratively over the Heart's `location` field to look for items that
// have expired. An item is marked as expired iff the last update time happened
// before the instant of the maxAge subtracted from the current time.
func (s HashExpireyStrategy) Expired(location string,
pool *redis.Pool) (expired []string, err error) {
now := time.Now()
cnx := pool.Get()
defer cnx.Close()
reply, err := redis.StringMap(cnx.Do("HGETALL", location))
if err != nil {
return
}
for id, tick := range reply {
lastUpdate, err := time.Parse(DefaultTimeFormat, tick)
if err != nil {
continue
} else if lastUpdate.Add(s.MaxAge).Before(now) {
expired = append(expired, id)
}
}
return
}
示例6: forward
func forward(incoming, outgoing chan slack.Message) {
c := redisPool.Get()
defer c.Close()
for m := range incoming {
if m.Type != "message" {
continue
}
ok, err := redis.Bool(c.Do("SISMEMBER", KEY_CHANNELS, m.Channel))
if err != nil {
log.Println(err)
} else if ok {
fwdMap, err := redis.StringMap(c.Do("HGETALL", m.Channel))
if err != nil {
log.Println(err)
} else {
for query, toChanId := range fwdMap {
ok, err := regexp.MatchString(query, m.Text)
if err != nil {
log.Println(err)
} else if ok {
m.Channel = toChanId
outgoing <- m
}
}
}
}
}
}
示例7: getItemScores
func (rr *Redrec) getItemScores(item string, max int) (map[string]string, error) {
scores, err := redis.StringMap(rr.rconn.Do("ZREVRANGE", fmt.Sprintf("item:%s:scores", item), 0, max))
if err != nil {
return nil, err
}
return scores, nil
}
示例8: queueStats
func queueStats(port string) {
// Connect to redis.
pool := newPool(port)
c := pool.Get()
if !instanceAlive(pool) {
log.Printf("error: cannot connect to redis on port %s, aborting\n", port)
return
}
// Subscribe to the keyspace notifications.
c.Send("PSUBSCRIBE", "[email protected]*", "redis-scouter")
c.Flush()
// Ignore first two ACKs when subscribing.
c.Receive()
c.Receive()
go instanceIsMaster(pool, port)
go keyspaceEnable(pool, port)
for {
if fetchPossible[port] {
reply, err := redis.StringMap(c.Receive())
if err != nil {
// Retry connection to Redis until it is back.
defer c.Close()
log.Printf("connection to redis lost. retry in %ds\n", connectionLostInterval)
time.Sleep(time.Second * time.Duration(connectionLostInterval))
c = pool.Get()
//go keyspaceEnable(pool, port)
c.Send("PSUBSCRIBE", "[email protected]*", "redis-scouter")
c.Flush()
c.Receive()
c.Receive()
continue
}
// Match for a LIST keyspace event.
for k, v := range reply {
if v == "stop" {
// Break loop if we get a message on redis-scouter pubsub.
continue
}
operation := listOperationsRegex.FindString(v)
queue := keyspaceRegex.FindStringSubmatch(k)
if len(queue) == 2 && operation != "" {
Stats.Add(fmt.Sprintf("%s.%s.%s", port, queue[1], operation), 1)
}
}
} else {
// Do not fetch stats for now.
time.Sleep(time.Second * time.Duration(fetchMetricsInterval))
}
}
}
示例9: GetStringMap
// GetStringMap returns map[string]string, err by its key
//returns nil and a filled error if something wrong happens
func (r *Service) GetStringMap(key string) (map[string]string, error) {
redisVal, err := r.Get(key)
if redisVal == nil {
return nil, ErrKeyNotFound.Format(key)
}
_map, err := redis.StringMap(redisVal, err)
if err != nil {
return nil, err
}
return _map, nil
}
示例10: c_redis_counters
func c_redis_counters(server string, db int) (opentsdb.MultiDataPoint, error) {
var md opentsdb.MultiDataPoint
conn, err := redis.Dial("tcp", server, redis.DialDatabase(db))
if err != nil {
return md, err
}
defer conn.Close()
if _, err := conn.Do("CLIENT", "SETNAME", "scollector"); err != nil {
return md, err
}
cursor := 0
for {
vals, err := redis.Values(conn.Do("HSCAN", collect.RedisCountersKey, cursor))
if err != nil {
return md, err
}
if len(vals) != 2 {
return md, fmt.Errorf("Unexpected number of values")
}
cursor, err = redis.Int(vals[0], nil)
if err != nil {
return md, err
}
pairs, err := redis.StringMap(vals[1], nil)
if err != nil {
return md, err
}
for mts, val := range pairs {
parts := strings.Split(mts, ":")
if len(parts) != 2 {
slog.Errorf("Invalid metric tag set counter: %s", mts)
continue
}
metric := parts[0]
tags, err := opentsdb.ParseTags(parts[1])
if err != nil {
slog.Errorf("Invalid tags: %s", parts[1])
continue
}
v, err := strconv.Atoi(val)
if err != nil {
slog.Errorf("Invalid counter value: %s", val)
continue
}
Add(&md, metric, v, tags, metadata.Counter, metadata.Count, "")
}
if cursor == 0 {
break
}
}
return md, nil
}
示例11: Begin
func (r *Checkpointer) Begin() error {
conn := r.pool.Get()
defer conn.Close()
res, err := conn.Do("HGETALL", r.redisPrefix+".sequence")
r.heads, err = redis.StringMap(res, err)
if err != nil {
return err
}
r.wg.Add(1)
go r.RunCheckpointer()
return nil
}
示例12: GetAll
func (this *UserOption) GetAll() []*User {
c := this.RO.Pool.Get()
defer c.Close()
length, _ := redis.Int(c.Do("LLEN", this.userListKey))
users := make([]*User, length)
userNames, _ := redis.Strings(c.Do("LRANGE", this.userListKey, 0, length-1))
for k, userName := range userNames {
userMap, _ := redis.StringMap(c.Do("HGETALL", this.nameKey(userName)))
time, _ := strconv.ParseInt(userMap["time"], 10, 64)
users[k] = NewUser(userMap["name"], userMap["nick"], userMap["password"], userMap["salt"], time)
}
return users
}
示例13: c_redis_counters
func c_redis_counters(server string, db int) (opentsdb.MultiDataPoint, error) {
var md opentsdb.MultiDataPoint
conn, err := redis.Dial("tcp", server, redis.DialDatabase(db))
if err != nil {
return md, slog.Wrap(err)
}
defer conn.Close()
//do a dance to detect proper hscan command for ledis or redis
hscanCmd := "XHSCAN"
info, err := redis.String(conn.Do("info", "server"))
if err != nil {
return md, slog.Wrap(err)
}
if strings.Contains(info, "redis_version") {
hscanCmd = "HSCAN"
}
cursor := "0"
for {
vals, err := redis.Values(conn.Do(hscanCmd, collect.RedisCountersKey, cursor))
if err != nil {
return md, slog.Wrap(err)
}
if len(vals) != 2 {
return md, fmt.Errorf("Unexpected number of values")
}
cursor, err = redis.String(vals[0], nil)
if err != nil {
return md, slog.Wrap(err)
}
pairs, err := redis.StringMap(vals[1], nil)
if err != nil {
return md, slog.Wrap(err)
}
for key, val := range pairs {
ak := models.AlertKey(key)
v, err := strconv.Atoi(val)
if err != nil {
slog.Errorf("Invalid counter value: %s", val)
continue
}
Add(&md, ak.Name(), v, ak.Group(), metadata.Counter, metadata.Count, "")
}
if cursor == "" || cursor == "0" {
break
}
}
return md, nil
}
示例14: HGETALL
// HGETALL() does the "HGETALL" command.
//
// Params:
// conn: redis.Conn.
// key: key stores the hash.
// Return:
// m: map contains the specified fields and their respective values.
// err: nil if no error occurs or specified error otherwise.
func HGETALL(conn redis.Conn, key string) (m map[string]string, err error) {
if err = CheckKey(key); err != nil {
return nil, err
}
if m, err = redis.StringMap(conn.Do("HGETALL", key)); err != nil {
if DEBUG {
fmt.Printf("HGETALL(%v) err: %v\n", key, err)
}
return nil, err
}
return m, nil
}
示例15: Get
func (this *UserOption) Get(name string) (*User, error) {
c := this.RO.Pool.Get()
defer c.Close()
key := this.nameKey(name)
if existed, _ := redis.Int(c.Do("EXISTS", key)); existed == 0 {
return nil, fmt.Errorf("不存在")
}
userMap, err := redis.StringMap(c.Do("HGETALL", key))
if err != nil {
return nil, err
}
time, _ := strconv.ParseInt(userMap["time"], 10, 64)
return NewUser(userMap["name"], userMap["nick"], userMap["password"], userMap["salt"], time), nil
}