本文整理匯總了Golang中github.com/garyburd/redigo/redis.Conn.Flush方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Flush方法的具體用法?Golang Conn.Flush怎麽用?Golang Conn.Flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/garyburd/redigo/redis.Conn
的用法示例。
在下文中一共展示了Conn.Flush方法的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: close
func (p *process) close(conn redis.Conn) error {
logger.Infof("%v shutdown", p)
conn.Send("SREM", fmt.Sprintf("%sworkers", namespace), p)
conn.Send("DEL", fmt.Sprintf("%sstat:processed:%s", namespace, p))
conn.Send("DEL", fmt.Sprintf("%sstat:failed:%s", namespace, p))
return conn.Flush()
}
示例3: 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
}
示例4: execute
func (self *redis_gateway) execute(c redis.Conn, commands [][]string) error {
switch len(commands) {
case 0:
return nil
case 1:
e := self.redis_do(c, commands[0])
if nil != e {
return errors.New("execute `" + strings.Join(commands[0], " ") + "` failed, " + e.Error())
}
return nil
default:
for _, command := range commands {
e := self.redis_send(c, command)
if nil != e {
return errors.New("execute `" + strings.Join(command, " ") + "` failed, " + e.Error())
}
}
e := c.Flush()
if nil != e {
return e
}
for i := 0; i < len(commands); i++ {
_, e = c.Receive()
if nil != e {
return errors.New("execute `" + strings.Join(commands[i], " ") + "` failed, " + e.Error())
}
}
return nil
}
}
示例5: Get
func Get(conn redis.Conn) string {
conn.Send("GET", "fooo")
conn.Flush()
result, _ := redis.String(conn.Receive()) // TODO missing two err catch
return result
}
示例6: Save
func Save(obj interface{}, conn redis.Conn) reflect.Type {
conn.Send("GET", "fooo")
conn.Flush()
//result, _ := redis.String(conn.Receive()) // TODO missing two err catch
return reflect.ValueOf(&obj).Type()
}
示例7: publishEventsPipeline
func publishEventsPipeline(conn redis.Conn, command string) publishFn {
return func(key outil.Selector, data []outputs.Data) ([]outputs.Data, error) {
var okEvents []outputs.Data
serialized := make([]interface{}, 0, len(data))
okEvents, serialized = serializeEvents(serialized, 0, data)
if len(serialized) == 0 {
return nil, nil
}
data = okEvents[:0]
for i, serializedEvent := range serialized {
eventKey, err := key.Select(okEvents[i].Event)
if err != nil {
logp.Err("Failed to set redis key: %v", err)
continue
}
data = append(data, okEvents[i])
if err := conn.Send(command, eventKey, serializedEvent); err != nil {
logp.Err("Failed to execute %v: %v", command, err)
return okEvents, err
}
}
if err := conn.Flush(); err != nil {
return data, err
}
failed := data[:0]
var lastErr error
for i := range serialized {
_, err := conn.Receive()
if err != nil {
if _, ok := err.(redis.Error); ok {
logp.Err("Failed to %v event to list with %v",
command, err)
failed = append(failed, data[i])
lastErr = err
} else {
logp.Err("Failed to %v multiple events to list with %v",
command, err)
failed = append(failed, data[i:]...)
lastErr = err
break
}
}
}
return failed, lastErr
}
}
示例8: parseBGPCSV
func (b *BGPDump) parseBGPCSV(r io.Reader, conn redis.Conn) (int, error) {
day := b.day()
s := bufio.NewScanner(r)
n := 0
var asn string
for s.Scan() {
cols := strings.Split(s.Text(), "|")
if len(cols) < 7 {
return n, ParseError{
Message: "too few columns",
Path: filepath.Base(b.Path()),
LineNum: n,
Line: s.Text(),
}
}
block := cols[5]
if _, ok := asn12654blocks[block]; ok {
asn = "12654"
} else {
asPath := cols[6]
asns := strings.Split(asPath, " ")
asn = asns[len(asns)-1]
if asn == "" {
return n, ParseError{
Message: "no ASPATH data",
Path: filepath.Base(b.Path()),
LineNum: n,
Line: s.Text(),
}
}
}
conn.Send("HSET", fmt.Sprintf("i2a:%s", block), day, asn)
n++
if n%10000 == 0 {
err := conn.Flush()
if err != nil {
return 0, err
}
}
}
conn.Send("SADD", "i2a:imported_dates", day)
err := conn.Flush()
if err != nil {
return 0, err
}
return n, nil
}
示例9: read
func read(list string, conn redis.Conn, count int) {
for i := 0; i < count; i++ {
conn.Send("LPOP", list)
}
conn.Flush()
for i := 0; i < count; i++ {
value, err := redis.String(conn.Receive())
if err != nil {
os.Exit(0)
}
if value != "" {
fmt.Println(value)
}
}
}
示例10: pipelineScore
func pipelineScore(conn redis.Conn, keyMembers []common.KeyMember) (map[common.KeyMember]Presence, error) {
for _, keyMember := range keyMembers {
if err := conn.Send("ZSCORE", keyMember.Key+insertSuffix, keyMember.Member); err != nil {
return map[common.KeyMember]Presence{}, err
}
if err := conn.Send("ZSCORE", keyMember.Key+deleteSuffix, keyMember.Member); err != nil {
return map[common.KeyMember]Presence{}, err
}
}
if err := conn.Flush(); err != nil {
return map[common.KeyMember]Presence{}, err
}
m := map[common.KeyMember]Presence{}
for i := 0; i < len(keyMembers); i++ {
insertReply, insertErr := conn.Receive()
insertValue, insertErr := redis.Float64(insertReply, insertErr)
deleteReply, deleteErr := conn.Receive()
deleteValue, deleteErr := redis.Float64(deleteReply, deleteErr)
switch {
case insertErr == nil && deleteErr == redis.ErrNil:
m[keyMembers[i]] = Presence{
Present: true,
Inserted: true,
Score: insertValue,
}
case insertErr == redis.ErrNil && deleteErr == nil:
m[keyMembers[i]] = Presence{
Present: true,
Inserted: false,
Score: deleteValue,
}
case insertErr == redis.ErrNil && deleteErr == redis.ErrNil:
m[keyMembers[i]] = Presence{
Present: false,
}
default:
return map[common.KeyMember]Presence{}, fmt.Errorf(
"pipelineScore bad state for %v (%v/%v)",
keyMembers[i],
insertErr,
deleteErr,
)
}
}
return m, nil
}
示例11: pipelineRange
func pipelineRange(conn redis.Conn, keys []string, offset, limit int) (map[string][]common.KeyScoreMember, error) {
if limit < 0 {
return map[string][]common.KeyScoreMember{}, fmt.Errorf("negative limit is invalid for offset-based select")
}
for _, key := range keys {
if err := conn.Send(
"ZREVRANGE",
key+insertSuffix,
offset,
offset+limit-1,
"WITHSCORES",
); err != nil {
return map[string][]common.KeyScoreMember{}, err
}
}
if err := conn.Flush(); err != nil {
return map[string][]common.KeyScoreMember{}, err
}
m := make(map[string][]common.KeyScoreMember, len(keys))
for _, key := range keys {
values, err := redis.Values(conn.Receive())
if err != nil {
return map[string][]common.KeyScoreMember{}, err
}
var (
ksm = common.KeyScoreMember{Key: key}
keyScoreMembers = make([]common.KeyScoreMember, 0, len(values))
)
for len(values) > 0 {
if values, err = redis.Scan(values, &ksm.Member, &ksm.Score); err != nil {
return map[string][]common.KeyScoreMember{}, err
}
keyScoreMembers = append(keyScoreMembers, ksm)
}
m[key] = keyScoreMembers
}
return m, nil
}
示例12: publishEventsPipeline
func publishEventsPipeline(conn redis.Conn, command string) publishFn {
return func(dest []byte, events []common.MapStr) ([]common.MapStr, error) {
var args [2]interface{}
args[0] = dest
serialized := make([]interface{}, 0, len(events))
events, serialized = serializeEvents(serialized, 0, events)
if len(serialized) == 0 {
return nil, nil
}
for _, event := range serialized {
args[1] = event
if err := conn.Send(command, args[:]...); err != nil {
logp.Err("Failed to execute %v: %v", command, err)
return events, err
}
}
if err := conn.Flush(); err != nil {
return events, err
}
failed := events[:0]
var lastErr error
for i := range serialized {
_, err := conn.Receive()
if err != nil {
if _, ok := err.(redis.Error); ok {
logp.Err("Failed to %v event to list (%v) with %v",
command, dest, err)
failed = append(failed, events[i])
lastErr = err
} else {
logp.Err("Failed to %v multiple events to list (%v) with %v",
command, dest, err)
failed = append(failed, events[i:]...)
lastErr = err
break
}
}
}
return failed, lastErr
}
}
示例13: GetRepo
func GetRepo(c redis.Conn, repo string) (string, bool, error) {
c.Send("GET", repo)
c.Send("TTL", repo)
if err := c.Flush(); err != nil {
return "", false, nil
}
content, err := redis.String(c.Receive())
if err == redis.ErrNil {
return "", false, nil
}
if err != nil {
return "", false, err
}
if ttl, err := redis.Int(c.Receive()); err == nil && ttl > FRESH_CACHE_LIMIT {
return content, true, nil
}
return content, false, err
}
示例14: newSession
func newSession(w http.ResponseWriter, userid uint64, username string, appid uint32, rc redis.Conn) (usertoken string, err error) {
if rc == nil {
rc = redisPool.Get()
defer rc.Close()
}
usertoken = ""
usertokenRaw, err := rc.Do("get", fmt.Sprintf("usertokens/%d+%d", userid, appid))
lwutil.CheckError(err, "")
if usertokenRaw != nil {
if usertoken, err := redis.String(usertokenRaw, err); err != nil {
return usertoken, lwutil.NewErr(err)
}
rc.Do("del", fmt.Sprintf("sessions/%s", usertoken))
}
usertoken = lwutil.GenUUID()
session := Session{userid, username, time.Now(), appid}
jsonSession, err := json.Marshal(session)
if err != nil {
return usertoken, lwutil.NewErr(err)
}
rc.Send("setex", fmt.Sprintf("sessions/%s", usertoken), sessionLifeSecond, jsonSession)
rc.Send("setex", fmt.Sprintf("usertokens/%d+%d", userid, appid), sessionLifeSecond, usertoken)
rc.Flush()
for i := 0; i < 2; i++ {
if _, err = rc.Receive(); err != nil {
return usertoken, lwutil.NewErr(err)
}
}
// cookie
http.SetCookie(w, &http.Cookie{Name: "usertoken", Value: usertoken, MaxAge: sessionLifeSecond, Path: "/"})
return usertoken, err
}
示例15: pipelineRevRange
func pipelineRevRange(conn redis.Conn, keys []string, offset, limit int) (map[string][]common.KeyScoreMember, error) {
for _, key := range keys {
if err := conn.Send(
"ZREVRANGE",
key+insertSuffix,
offset,
offset+limit-1,
"WITHSCORES",
); err != nil {
return map[string][]common.KeyScoreMember{}, err
}
}
if err := conn.Flush(); err != nil {
return map[string][]common.KeyScoreMember{}, err
}
m := make(map[string][]common.KeyScoreMember, len(keys))
for _, key := range keys {
values, err := redis.Values(conn.Receive())
if err != nil {
return map[string][]common.KeyScoreMember{}, err
}
keyScoreMembers := make([]common.KeyScoreMember, 0, len(values))
for len(values) > 0 {
var member string
var score float64
if values, err = redis.Scan(values, &member, &score); err != nil {
return map[string][]common.KeyScoreMember{}, err
}
keyScoreMembers = append(keyScoreMembers, common.KeyScoreMember{Key: key, Score: score, Member: member})
}
m[key] = keyScoreMembers
}
return m, nil
}