当前位置: 首页>>代码示例>>Golang>>正文


Golang redis.DialTimeout函数代码示例

本文整理汇总了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
	}
}
开发者ID:DuoSoftware,项目名称:DVP-DashBoard,代码行数:35,代码来源:DashBoard.go

示例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
	}
}
开发者ID:DuoSoftware,项目名称:DVP-DashBoard,代码行数:25,代码来源:DashBoard.go

示例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
	}
}
开发者ID:DuoSoftware,项目名称:DVP-DashBoard,代码行数:32,代码来源:DashBoard.go

示例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
}
开发者ID:vaderyang,项目名称:gogstash,代码行数:25,代码来源:outputredis.go

示例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
}
开发者ID:samalba,项目名称:docker-cache,代码行数:32,代码来源:cache.go

示例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
	}
}
开发者ID:DuoSoftware,项目名称:DVP-CallBackService,代码行数:26,代码来源:redisHandler.go

示例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
}
开发者ID:forndb,项目名称:bytengine,代码行数:28,代码来源:redis.go

示例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
	}
}
开发者ID:DuoSoftware,项目名称:DVP-DashBoard,代码行数:34,代码来源:DashBoard.go

示例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
}
开发者ID:jfbrown,项目名称:aegis,代码行数:7,代码来源:aegis_redis.go

示例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
}
开发者ID:martin-naumann,项目名称:go-hbcid,代码行数:9,代码来源:persistence.go

示例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()
	}
}
开发者ID:jasonrsmith,项目名称:ops_scripts,代码行数:10,代码来源:redis_monitor.go

示例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
}
开发者ID:hartfordfive,项目名称:golog,代码行数:10,代码来源:golog.go

示例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
}
开发者ID:mehulsbhatt,项目名称:gollector-monitors,代码行数:11,代码来源:redis-monitor.go

示例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()
}
开发者ID:jasonrsmith,项目名称:ops_scripts,代码行数:11,代码来源:redis_db_migrate.go

示例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
}
开发者ID:nurblieh,项目名称:restos,代码行数:11,代码来源:db.go


注:本文中的github.com/fzzy/radix/redis.DialTimeout函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。