本文整理匯總了Golang中github.com/garyburd/redigo/redis.Conn.Do方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Do方法的具體用法?Golang Conn.Do怎麽用?Golang Conn.Do使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/garyburd/redigo/redis.Conn
的用法示例。
在下文中一共展示了Conn.Do方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: clearRedis
func clearRedis(t *testing.T, c redis.Conn, key string) {
reply, err := c.Do("DEL", key)
_, err = redis.Int(reply, err)
if nil != err {
t.Logf("DEL %s failed, %v", key, err)
}
}
示例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: checkZscore
func (self *SortedSetGenerator) checkZscore(conn redis.Conn, reqnum int32, mytime *time.Timer) {
//執行req_num次,重複利用args數組中的數據,直到執行了req_num次結束
length := int32(len(self.data_list))
var i int32 = 0
for i < reqnum {
values := self.data_list[i%length]
key := values.key
for _, value := range values.sortedlist {
select {
case <-mytime.C:
return
default:
if i > reqnum {
break
}
i++
//log.Info("redis zscore ops: [%d:%d]", key, value)
reporter.Resultdata.AddSendQuantity()
_, err := conn.Do("zscore", key, value)
if err != nil {
log.Error("redis zscore failed: [%d:%d],err %v", key, value, err)
reporter.Resultdata.AddFailQuantity()
} else {
reporter.Resultdata.AddSuccQuantity()
}
}
}
}
}
示例5: createShortURL
func createShortURL(url string, conn redis.Conn) (Data, error) {
var d Data
count, err := redis.Int(conn.Do("INCR", "global:size"))
if err != nil {
log.Print(err)
return d, err
}
log.Print("Total: ", count)
encodedVar := base62.EncodeInt(int64(count))
key := strings.Join([]string{encodedVar, url}, "||")
conn.Send("MULTI")
conn.Send("HSET", key, "count", 0)
_, err2 := conn.Do("EXEC")
if err2 != nil {
log.Print(err2)
return d, err2
}
d.Original = url
d.HitCount = 0
d.Short = encodedVar
d.FullShort = strings.Join([]string{*base, encodedVar}, "")
return d, err
}
示例6: checkZadd
func (self *SortedSetGenerator) checkZadd(conn redis.Conn, reqnum int32, mytime *time.Timer) {
//執行req_num次,重複利用args數組中的數據,直到執行了req_num次結束
length := int32(len(self.data_list))
var i int32 = 0
var testquantity int32 = 10
var index int = 0
for ; i < reqnum; i++ {
select {
case <-mytime.C:
return
default:
values := self.data_list[testquantity%length]
key := values.key
data := values.sortedlist[index%len(values.sortedlist)]
//log.Info("redis zadd ops: [%d:%d:%d]", key, index, data)
reporter.Resultdata.AddSendQuantity()
_, err := redis.Int(conn.Do("zadd", key, index, data))
if err != nil {
log.Error("redis zadd failed: [%d:%d],err %v", values.key, data, err)
reporter.Resultdata.AddFailQuantity()
} else {
reporter.Resultdata.AddSuccQuantity()
//log.Error("redis set failed: %v", values)
}
testquantity++
if testquantity%length == 0 {
index++
}
}
}
}
示例7: checkZcount
func (self *SortedSetGenerator) checkZcount(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.Int(conn.Do("zcount", value.key, "-inf", "+inf"))
//log.Info("redis operating: zcount %d -inf +inf", value.key)
if err != nil {
log.Error("redis operating: zcount %d error %v", value.key, err)
reporter.Resultdata.AddFailQuantity()
} else {
if reply > 0 {
reporter.Resultdata.AddSuccQuantity()
} else {
reporter.Resultdata.AddErrorQuantity()
}
}
pos++
}
}
}
示例8: 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)
}
示例9: DrainStore
func DrainStore(r redis.Conn, id string, secret string, body string) bool {
// STABLE AS FUCK
if !strings.Contains(body, "host heroku router - at=info method=") {
return false
}
key := fmt.Sprintf("auth-%s", id)
existing, _ := redis.String(r.Do("GET", key))
if existing != secret {
return false
}
request := make(map[string]string)
request["app_id"] = id
matchVerb, _ := regexp.Compile(`method=(\w+)`)
request["verb"] = matchVerb.FindStringSubmatch(body)[1]
matchPath, _ := regexp.Compile(`path=([^ ]+)`)
request["path"] = matchPath.FindStringSubmatch(body)[1]
matchStatus, _ := regexp.Compile(`status=(\d+)`)
request["status"] = matchStatus.FindStringSubmatch(body)[1]
raw, err := json.Marshal(request)
if err != nil {
panic(err)
}
r.Do("RPUSH", "requests", raw)
return true
}
示例10: 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)
}
}
}
}
}
示例11: testOnBorrow
func (r *RedisBackend) testOnBorrow(c redis.Conn, t time.Time) error {
_, err := c.Do("PING")
if err != nil {
defer c.Close()
}
return err
}
示例12: 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)
}
}
}
}
示例13: 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)
}
}
}
}
}
示例14: 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
}
示例15: checkGet
func (self *StringGenerator) checkGet(conn redis.Conn, reqnum int32, mytime *time.Timer) {
//執行req_num次,重複利用args數組中的數據,直到執行了req_num次結束
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]
reporter.Resultdata.AddSendQuantity()
//reply, err := redis.String(conn.Do("get", values.key))
_, err := conn.Do("get", values.key)
//log.Info("redis operating: get %s", values.key)
if err != nil {
//log.Error("redis %s failed: %v, %v", cmd, values, err)
reporter.Resultdata.AddFailQuantity()
} else {
/*if values.value == reply {
reporter.Resultdata.AddSuccQuantity()
} else {
reporter.Resultdata.AddErrorQuantity()
//log.Error("redis set failed: %v", values)
}*/
reporter.Resultdata.AddSuccQuantity()
}
}
}
}