當前位置: 首頁>>代碼示例>>Golang>>正文


Golang redis.NewPool函數代碼示例

本文整理匯總了Golang中github.com/garyburd/redigo/redis.NewPool函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewPool函數的具體用法?Golang NewPool怎麽用?Golang NewPool使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewPool函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestAddRouteCommandFailure

func (s *S) TestAddRouteCommandFailure(c *check.C) {
	r := hipacheRouter{prefix: "hipache", pool: redis.NewPool(fakeConnect, 5)}
	addr, _ := url.Parse("http://www.tsuru.io")
	err := r.AddBackend("tip")
	c.Assert(err, check.IsNil)
	conn = &FailingFakeRedisConn{}
	r2 := hipacheRouter{prefix: "hipache", pool: redis.NewPool(fakeConnect, 5)}
	err = r2.AddRoute("tip", addr)
	c.Assert(err, check.FitsTypeOf, &router.RouterError{})
	e, ok := err.(*router.RouterError)
	c.Assert(ok, check.Equals, true)
	c.Assert(e.Err.Error(), check.Equals, "I can't do that.")
	c.Assert(e.Op, check.Equals, "routes")
}
開發者ID:zhenruyan,項目名稱:tsuru,代碼行數:14,代碼來源:router_test.go

示例2: NewStorage

func NewStorage(server string) *Storage {
	pool := redis.NewPool(func() (conn redis.Conn, err error) {
		conn, err = redis.Dial("tcp", server)
		return
	}, 3)
	return &Storage{pool}
}
開發者ID:kalagxw,項目名稱:shadowsocks-auth,代碼行數:7,代碼來源:storage.go

示例3: NewConnectionPoolHost

// Create a new connection pool given a host:port string.
// A password may be supplied as well, on the form "[email protected]:port".
func NewConnectionPoolHost(hostColonPort string) *ConnectionPool {
	// Create a redis Pool
	redisPool := redis.NewPool(
		// Anonymous function for calling new RedisConnectionTo with the host:port
		func() (redis.Conn, error) {
			conn, err := newRedisConnectionTo(hostColonPort)
			if err != nil {
				return nil, err
			}
			// If a password is given, use it to authenticate
			if password, _, ok := twoFields(hostColonPort, "@"); ok {
				if password != "" {
					if _, err := conn.Do("AUTH", password); err != nil {
						conn.Close()
						return nil, err
					}
				}
			}
			return conn, err
		},
		// Maximum number of idle connections to the redis database
		maxIdleConnections)
	pool := ConnectionPool(*redisPool)
	return &pool
}
開發者ID:trietphm,項目名稱:simpleredis,代碼行數:27,代碼來源:simpleredis.go

示例4: main

func main() {
	// 4 reqs/hour
	rate, err := limiter.NewRateFromFormatted("4-H")
	if err != nil {
		panic(err)
	}

	// Create a Redis pool.
	pool := redis.NewPool(func() (redis.Conn, error) {
		c, err := redis.Dial("tcp", ":6379")
		if err != nil {
			return nil, err
		}
		return c, err
	}, 100)

	// Create a store with the pool.
	store, err := limiter.NewRedisStore(pool, "limitergjrexample")
	if err != nil {
		panic(err)
	}

	mw := limiter.NewHTTPMiddleware(limiter.NewLimiter(store, rate))
	http.Handle("/", mw.Handler(http.HandlerFunc(index)))

	fmt.Println("Server is running on port 7777...")
	log.Fatal(http.ListenAndServe(":7777", nil))

}
開發者ID:cinderalla,項目名稱:limiter,代碼行數:29,代碼來源:main.go

示例5: init

func init() {
	max := maxConnection()
	url := address()
	redisPool = redis.NewPool(func() (redis.Conn, error) {
		return redisurl.ConnectToURL(url)
	}, max)
}
開發者ID:Leko,項目名稱:godemo,代碼行數:7,代碼來源:redis.go

示例6: main

func main() {
	pool := redis.NewPool(func() (redis.Conn, error) {
		return redis.Dial("tcp", ":6379")
	}, 10)
	app := redisocket.NewApp(pool)

	err := make(chan error)
	go func() {
		err <- app.Listen()
	}()

	http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {

		sub, err := app.NewClient(w, r)
		if err != nil {
			log.Fatal("Client Connect Error")
			return
		}
		c := &User{app, sub}
		err = c.Listen()
		log.Println(err, "http point")
		return
	})

	go func() {
		err <- http.ListenAndServe(":8888", nil)
	}()
	select {
	case e := <-err:
		log.Println(e)
	}
}
開發者ID:syhlion,項目名稱:redisocket,代碼行數:32,代碼來源:main.go

示例7: SessionInit

func (this *RedisProvider) SessionInit(path string, gctime int) error {
	this.maxlifetime = gctime
	pathArr := strings.Split(path, ",")
	if len(pathArr) > 0 {
		this.path = pathArr[0]
	}
	if len(pathArr) > 1 {
		ps, err := strconv.Atoi(pathArr[1])
		if err != nil || ps <= 0 {
			this.poolsize = 200
		} else {
			this.poolsize = ps
		}
	} else {
		this.poolsize = 200
	}
	this.pools = redis.NewPool(func() (redis.Conn, error) {
		c, err := redis.Dial("tcp", this.path)
		if err != nil {
			return nil, err
		}
		_, err = c.Do("SELECT", 0)
		if err != nil {
			c.Close()
			return nil, err
		}
		return c, nil
	}, this.poolsize)
	return this.pools.Get().Err()
}
開發者ID:jesusslim,項目名稱:slimgo,代碼行數:30,代碼來源:session_redis.go

示例8: SessionInit

//savepath like redisserveraddr,poolsize,password
//127.0.0.1:6379,100,astaxie
func (rp *RedisProvider) SessionInit(maxlifetime int64, savePath string) error {
	rp.maxlifetime = maxlifetime
	configs := strings.Split(savePath, ",")
	if len(configs) > 0 {
		rp.savePath = configs[0]
	}
	if len(configs) > 1 {
		poolsize, err := strconv.Atoi(configs[1])
		if err != nil || poolsize <= 0 {
			rp.poolsize = MAX_POOL_SIZE
		} else {
			rp.poolsize = poolsize
		}
	} else {
		rp.poolsize = MAX_POOL_SIZE
	}
	if len(configs) > 2 {
		rp.password = configs[2]
	}
	rp.poollist = redis.NewPool(func() (redis.Conn, error) {
		c, err := redis.Dial("tcp", rp.savePath)
		if err != nil {
			return nil, err
		}
		if rp.password != "" {
			if _, err := c.Do("AUTH", rp.password); err != nil {
				c.Close()
				return nil, err
			}
		}
		return c, err
	}, rp.poolsize)
	return nil
}
開發者ID:rose312,項目名稱:beego,代碼行數:36,代碼來源:sess_redis.go

示例9: NewMessageServer

func NewMessageServer(redisAddr string, fast bool) (http.Handler, error) {
	hostname, err := os.Hostname()
	if err != nil {
		return nil, err
	}
	m := &MessageServer{
		r:    mux.NewRouter(),
		name: strings.Replace(hostname, "linuxcon-demo-", "", -1),
		pool: redis.NewPool(func() (redis.Conn, error) {
			return redis.Dial("tcp", redisAddr)
		}, 10),
	}
	m.r.HandleFunc("/", m.getMessage).Methods("GET")
	m.r.HandleFunc("/cache", m.getCache).Methods("GET")
	// start filling the cache async on boot
	go m.fillCache(redisAddr, fast)
	go func() {
		for range time.Tick(3 * time.Second) {
			if _, err := m.do("SET", fmt.Sprintf("nodes.%s.avg", m.name), requests.Rate1()); err != nil {
				logrus.Error(err)
			}
		}
	}()
	return m, nil
}
開發者ID:atxwebs,項目名稱:dolly,代碼行數:25,代碼來源:server.go

示例10: getPool

// getPool returns a redis connection pool for a given address
func (p *Pool) getPool(addr string) *redis.Pool {

	defer scopedLock(&p.mutx)()

	pool, found := p.pools[addr]
	if !found {
		pool = redis.NewPool(func() (redis.Conn, error) {
			return p.dialFunc(addr)
		}, maxIdle)

		pool.TestOnBorrow = func(c redis.Conn, t time.Time) error {

			// for testing - count how many borrows we did
			p.numBorrowed++
			if time.Since(t) > testOnBorrowInterval {
				_, err := c.Do("PING")
				return err
			}
			return nil
		}

		p.pools[addr] = pool
	}

	return pool

}
開發者ID:robfinner,項目名稱:go-disque,代碼行數:28,代碼來源:pool.go

示例11: TestRedisStorageRemoveImagePrefixed

func TestRedisStorageRemoveImagePrefixed(t *testing.T) {
	conn := resultCommandConn{
		fakeConn: &fakeConn{},
		reply:    map[string]interface{}{"DEL": int64(1)},
	}
	var storage redisStorage
	storage.pool = redis.NewPool(func() (redis.Conn, error) {
		return &conn, nil
	}, 3)
	storage.prefix = "cluster"
	image := "tsuru/python"
	err := storage.RemoveImage(image)
	if err != nil {
		t.Error(err)
	}
	cmd := conn.cmds[0]
	expectedCmd := "DEL"
	if cmd.cmd != expectedCmd {
		t.Errorf("RemoveImage(%q): want command %q. Got %q.", image, expectedCmd, cmd.cmd)
	}
	expectedArgs := []interface{}{"cluster:image:" + image}
	if !reflect.DeepEqual(cmd.args, expectedArgs) {
		t.Errorf("RemoveImage(%q): want args %#v. Got %#v.", image, expectedArgs, cmd.args)
	}
}
開發者ID:pombredanne,項目名稱:docker-stuff,代碼行數:25,代碼來源:redis_test.go

示例12: NewRedisOption

func NewRedisOption(host string, password string, size int, num int, life int64) (*RedisOption, error) {
	ro := &RedisOption{
		num:      num,
		size:     size,
		life:     life,
		host:     host,
		password: password,
	}
	ro.Pool = redis.NewPool(func() (redis.Conn, error) {
		c, err := redis.Dial("tcp", ro.host)
		if err != nil {
			return nil, err
		}
		if ro.password != "" {
			if _, err := c.Do("AUTH", ro.password); err != nil {
				c.Close()
				return nil, err
			}
		}
		_, err = c.Do("SELECT", ro.num)
		if err != nil {
			c.Close()
			return nil, err
		}
		return c, err
	}, ro.size)
	err := ro.Pool.Get().Err()
	if err != nil {
		return nil, err
	}
	return ro, nil
}
開發者ID:tangseng,項目名稱:yts,代碼行數:32,代碼來源:base.go

示例13: TestRedisStorageRetrieveContainer

func TestRedisStorageRetrieveContainer(t *testing.T) {
	conn := resultCommandConn{
		fakeConn: &fakeConn{},
		reply:    map[string]interface{}{"GET": []byte("server0")},
	}
	var storage redisStorage
	storage.pool = redis.NewPool(func() (redis.Conn, error) {
		return &conn, nil
	}, 3)
	container := "affe3022"
	host, err := storage.RetrieveContainer(container)
	if err != nil {
		t.Error(err)
	}
	expectedHost := "server0"
	if host != expectedHost {
		t.Errorf("RetrieveContainer(%q): want host %q. Got %q.", container, expectedHost, host)
	}
	cmd := conn.cmds[0]
	expectedCmd := "GET"
	if cmd.cmd != expectedCmd {
		t.Errorf("RetrieveContainer(%q): want command %q. Got %q.", container, expectedCmd, cmd.cmd)
	}
	expectedArgs := []interface{}{container}
	if !reflect.DeepEqual(cmd.args, expectedArgs) {
		t.Errorf("RetrieveContainer(%q): want args %#v. Got %#v.", container, expectedArgs, cmd.args)
	}
}
開發者ID:pombredanne,項目名稱:docker-stuff,代碼行數:28,代碼來源:redis_test.go

示例14: Setup

func (rb *Redisbeat) Setup(b *beat.Beat) error {
	rb.events = b.Publisher.Connect()
	rb.done = make(chan struct{})

	// Set up redis pool
	redisPool := redis.NewPool(func() (redis.Conn, error) {
		c, err := redis.Dial(rb.network, rb.host+":"+strconv.Itoa(rb.port))

		if err != nil {
			return nil, err
		}

		return c, err
	}, rb.maxConn)

	rb.redisPool = redisPool

	if rb.auth {
		c := rb.redisPool.Get()
		defer c.Close()

		authed, err := c.Do("AUTH", rb.pass)
		if err != nil {
			return err
		} else {
			logp.Debug("redisbeat", "AUTH %v", authed)
		}
	}

	return nil
}
開發者ID:chrsblck,項目名稱:redisbeat,代碼行數:31,代碼來源:redisbeat.go

示例15: main

func main() {

	rp = redis.NewPool(func() (redis.Conn, error) {
		return redis.Dial("tcp", RedisHost+":"+RedisPort)
	}, 1000)

	var url = DbUser + ":" + DbPass + "@tcp(" + DbHost + ":" + DbPort + ")/" + DbName
	db, _ = sql.Open("mysql", url)
	defer db.Close()

	// Clear Redis
	go func() {
		c := rp.Get()
		c.Do("FLUSHALL")
	}()
	go loadAllUser()
	go loadAllFood()

	router := httprouter.New()
	router.POST("/login", LoginController)
	router.GET("/foods", FoodController)
	router.POST("/carts", NewCartsController)
	router.PATCH("/carts/:cart_id", FoodsToCartController)
	router.POST("/orders", PlaceOrderController)
	router.GET("/orders", ShowOrdersController)
	router.GET("/admin/orders", AdminShowOrdersController)

	log.Fatal(http.ListenAndServe(AppHost+":"+AppPort, router))
}
開發者ID:ele828,項目名稱:eleme-hackathon,代碼行數:29,代碼來源:main.go


注:本文中的github.com/garyburd/redigo/redis.NewPool函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。