本文整理匯總了Golang中github.com/garyburd/redigo/redis.Conn類的典型用法代碼示例。如果您正苦於以下問題:Golang Conn類的具體用法?Golang Conn怎麽用?Golang Conn使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Conn類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: pipelineInsert
func pipelineInsert(conn redis.Conn, keyScoreMembers []common.KeyScoreMember, maxSize int) error {
for _, tuple := range keyScoreMembers {
if err := insertScript.Send(
conn,
tuple.Key,
tuple.Score,
tuple.Member,
maxSize,
); err != nil {
return err
}
}
if err := conn.Flush(); err != nil {
return err
}
for _ = range keyScoreMembers {
// TODO actually count inserts
if _, err := conn.Receive(); err != nil {
return err
}
}
return nil
}
示例2: QueueDocsetJob
// QueueDocsetJob will queue a job to build a docset for an artifact, if there
// is not yet one built.
func QueueDocsetJob(groupId, artifactId string, version string) error {
var redisConn redis.Conn = redisconn.Get()
id := groupId + ":" + artifactId
exists, err := redis.Bool(redisConn.Do("SISMEMBER", "docsets", id))
if err != nil {
return err
}
if exists == true && version != "" {
verExists, err := redis.Bool(redisConn.Do("SISMEMBER", "docset:"+id, version))
if err != nil || verExists {
return err
}
} else if exists == true {
return nil
}
if err := QueueJob(map[string]string{
"Job": "build-docset",
"ArtifactId": artifactId,
"GroupId": groupId,
"Version": version,
}); err != nil {
return err
}
return nil
}
示例3: PingRedis
func PingRedis(c redis.Conn, t time.Time) error {
_, err := c.Do("ping")
if err != nil {
log.Println("[ERROR] ping redis fail", err)
}
return err
}
示例4: 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)
}
}
}
}
示例5: checkZscoreOk
func (self *SortedSetGenerator) checkZscoreOk(conn redis.Conn, reqnum int32, mytime *time.Timer) {
length := int32(len(self.data_list))
var i int32 = 0
var index int32 = -1
for ; i < reqnum; i++ {
if i%length == 0 {
index++
}
values := self.data_list[i%length]
key := values.key
data := values.sortedlist[index]
//log.Info("redis zscore ops: [%d:%d]", key, data)
reporter.Resultdata.AddSendQuantity()
_, err := redis.Int(conn.Do("zscore", key, data))
if err != nil {
log.Error("redis zscore failed: [%d:%d],err %v", key, data, err)
reporter.Resultdata.AddFailQuantity()
} else {
reporter.Resultdata.AddSuccQuantity()
}
if i%length == 0 {
index++
}
}
}
示例6: runDel
func (self *StringGenerator) runDel(conn redis.Conn, req_num int32, mytime *time.Timer) {
var pos int32 = 0
for _, values := range self.data_list {
if pos >= req_num {
break
}
reporter.Resultdata.AddSendQuantity()
reply, err := redis.Int(conn.Do("del", values.key))
//log.Info("redis operating: del %s", values.key)
if err != nil {
//log.Error("redis %s failed: %v, %v", cmd, values, err)
reporter.Resultdata.AddFailQuantity()
} else {
if reply > 0 {
reporter.Resultdata.AddSuccQuantity()
} else {
reporter.Resultdata.AddErrorQuantity()
}
}
pos++
}
/*
if pos >= req_num {
log.Info(" %d > %d, end del", pos, req_num)
} else {
log.Info("del all data in data_list")
}*/
}
示例7: checkZrevrange
func (self *SortedSetGenerator) checkZrevrange(conn redis.Conn, req_num int32, mytime *time.Timer) {
var pos int32 = 0
for _, value := range self.data_list {
select {
case <-mytime.C:
return
default:
if pos >= req_num {
break
}
reporter.Resultdata.AddSendQuantity()
reply, err := redis.Values(conn.Do("zrevrange", value.key, 0, ZRANGE_100))
//log.Info("redis operating: zrevrange %d 0 %d", value.key, ZRANGE_100)
if err != nil {
log.Info("redis operating: zrevrange %d 0 %d error %v", value.key, ZRANGE_100, err)
reporter.Resultdata.AddFailQuantity()
} else {
if len(reply) > 0 {
reporter.Resultdata.AddSuccQuantity()
} else {
reporter.Resultdata.AddErrorQuantity()
}
}
pos++
}
}
}
示例8: testOnBorrow
func (r *RedisBackend) testOnBorrow(c redis.Conn, t time.Time) error {
_, err := c.Do("PING")
if err != nil {
defer c.Close()
}
return err
}
示例9: 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)
}
示例10: hkeys
func (self *HashGenerator) hkeys(conn redis.Conn, reqnum int32, mytime *time.Timer) {
length := int32(len(self.data_list))
var i int32 = 0
for ; i < reqnum; i++ {
select {
case <-mytime.C:
return
default:
values := self.data_list[i%length]
key := values.key
length := len(values.names)
name_slice := make([]string, length)
for pos, data := range values.names {
name_slice[pos] = data.name
}
reporter.Resultdata.AddSendQuantity()
reply, err := redis.Strings(conn.Do("hkeys", key))
if err != nil {
log.Error("redis lpush failed: [%s],err %v", key, err)
reporter.Resultdata.AddFailQuantity()
} else {
//reporter.Resultdata.AddSuccQuantity()
datacheck := &reporter.StringArrayChecker{name_slice, reply}
reporter.Datasummer.AddChecker(datacheck)
}
}
}
}
示例11: hdel
func (self *HashGenerator) hdel(conn redis.Conn, reqnum int32, mytime *time.Timer) {
length := int32(len(self.data_list))
var i, j int32 = 0, 0
for ; j < reqnum; i++ {
values := self.data_list[i%length]
for _, data := range values.names {
if j > reqnum {
break
}
j++
select {
case <-mytime.C:
return
default:
reporter.Resultdata.AddSendQuantity()
_, err := redis.Int(conn.Do("hdel", values.key, data.name))
if err != nil {
log.Error("redis hdel failed: [%s:%s],err %v", values.key, data.name, err)
reporter.Resultdata.AddFailQuantity()
} else {
reporter.Resultdata.AddSuccQuantity()
//datacheck := &reporter.ObjChecker{1, reply}
//reporter.Datasummer.AddChecker(datacheck)
}
}
}
}
}
示例12: hset
// key name value
func (self *HashGenerator) hset(conn redis.Conn, reqnum int32, mytime *time.Timer) {
length := int32(len(self.data_list))
var i int32 = 0
for ; i < reqnum; i++ {
values := self.data_list[i%length]
key := values.key
for _, data := range values.names {
select {
case <-mytime.C:
return
default:
reporter.Resultdata.AddSendQuantity()
_, err := redis.Int(conn.Do("hset", key, data.name, data.value))
if err != nil {
log.Error("redis lpush failed: [%s:%s:%d],err %v", key, data.name, data.value, err)
reporter.Resultdata.AddFailQuantity()
} else {
reporter.Resultdata.AddSuccQuantity()
//log.Error("redis lpush failed: %v", values)
}
}
}
}
}
示例13: findGame
// findGame finds a game in the list of open games. If one doesn't exist, creates a new gameid
// returns a new Game and if it's a new game or not.
func findGame(ctx context.Context, con redis.Conn) (*Game, bool, error) {
lc := "FindGame"
// do we have an open game?
gameID, err := redis.String(con.Do("RPOP", openGames))
// ignore nil errors, since that is expected
if err != nil && err != redis.ErrNil {
logger.Error(ctx, lc, "Error finding open game: %v", err)
return new(Game), false, err
}
// is this a brand new game?
isNew := (gameID == "")
if isNew {
logger.Info(ctx, lc, "Could not find open game, creating one... ")
u, err := uuid.NewV4()
if err != nil {
return nil, false, err
}
gameID = u.String()
}
return NewGame(gameID), isNew, nil
}
示例14: pipelineDelete
func pipelineDelete(conn redis.Conn, keyScoreMembers []common.KeyScoreMember, maxSize int) error {
for _, keyScoreMember := range keyScoreMembers {
if err := deleteScript.Send(
conn,
keyScoreMember.Key,
keyScoreMember.Score,
keyScoreMember.Member,
maxSize,
); err != nil {
return err
}
}
if err := conn.Flush(); err != nil {
return err
}
for _ = range keyScoreMembers {
// TODO actually count deletes
if _, err := conn.Receive(); err != nil {
return err
}
}
return nil
}
示例15: UpdateLocalTopologyMap
func (out *RedisOutput) UpdateLocalTopologyMap(conn redis.Conn) {
TopologyMapTmp := make(map[string]string)
hostnames, err := redis.Strings(conn.Do("KEYS", "*"))
if err != nil {
logp.Err("Fail to get the all shippers from the topology map %s", err)
return
}
for _, hostname := range hostnames {
res, err := redis.String(conn.Do("HGET", hostname, "ipaddrs"))
if err != nil {
logp.Err("[%s] Fail to get the IPs: %s", hostname, err)
} else {
ipaddrs := strings.Split(res, ",")
for _, addr := range ipaddrs {
TopologyMapTmp[addr] = hostname
}
}
}
out.TopologyMap = TopologyMapTmp
logp.Debug("output_redis", "Topology %s", TopologyMapTmp)
}