本文整理匯總了Golang中github.com/fzzy/radix/redis.DialTimeout函數的典型用法代碼示例。如果您正苦於以下問題:Golang DialTimeout函數的具體用法?Golang DialTimeout怎麽用?Golang DialTimeout使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DialTimeout函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: OnGetCurrentMaxTime
func OnGetCurrentMaxTime(_tenant, _company int, _window, _parameter1, _parameter2 string, resultChannel chan int) {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in OnGetCurrentMaxTime", r)
}
}()
client, err := redis.DialTimeout("tcp", redisIp, time.Duration(10)*time.Second)
errHndlr(err)
defer client.Close()
//authServer
authE := client.Cmd("auth", redisPassword)
errHndlr(authE.Err)
// select database
r := client.Cmd("select", redisDb)
errHndlr(r.Err)
maxtimeSearch := fmt.Sprintf("SESSION:%d:%d:%s:*:%s:%s", _tenant, _company, _window, _parameter1, _parameter2)
keyList, _ := client.Cmd("keys", maxtimeSearch).List()
if len(keyList) > 0 {
tempMaxTime := 0
tm := time.Now()
for _, key := range keyList {
tmx, _ := client.Cmd("hget", key, "time").Str()
tm2, _ := time.Parse(layout, tmx)
timeDiff := int(tm.Local().Sub(tm2.Local()).Seconds())
if tempMaxTime < timeDiff {
tempMaxTime = timeDiff
}
}
resultChannel <- tempMaxTime
} else {
resultChannel <- 0
}
}
示例2: GetQueueName
func GetQueueName(queueId string) string {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in GetQueueName", r)
}
}()
client, err := redis.DialTimeout("tcp", redisIp, time.Duration(10)*time.Second)
errHndlr(err)
defer client.Close()
//authServer
authE := client.Cmd("auth", redisPassword)
errHndlr(authE.Err)
// select database
r := client.Cmd("select", ardsRedisDb)
errHndlr(r.Err)
qId := strings.Replace(queueId, "-", ":", -1)
queueName, _ := client.Cmd("hget", "QueueNameHash", qId).Str()
fmt.Println("queueName: ", queueName)
if queueName == "" {
return queueId
} else {
return queueName
}
}
示例3: OnGetMaxTime
func OnGetMaxTime(_tenant, _company int, _window, _parameter1, _parameter2 string, resultChannel chan int) {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in OnGetMaxTime", r)
}
}()
client, err := redis.DialTimeout("tcp", redisIp, time.Duration(10)*time.Second)
errHndlr(err)
defer client.Close()
//authServer
authE := client.Cmd("auth", redisPassword)
errHndlr(authE.Err)
// select database
r := client.Cmd("select", redisDb)
errHndlr(r.Err)
maxtimeSearch := fmt.Sprintf("MAXTIME:%d:%d:%s:%s:%s", _tenant, _company, _window, _parameter1, _parameter2)
keyList, _ := client.Cmd("keys", maxtimeSearch).List()
if len(keyList) > 0 {
tempMaxTime := 0
for _, key := range keyList {
value, _ := client.Cmd("get", key).Int()
if tempMaxTime < value {
tempMaxTime = value
}
}
resultChannel <- tempMaxTime
} else {
resultChannel <- 0
}
}
示例4: initRedisClient
func (self *OutputConfig) initRedisClient() (err error) {
var (
client *redis.Client
)
self.closeRedisClient()
for _, addr := range self.Host {
if client, err = redis.DialTimeout("tcp", addr, time.Duration(self.Timeout)*time.Second); err == nil {
self.clients = append(self.clients, client)
} else {
log.Warnf("Redis connection failed: %q\n%s", addr, err)
}
}
if len(self.clients) > 0 {
self.client = self.clients[0]
err = nil
} else {
self.client = nil
err = errors.New("no valid redis server connection")
}
return
}
示例5: NewCache
func NewCache(cacheUrl string, id string, ttl time.Duration) (*Cache, error) {
u, err := url.Parse(cacheUrl)
if err != nil {
return nil, err
}
redisConn, err := redis.DialTimeout("tcp", u.Host,
time.Duration(30)*time.Second)
if err != nil {
return nil, err
}
if len(u.Path) > 2 {
db, err := strconv.Atoi(u.Path[1:])
if err == nil {
return nil, fmt.Errorf("Wrong Redis db: %s", err)
}
r := redisConn.Cmd("select", db)
if r.Err != nil {
return nil, r.Err
}
}
if u.User != nil {
if pwd, ok := u.User.Password(); ok {
r := redisConn.Cmd("auth", pwd)
if r.Err != nil {
return nil, r.Err
}
}
}
cache := &Cache{redisConn, id, ttl}
cache.publishEvent("new_host", id)
return cache, nil
}
示例6: RedisAdd
// Redis String Methods
func RedisAdd(key, value string) string {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in RedisSet", r)
}
}()
client, err := redis.DialTimeout("tcp", redisIp, time.Duration(10)*time.Second)
errHndlr(err)
defer client.Close()
// select database
r := client.Cmd("select", redisDb)
errHndlr(r.Err)
isExists, _ := client.Cmd("EXISTS", key).Bool()
if isExists {
return "Key Already exists"
} else {
result, sErr := client.Cmd("set", key, value).Str()
errHndlr(sErr)
fmt.Println(result)
return result
}
}
示例7: connect
func (s *StateStore) connect() error {
client, err := redis.DialTimeout(
"tcp",
s.config.Address,
s.config.Timeout*time.Second,
)
if err != nil {
return err
}
// check if passowrd given and authenticate accordingly
if len(s.config.Password) > 0 {
r := client.Cmd("AUTH", s.config.Password)
if r.Err != nil {
return r.Err
}
}
// select the database
r := client.Cmd("SELECT", s.config.Database)
if r.Err != nil {
return r.Err
}
// set client
s.client = client
return nil
}
示例8: OnGetCurrentCount
func OnGetCurrentCount(_tenant, _company int, _window, _parameter1, _parameter2 string, resultChannel chan int) {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in OnGetCurrentCount", r)
}
}()
client, err := redis.DialTimeout("tcp", redisIp, time.Duration(10)*time.Second)
errHndlr(err)
defer client.Close()
//authServer
authE := client.Cmd("auth", redisPassword)
errHndlr(authE.Err)
// select database
r := client.Cmd("select", redisDb)
errHndlr(r.Err)
concurrentSearch := fmt.Sprintf("CONCURRENT:%d:%d:%s:%s:%s", _tenant, _company, _window, _parameter1, _parameter2)
keyList, _ := client.Cmd("keys", concurrentSearch).List()
if len(keyList) > 0 {
temptotal := 0
for _, key := range keyList {
value, _ := client.Cmd("get", key).Int()
temptotal = temptotal + value
}
if temptotal < 0 {
resultChannel <- 0
} else {
resultChannel <- temptotal
}
} else {
resultChannel <- 0
}
}
示例9: connect
func connect() *redis.Client {
c, err := redis.DialTimeout("tcp", os.Getenv("REDIS_PORT_6379_TCP_ADDR")+":"+os.Getenv("REDIS_PORT_6379_TCP_PORT"), time.Duration(10)*time.Second)
errHndlr(err)
return c
}
示例10: getClient
func getClient() (*redis.Client, error) {
c, err := redis.DialTimeout("tcp", "127.0.0.1:6379", time.Duration(10)*time.Second)
if err != nil {
return c, err
}
c.Cmd("select", 0)
return c, nil
}
示例11: worker
// ******************** Worker Pool information
func worker(id int, jobs <-chan Redisbox, results chan<- string) {
for j := range jobs {
c, err := redis.DialTimeout("tcp", fmt.Sprintf("%s:%d", j.Hostname, j.Port), time.Duration(3)*time.Second)
check(err)
c.Cmd("PING")
results <- "OK"
c.Close()
}
}
示例12: getRedisConnection
func getRedisConnection() *redis.Client {
// Finally, load the redis instance
rc, redisErr := redis.DialTimeout("tcp", state.Config["redisIp"]+":"+state.Config["redisPort"], time.Duration(2)*time.Second)
redisErrHandler(redisErr, "["+tools.DateStampAsString()+"] 1 - tcp connect")
// Select the desired DB
r := rc.Cmd("select", state.Config["redisDb"])
redisErrHandler(r.Err, "["+tools.DateStampAsString()+"] Redis op error: select "+state.Config["redisDb"])
return rc
}
示例13: makeClient
func makeClient(address string, password string, db int64) *redis.Client {
client, err := redis.DialTimeout("tcp", address, time.Duration(10)*time.Second)
errHndlr(err)
if password != "" {
r := client.Cmd("AUTH", password)
errHndlr(r.Err)
}
r := client.Cmd("SELECT", db)
errHndlr(r.Err)
return client
}
示例14: worker
func worker(id int, jobs <-chan string, results chan<- string, hostame string, port int, database int, dst_database int) {
c, err := redis.DialTimeout("tcp", fmt.Sprintf("%s:%d", hostname, port), time.Duration(3)*time.Second)
errHndlr(err)
for j := range jobs {
errHndlr(err)
k := c.Cmd("SELECT", database)
k = c.Cmd("MOVE", j, dst_database)
results <- k.String()
}
c.Close()
}
示例15: DbConnect
func DbConnect(addr *string) error {
var e error
log.Println("Connecting to DB...")
myDbClient, e = redis.DialTimeout("tcp", *addr, time.Duration(10)*time.Second)
if e == nil {
log.Println("db connection successful.")
} else {
log.Println("db connect error: ", e)
}
return e
}