• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang redis.DialURL函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/garyburd/redigo/redis.DialURL函数的典型用法代码示例。如果您正苦于以下问题:Golang DialURL函数的具体用法?Golang DialURL怎么用?Golang DialURL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了DialURL函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: InitHub

func InitHub(url string) error {
	c, err := redis.DialURL(url)
	if err != nil {
		return err
	}
	pubconn = c

	c, err = redis.DialURL(url)
	if err != nil {
		return err
	}
	subconn = redis.PubSubConn{c}

	go func() {
		for {
			switch v := subconn.Receive().(type) {
			case redis.Message:
				EmitLocal(v.Channel, string(v.Data))

			case error:
				panic(v)
			}
		}
	}()

	return nil
}
开发者ID:hjr265,项目名称:tonesa,代码行数:27,代码来源:hub.go


示例2: redisconn

func redisconn(redisdb *redis.Conn) {
	if *redisdb == nil {
		conn, err := redis.DialURL(os.Getenv("REDIS_URL"))
		checkErr(err)
		*redisdb = conn
	}
	_, err := (*redisdb).Do("PING")
	if err != nil {
		conn, err := redis.DialURL(os.Getenv("REDIS_URL"))
		checkErr(err)
		*redisdb = conn
	}
}
开发者ID:kavehmz,项目名称:pg_notify_redis_pub,代码行数:13,代码来源:pg_notify_redis_pub.go


示例3: Connect

//Open 2 connections to redis
func Connect(url string) error {
	c, err := redis.DialURL(url)
	if err != nil {
		return err
	}
	pubconn = c

	c, err = redis.DialURL(url)
	if err != nil {
		return err
	}
	subconn = redis.PubSubConn{c}
	return nil
}
开发者ID:so0k,项目名称:ecs-sample,代码行数:15,代码来源:hub.go


示例4: TestMain

func TestMain(m *testing.M) {
	// clean test dir
	os.RemoveAll("/tmp/clusterTest")

	// initialize backend if redis-server found
	initialize()

	conn, err := redis.DialURL(config.ClusterConnection, redis.DialConnectTimeout(30*time.Second), redis.DialPassword(config.ClusterToken))
	if err != nil {
		return
	}
	hostname, _ := os.Hostname()
	self := fmt.Sprintf("%v:%v", hostname, config.ApiPort)
	defer conn.Do("SREM", "members", self)
	defer conn.Close()

	rtn := m.Run()

	// clean test dir
	os.RemoveAll("/tmp/clusterTest")
	// just in case, ensure clean members
	conn.Do("SREM", "members", self)
	conn.Close()

	os.Exit(rtn)
}
开发者ID:nanopack,项目名称:portal,代码行数:26,代码来源:redis_test.go


示例5: redisdb

func (site Site) redisdb() redis.Conn {
	redisdb, err := redis.DialURL(site.redisURL())
	if err != nil {
		panic(err)
	}
	return redisdb
}
开发者ID:kavehmz,项目名称:short,代码行数:7,代码来源:short.go


示例6: getRedisConn

func getRedisConn(redisURI string) redis.Conn {
	redisConn, err := redis.DialURL(redisURI)
	if err != nil {
		log.Panicln("Error with redis.DialURL", err.Error())
	}
	return redisConn
}
开发者ID:octoblu,项目名称:governator,代码行数:7,代码来源:main.go


示例7: updateMaster

// updateMaster gets the address of the master node from sentinel
func updateMaster() error {
	config.Log.Debug("Contacting sentinel for address of master...")

	// connect to sentinel in order to query for the master address
	r, err := redis.DialURL("redis://"+config.SentinelAddress, redis.DialConnectTimeout(config.TimeoutNotReady), redis.DialReadTimeout(config.TimeoutSentinelPoll), redis.DialPassword(config.SentinelPassword))
	if err != nil {
		return fmt.Errorf("Failed to reach sentinel - %v", err)
	}

	// retrieve the master redis address
	addr, err := redis.Strings(r.Do("SENTINEL", "get-master-addr-by-name", config.MonitorName))
	if err != nil {
		return fmt.Errorf("Failed to get-master-addr-by-name - %v", err)
	}

	// cleanup after ourselves
	r.Close()

	// construct a useable address from sentinel's response
	masterAddr = fmt.Sprintf("%v:%v", addr[0], addr[1])
	config.Log.Debug("Master address: '%v'", masterAddr)

	// wait for redis to transition to master
	if err = verifyMaster(masterAddr, config.SentinelPassword); err != nil {
		return fmt.Errorf("Could not verify master - %v", err)
	}

	return nil
}
开发者ID:nanopack,项目名称:redundis,代码行数:30,代码来源:redundis.go


示例8: ExampleDialURL

// Connect to remote instance of Redis using a URL.
func ExampleDialURL() {
	c, err := redis.DialURL(os.Getenv("REDIS_URL"))
	if err != nil {
		// handle connection error
	}
	defer c.Close()
}
开发者ID:rayyang2000,项目名称:topbeat,代码行数:8,代码来源:conn_test.go


示例9: verifyMaster

// verifyMaster verifies that the decided master node has fully transitioned
func verifyMaster(addr, pass string) error {
	// connect to redis in order to verify its state
	r, err := redis.DialURL("redis://"+addr, redis.DialConnectTimeout(config.TimeoutNotReady), redis.DialPassword(pass))
	if err != nil {
		return fmt.Errorf("Failed to reach redis at: '%v'", addr)
	}

	// give redis some time to transition
	timeout := time.After(config.TimeoutMasterWait)

	for {
		select {
		case <-timeout:
			return fmt.Errorf("Timed out waiting for redis to transition to master")
		default:
			// retrieve the redis node's role
			info, err := redis.Bytes(r.Do("INFO", "replication"))
			if err != nil {
				return fmt.Errorf("Failed to get INFO - %v", err)
			}

			// check if node is master
			if strings.Contains(string(info), "role:master") {
				return nil
			}
		}
	}

	// cleanup after ourselves
	r.Close()

	return nil
}
开发者ID:nanopack,项目名称:redundis,代码行数:34,代码来源:redundis.go


示例10: AnalysePool

/*
AnalysePool can be calls to process redis queue(s).
analyzerID will set which redis AnalysePool will connect to (redis:=pool[len(urls)%AnalysePool])

exitOnEmpty is a closure function which will control inner loop of AnalysePool when queue is empty.
	exitOnEmpty := func() bool {
		return true
	}
analyzer is a closure function which will be called for processing the tasks popped from queue.
	analyzer := func(id int, task chan string, success chan bool, next chan bool) {
		for {
			select {
			case msg := <-task:
				if id == 2 {
					time.Sleep(20 * time.Millisecond)
				}
				fmt.Println(id, msg)
				if msg == "stop" {
					<-next
					success <- true
					return
				}
			case <-time.After(2 * time.Second):
				fmt.Println("no new event for 2 seconds for ID", id)
				<-next
				success <- false
				return
			}
		}
	}
Analyser clousre must be able to accept the new Tasks without delay and if needed process them concurrently. Delay in accepting new Task will block AnalysePool.
*/
func (q *Queue) AnalysePool(analyzerID int, exitOnEmpty func() bool, analyzer func(int, chan string, chan bool, chan bool)) {
	redisdb, _ := redis.DialURL(q.urls[q.redisID(analyzerID)])

	next := make(chan bool, q.analyzerBuff())
	pool := make(map[int]chan string)
	for {
		id, task := q.removeTask(redisdb, q.queueName(analyzerID))
		if task == "" {
			if exitOnEmpty() {
				break
			} else {
				time.Sleep(100 * time.Millisecond)
			}
		} else {
			if pool[id] == nil {
				pool[id] = make(chan string)
				success := make(chan bool)
				go analyzer(id, pool[id], success, next)
				go q.waitforSuccess(id, success, pool)
				pool[id] <- task
				next <- true
			} else {
				pool[id] <- task
			}
		}
	}

	for i := 0; i < q.analyzerBuff(); i++ {
		next <- true
	}
}
开发者ID:Hunta01,项目名称:queue,代码行数:63,代码来源:queue.go


示例11: Partitions

// Partitions will define the number of redis partitions for queue. It is useful if one redis for any reason cannot handle the load of analyser.
// This function will accept a slice of redisURL to set the redis pool.
func Partitions(urls []string) {
	redisParitions = len(urls)
	redisPool = redisPool[:0]
	for _, v := range urls {
		r, _ := redis.DialURL(v)
		redisPool = append(redisPool, redisStruct{r, v})
	}
}
开发者ID:gitter-badger,项目名称:queue,代码行数:10,代码来源:queue.go


示例12: NewCacheRedis

func NewCacheRedis(address string) *CacheRedis {
	c, err := redis.DialURL(address)
	if err != nil {
		panic(err)
	}

	return &CacheRedis{conn: c}
}
开发者ID:kan,项目名称:million-timer,代码行数:8,代码来源:cache.go


示例13: NewClient

func NewClient(address string, options Options) *Client {
	pool := &redis.Pool{
		Dial: func() (redis.Conn, error) {
			return redis.DialURL(address)
		},
	}
	return NewClientWithPool(pool, options)
}
开发者ID:artnez,项目名称:go-redis,代码行数:8,代码来源:client.go


示例14: TestDialURLErrors

func TestDialURLErrors(t *testing.T) {
	for _, d := range dialErrors {
		_, err := redis.DialURL(d.rawurl)
		if err == nil || !strings.Contains(err.Error(), d.expectedError) {
			t.Errorf("DialURL did not return expected error (expected %v to contain %s)", err, d.expectedError)
		}
	}
}
开发者ID:doubledutch,项目名称:dd-vote,代码行数:8,代码来源:conn_test.go


示例15: waitforSuccess

func waitforSuccess(n int, id int, success chan bool, pool map[int]chan string) {
	redisdb, _ := redis.DialURL(redisPool[id%redisParitions].url)
	redisdb.Do("SET", "PENDING::"+strconv.Itoa(id), 1)
	r := <-success
	if r {
		delete(pool, id)
		redisdb.Do("DEL", "PENDING::"+strconv.Itoa(id))
	}
}
开发者ID:gitter-badger,项目名称:queue,代码行数:9,代码来源:queue.go


示例16: waitforSuccess

func (q *Queue) waitforSuccess(id int, success chan bool, pool map[int]chan string) {
	redisdb, _ := redis.DialURL(q.urls[q.redisID(id)])
	redisdb.Do("SET", q.pendingKeyName(id), 1)
	r := <-success
	if r {
		delete(pool, id)
		redisdb.Do("DEL", q.pendingKeyName(id))
	}
}
开发者ID:Hunta01,项目名称:queue,代码行数:9,代码来源:queue.go


示例17: NewRedisStore

// NewMemoryStore creates the new store.
func NewRedisStore(rawurl string, options ...redis.DialOption) *RedisStore {
	c, err := redis.DialURL(rawurl, options...)
	if err != nil {
		fmt.Println("NewRedisStore Error", err)
		return nil
	}
	s := RedisStore{c: c}
	return &s
}
开发者ID:0xwindows,项目名称:gryffin,代码行数:10,代码来源:redis.go


示例18: runLogger

func runLogger(redisURI, queueName string, logChannel chan []byte) {
	redisConn, err := redis.DialURL(redisURI)
	logError("redis.DialURL Failed: %v\n", err)

	for {
		logEntryBytes := <-logChannel
		_, err = redisConn.Do("lpush", queueName, logEntryBytes)
		logError("Redis LPUSH failed: %v\n", err)
	}
}
开发者ID:octoblu,项目名称:traefik,代码行数:10,代码来源:job-logger.go


示例19: Urls

// Urls will accept a slice of redis connection URLS. This slice will setup the connections and also set how many redis paritions will be used.
// Setting more than one redis is useful in some cases that a single redis can't handle a the queue load either because of IO and memory restrictions or if possible CPU.
func (q *Queue) Urls(urls []string) {
	q.urls = q.urls[:0]
	q.pool = q.pool[:0]
	for _, v := range urls {
		c, e := redis.DialURL(v)
		checkErr(e)
		q.urls = append(q.urls, v)
		q.pool = append(q.pool, c)
	}
}
开发者ID:Hunta01,项目名称:queue,代码行数:12,代码来源:queue.go


示例20: initRedisConn

func (r *redisStore) initRedisConn() {
	fmt.Println("链接redis服务器")
	c, err := redis.DialURL("redis://192.168.6.108")

	if err != nil {
		fmt.Println("redis初始化失败")
		fmt.Println(err)
	}
	r.redis = c
}
开发者ID:LibiChai,项目名称:gin-session,代码行数:10,代码来源:session-redis.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang redis.Float64函数代码示例发布时间:2022-05-23
下一篇:
Golang redis.DialTimeout函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap