本文整理匯總了Golang中github.com/garyburd/redigo/redis.Conn.Send方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Send方法的具體用法?Golang Conn.Send怎麽用?Golang Conn.Send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/garyburd/redigo/redis.Conn
的用法示例。
在下文中一共展示了Conn.Send方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TickTock
// Decrements all jobs' score by one
func (q *delayedQueue) TickTock(conn redis.Conn) error {
// if ticktock is running, don't run another one
if q.isTicking {
return nil
}
q.isTicking = true
// there are multiple returns, but whichever return
// gets hit, make sure isTicking is switched off
defer func() {
q.isTicking = false
}()
// get all job ids
//
// NOTE: loading all ids into memory might be an overhead
// if the set is big, ZSCAN might be able to help on this
idToScore := GetQueueScores(q.GetIndexName(), conn)
// decrement each job's score
conn.Send("MULTI")
for id, score := range idToScore {
// only decrement scores > zero so we
// don't ran into negative scores
if score > 0 {
conn.Send("ZINCRBY", q.GetIndexName(), -1, id)
}
}
if _, err := conn.Do("EXEC"); err != nil {
return err
}
return nil
}
示例2: startSession
// check - lock - check
func (provider *RedisProvider) startSession(sid string, conn redis.Conn, option *Options) (Sessioner, bool, error) {
// 檢查隨機生成的session是否被占用了
if exist, err := redis.Bool(conn.Do("EXISTS", getRedisKey(sid))); exist || err != nil {
return nil, false, err
}
// 觀察sid
conn.Send("WATCH", getRedisKey(sid))
conn.Send("MULTI")
conn.Send("HSET", getRedisKey(sid), "createtime", time.Now().Unix())
if option.Cookielifttime > 0 {
conn.Send("EXPIRE", getRedisKey(sid), option.Cookielifttime)
} else {
conn.Send("EXPIRE", getRedisKey(sid), 30*24*60*60)
}
replay, err := conn.Do("EXEC")
if err != nil {
return nil, false, err
}
if replay == nil {
return nil, false, nil
}
sessioner, err := provider.GetSessioner(sid)
return sessioner, true, err
}
示例3: 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
}
示例4: checkRateLimit
// Checking rate limit 10 request / 1 sec.
func checkRateLimit(con redis.Conn, c *echo.Context) bool {
ip, _, err := net.SplitHostPort(c.Request().RemoteAddr)
if err != nil {
panic(err)
}
//If list of ip address's length is 10 retun false.
current, err := redis.Int(con.Do("LLEN", ip))
if err == nil && current > 10 {
return false
}
exists, err := redis.Bool(con.Do("EXISTS", ip))
if err != nil {
panic(err)
}
if !exists {
con.Send("MULTI")
con.Send("RPUSH", ip, ip)
con.Send("EXPIRE", ip, 1)
_, err := con.Do("EXEC")
if err != nil {
panic(err)
}
} else {
_, err := con.Do("RPUSHX", ip, ip)
if err != nil {
panic(err)
}
}
return true
}
示例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: writeBatch
func writeBatch(list string, conn redis.Conn, values []string) {
conn.Send("MULTI")
for _, value := range values {
value = strings.TrimSpace(value)
if value != "" {
conn.Send("LPUSH", list, value)
}
}
_, err := redis.Values(conn.Do("EXEC"))
if err != nil {
log.Fatalf("Could not LPUSH: %s \"%s\"\n", list, err.Error())
}
}
示例8: recordHitAtGranularity
func recordHitAtGranularity( granularity Granularity, time float64, key string, c redis.Conn ) bool{
size := granularity.size
factor := granularity.factor
ttl := granularity.ttl
name := granularity.name
tsround := getRoundedTimestamp(time, size * factor)
s := []string{"stats",key,name,strconv.FormatFloat(tsround, 'f', 0, 64)}
redis_key := strings.Join(s,":")
ts := strconv.FormatFloat(getFactoredTimestamp (time, factor), 'f', 0, 64)
ttl_str := strconv.FormatFloat(tsround+ttl, 'f', 0, 64)
c.Send("HINCRBY", redis_key, ts, 1)
c.Send("EXPIREAT", redis_key, ttl_str)
return true;
}
示例9: 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
}
}
示例10: 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
}
示例11: 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)
}
}
}
示例12: 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
}
示例13: start
func (w *worker) start(conn redis.Conn, job *job) error {
work := &work{
Queue: job.Queue,
RunAt: time.Now(),
Payload: job.Payload,
}
buffer, err := json.Marshal(work)
if err != nil {
return err
}
conn.Send("SET", fmt.Sprintf("%sworker:%s", namespace, w), buffer)
logger.Debugf("Processing %s since %s [%v]", work.Queue, work.RunAt, work.Payload.Class)
return w.process.start(conn)
}
示例14: fail
func (w *worker) fail(conn redis.Conn, job *job, err error) error {
failure := &failure{
FailedAt: time.Now(),
Payload: job.Payload,
Exception: "Error",
Error: err.Error(),
Worker: w,
Queue: job.Queue,
}
buffer, err := json.Marshal(failure)
if err != nil {
return err
}
conn.Send("RPUSH", fmt.Sprintf("%sfailed", namespace), buffer)
return w.process.fail(conn)
}
示例15: 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
}