本文整理汇总了Golang中github.com/lonelycode/redigocluster/rediscluster.ClusterTransaction类的典型用法代码示例。如果您正苦于以下问题:Golang ClusterTransaction类的具体用法?Golang ClusterTransaction怎么用?Golang ClusterTransaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClusterTransaction类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetAndDeleteSet
func (r *RedisClusterStorageManager) GetAndDeleteSet(keyName string) []interface{} {
log.WithFields(logrus.Fields{
"prefix": redisLogPrefix,
}).Debug("Getting raw key set: ", keyName)
if r.db == nil {
log.WithFields(logrus.Fields{
"prefix": redisLogPrefix,
}).Warning("Connection dropped, connecting..")
r.Connect()
r.GetAndDeleteSet(keyName)
} else {
log.WithFields(logrus.Fields{
"prefix": redisLogPrefix,
}).Debug("keyName is: ", keyName)
fixedKey := r.fixKey(keyName)
log.WithFields(logrus.Fields{
"prefix": redisLogPrefix,
}).Debug("Fixed keyname is: ", fixedKey)
lrange := rediscluster.ClusterTransaction{}
lrange.Cmd = "LRANGE"
lrange.Args = []interface{}{fixedKey, 0, -1}
delCmd := rediscluster.ClusterTransaction{}
delCmd.Cmd = "DEL"
delCmd.Args = []interface{}{fixedKey}
redVal, err := redis.Values(r.db.DoTransaction([]rediscluster.ClusterTransaction{lrange, delCmd}))
if err != nil {
log.WithFields(logrus.Fields{
"prefix": redisLogPrefix,
}).Error("Multi command failed: ", err)
r.Connect()
}
log.WithFields(logrus.Fields{
"prefix": redisLogPrefix,
}).Debug("Analytics returned: ", redVal)
if len(redVal) == 0 {
return []interface{}{}
}
vals := redVal[0].([]interface{})
log.WithFields(logrus.Fields{
"prefix": redisLogPrefix,
}).Debug("Unpacked vals: ", vals)
return vals
}
return []interface{}{}
}
开发者ID:TykTechnologies,项目名称:tyk-pump,代码行数:55,代码来源:redis.go
示例2: SetRollingWindow
// SetRollingWindow will append to a sorted set in redis and extract a timed window of values
func (r *RedisClusterStorageManager) SetRollingWindow(keyName string, per int64, value_override string) (int, []interface{}) {
log.Debug("Incrementing raw key: ", keyName)
if r.db == nil {
log.Info("Connection dropped, connecting..")
r.Connect()
return r.SetRollingWindow(keyName, per, value_override)
} else {
log.Debug("keyName is: ", keyName)
now := time.Now()
log.Debug("Now is:", now)
onePeriodAgo := now.Add(time.Duration(-1*per) * time.Second)
log.Debug("Then is: ", onePeriodAgo)
ZREMRANGEBYSCORE := rediscluster.ClusterTransaction{}
ZREMRANGEBYSCORE.Cmd = "ZREMRANGEBYSCORE"
ZREMRANGEBYSCORE.Args = []interface{}{keyName, "-inf", onePeriodAgo.UnixNano()}
ZRANGE := rediscluster.ClusterTransaction{}
ZRANGE.Cmd = "ZRANGE"
ZRANGE.Args = []interface{}{keyName, 0, -1}
ZADD := rediscluster.ClusterTransaction{}
ZADD.Cmd = "ZADD"
if value_override != "-1" {
ZADD.Args = []interface{}{keyName, now.UnixNano(), value_override}
} else {
ZADD.Args = []interface{}{keyName, now.UnixNano(), strconv.Itoa(int(now.UnixNano()))}
}
EXPIRE := rediscluster.ClusterTransaction{}
EXPIRE.Cmd = "EXPIRE"
EXPIRE.Args = []interface{}{keyName, per}
redVal, err := redis.Values(r.db.DoTransaction([]rediscluster.ClusterTransaction{ZREMRANGEBYSCORE, ZRANGE, ZADD, EXPIRE}))
if len(redVal) < 2 {
log.Error("Multi command failed: return index is out of range")
return 0, []interface{}{}
}
intVal := len(redVal[1].([]interface{}))
log.Debug("Returned: ", intVal)
if err != nil {
log.Error("Multi command failed: ", err)
}
return intVal, redVal[1].([]interface{})
}
return 0, []interface{}{}
}
开发者ID:coutPKprintf,项目名称:tyk,代码行数:55,代码来源:redis_cluster_handler.go
示例3: SetRollingWindowPipeline
func (r *RedisClusterStorageManager) SetRollingWindowPipeline(keyName string, per int64, value_override string) (int, []interface{}) {
log.Debug("Incrementing raw key: ", keyName)
if GetRelevantClusterReference(r.IsCache) == nil {
log.Info("Connection dropped, connecting..")
r.Connect()
return r.SetRollingWindow(keyName, per, value_override)
}
log.Debug("keyName is: ", keyName)
now := time.Now()
log.Debug("Now is:", now)
onePeriodAgo := now.Add(time.Duration(-1*per) * time.Second)
log.Debug("Then is: ", onePeriodAgo)
ZREMRANGEBYSCORE := rediscluster.ClusterTransaction{}
ZREMRANGEBYSCORE.Cmd = "ZREMRANGEBYSCORE"
ZREMRANGEBYSCORE.Args = []interface{}{keyName, "-inf", onePeriodAgo.UnixNano()}
ZRANGE := rediscluster.ClusterTransaction{}
ZRANGE.Cmd = "ZRANGE"
ZRANGE.Args = []interface{}{keyName, 0, -1}
ZADD := rediscluster.ClusterTransaction{}
ZADD.Cmd = "ZADD"
if value_override != "-1" {
ZADD.Args = []interface{}{keyName, now.UnixNano(), value_override}
} else {
ZADD.Args = []interface{}{keyName, now.UnixNano(), strconv.Itoa(int(now.UnixNano()))}
}
EXPIRE := rediscluster.ClusterTransaction{}
EXPIRE.Cmd = "EXPIRE"
EXPIRE.Args = []interface{}{keyName, per}
redVal, err := redis.Values(GetRelevantClusterReference(r.IsCache).DoPipeline([]rediscluster.ClusterTransaction{ZREMRANGEBYSCORE, ZRANGE, ZADD, EXPIRE}))
if err != nil {
log.Error("Multi command failed: ", err)
return 0, make([]interface{}, 0)
}
// Check for nil array
if redVal == nil {
return 0, make([]interface{}, 0)
}
// Check for nil length
if len(redVal) == 0 {
return 0, make([]interface{}, 0)
}
// Check actual value
if redVal[1] == nil {
return 0, make([]interface{}, 0)
}
// All clear
intVal := len(redVal[1].([]interface{}))
log.Debug("Returned: ", intVal)
return intVal, redVal[1].([]interface{})
}
开发者ID:TykTechnologies,项目名称:tyk,代码行数:63,代码来源:redis_cluster_handler.go
注:本文中的github.com/lonelycode/redigocluster/rediscluster.ClusterTransaction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论