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


Golang redis.DialPassword函数代码示例

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


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

示例1: open

// Returns / creates instance of Redis connection
func (redisBroker *RedisBroker) open() (redis.Conn, error) {
	if redisBroker.socketPath != "" {
		return redis.Dial("unix", redisBroker.socketPath, redis.DialPassword(redisBroker.password), redis.DialDatabase(redisBroker.db))
	}

	// package redis takes care of pwd or db
	return redis.Dial("tcp", redisBroker.host, redis.DialPassword(redisBroker.password), redis.DialDatabase(redisBroker.db))
}
开发者ID:gooops,项目名称:machinery,代码行数:9,代码来源:redis.go

示例2: newPool

// Returns a new pool of Redis connections
func (redisBroker *RedisBroker) newPool() *redis.Pool {
	return &redis.Pool{
		MaxIdle:     3,
		IdleTimeout: 240 * time.Second,
		Dial: func() (redis.Conn, error) {
			var (
				c   redis.Conn
				err error
			)

			if redisBroker.password != "" {
				c, err = redis.Dial("tcp", redisBroker.host,
					redis.DialPassword(redisBroker.password))
			} else {
				c, err = redis.Dial("tcp", redisBroker.host)
			}

			if err != nil {
				return nil, err
			}
			return c, err
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			_, err := c.Do("PING")
			return err
		},
	}
}
开发者ID:jackdong16,项目名称:machinery,代码行数:29,代码来源:redis.go

示例3: open

// Returns / creates instance of Redis connection
func (redisBackend *RedisBackend) open() (redis.Conn, error) {
	if redisBackend.password != "" {
		return redis.Dial("tcp", redisBackend.host,
			redis.DialPassword(redisBackend.password))
	}
	return redis.Dial("tcp", redisBackend.host)
}
开发者ID:denkhaus,项目名称:machinery,代码行数:8,代码来源:redis.go

示例4: NewRedisPool

func NewRedisPool() *redis.Pool {
	return &redis.Pool{
		MaxIdle:   config.GetInt("redis_max_idle"),
		MaxActive: config.GetInt("redis_concurrent"), // max number of connections
		Dial: func() (redis.Conn, error) {
			var (
				c   redis.Conn
				err error
			)
			redis_host := fmt.Sprintf("%s:%s", config.GetMulti("redis_host", "redis_port")...)

			redis_passwd := config.Get("redis_passwd")
			if redis_passwd != "" {
				pwd := redis.DialPassword(redis_passwd)
				c, err = redis.Dial("tcp", redis_host, pwd)
			} else {
				c, err = redis.Dial("tcp", redis_host)
			}

			return c, err
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			_, err := c.Do("PING")
			return err
		},
	}
}
开发者ID:nagae-memooff,项目名称:surgemq,代码行数:27,代码来源:utils.go

示例5: tryConnect

// Iterate through `machines`, trying to connect to each in turn.
// Returns the first successful connection or the last error encountered.
// Assumes that `machines` is non-empty.
func tryConnect(machines []string, password string) (redis.Conn, error) {
	var err error
	for _, address := range machines {
		var conn redis.Conn
		network := "tcp"
		if _, err = os.Stat(address); err == nil {
			network = "unix"
		}
		log.Debug(fmt.Sprintf("Trying to connect to redis node %s", address))

		dialops := []redis.DialOption{
			redis.DialConnectTimeout(time.Second),
			redis.DialReadTimeout(time.Second),
			redis.DialWriteTimeout(time.Second),
		}

		if password != "" {
			dialops = append(dialops, redis.DialPassword(password))
		}

		conn, err = redis.Dial(network, address, dialops...)

		if err != nil {
			continue
		}
		return conn, nil
	}
	return nil, err
}
开发者ID:kelseyhightower,项目名称:confd,代码行数:32,代码来源:client.go

示例6: open

// Returns / creates instance of Redis connection
func (redisBroker *RedisBroker) open() (redis.Conn, error) {
	if redisBroker.password != "" {
		return redis.Dial("tcp", redisBroker.host,
			redis.DialPassword(redisBroker.password))
	}
	return redis.Dial("tcp", redisBroker.host)
}
开发者ID:jackdong16,项目名称:machinery,代码行数:8,代码来源:redis.go

示例7: newPool

// create pool
func newPool() *redis.Pool {
	return &redis.Pool{
		MaxIdle:   80,
		MaxActive: 12000, // max number of connections
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp", Conf.RedisHost, redis.DialPassword(Conf.RedisPwd))
			if err != nil {
				panic(err.Error())
			}
			return c, err
		},
	}
}
开发者ID:qinlodestar,项目名称:simplecomet,代码行数:14,代码来源:redis.go

示例8: ping

// ping executes a PING command against addr until timeout occurs.
func (p *Process) ping(addr string, timeout time.Duration) error {
	// Default to local process if addr not specified.
	if addr == "" {
		addr = fmt.Sprintf("localhost:%s", p.Port)
	}

	logger := p.Logger.New("fn", "ping", "addr", addr, "timeout", timeout)
	logger.Info("sending")

	timer := time.NewTimer(timeout)
	defer timer.Stop()

	ticker := time.NewTicker(checkInterval)
	defer ticker.Stop()

	for {
		// Attempt to ping the server.
		if ok := func() bool {
			logger.Info("sending PING")

			conn, err := redis.Dial("tcp", addr,
				redis.DialPassword(p.Password),
				redis.DialConnectTimeout(timeout),
				redis.DialReadTimeout(timeout),
				redis.DialWriteTimeout(timeout),
			)
			if err != nil {
				logger.Error("conn error", "err", err)
				return false
			}
			defer conn.Close()

			if _, err := conn.Do("PING"); err != nil {
				logger.Error("error getting upstream status", "err", err)
				return false
			}

			logger.Info("PONG received")
			return true
		}(); ok {
			return nil
		}

		select {
		case <-timer.C:
			logger.Info("timeout")
			return ErrTimeout
		case <-ticker.C:
		}
	}
}
开发者ID:ably-forks,项目名称:flynn,代码行数:52,代码来源:process.go

示例9: GetRedisConn

func GetRedisConn() {
	// tcp连接
	var err error
	dialoption := redis.DialPassword("admin")
	rs, err = redis.Dial("tcp", "localhost:6379", dialoption)

	// 若连接出错,则打印错误信息,返回
	if err != nil {
		fmt.Println(err)
		fmt.Println("redis connect error")
	} else {
		fmt.Println("redis conn success")
	}
}
开发者ID:yunkaiyueming,项目名称:go_code,代码行数:14,代码来源:redis.go

示例10: main

func main() {
	var (
		listen = flag.String("listen", ":8080", "HTTP listen address")
		// proxy  = flag.String("proxy", "", "Optional comma-separated list of URLs to proxy uppercase requests")
	)
	flag.Parse()

	var logger log.Logger
	logger = log.NewLogfmtLogger(os.Stderr)
	logger = log.NewContext(logger).With("listen", *listen).With("caller", log.DefaultCaller)
	loglevel := levels.New(logger)

	ctx := context.Background()

	redisURL := os.Getenv("REDIS_URL")
	redisPassword := os.Getenv("REDIS_PASSWORD")
	if redisURL == "" || redisPassword == "" {
		_ = loglevel.Crit("err", "missing REDIS connection information")
		return
	}

	infra, err := BuildInfrastructure(InfrastructureOptions{
		DialURL:    os.Getenv("REDIS_URL"),
		DialOption: []redis.DialOption{redis.DialPassword(redisPassword)},
	})
	if err != nil {
		_ = loglevel.Crit("err", fmt.Sprintf("Infrastructure error: %v", err))
		return
	}
	defer infra.conn.Close()

	var svc CacheService
	svc = cacheService{}
	svc = loggingMiddleware(logger)(svc)

	cacheHandler := httptransport.NewServer(
		ctx,
		makeCacheEndpoint(svc),
		decodeCacheRequest,
		encodeResponse,
	)

	http.Handle("/cache", cacheHandler)
	_ = logger.Log("msg", "HTTP", "addr", *listen)
	_ = logger.Log("err", http.ListenAndServe(*listen, nil))
}
开发者ID:anweiss,项目名称:fiadatasearch,代码行数:46,代码来源:main.go

示例11: RedisInfo

// RedisInfo executes an INFO command against a Redis server and returns the results.
func (p *Process) RedisInfo(addr string, timeout time.Duration) (*RedisInfo, error) {
	// Default to local process if addr not specified.
	if addr == "" {
		addr = fmt.Sprintf("localhost:%s", p.Port)
	}

	logger := p.Logger.New("fn", "replInfo", "addr", addr)
	logger.Info("sending INFO")

	// Connect to the redis server.
	conn, err := redis.Dial("tcp", addr,
		redis.DialPassword(p.Password),
		redis.DialConnectTimeout(timeout),
		redis.DialReadTimeout(timeout),
		redis.DialWriteTimeout(timeout),
	)
	if err != nil {
		logger.Info("dial error", "err", err)
		return nil, err
	}
	defer conn.Close()

	// Execute INFO command.
	reply, err := conn.Do("INFO")
	if err != nil {
		logger.Error("info error", "err", err)
		return nil, err
	}

	buf, ok := reply.([]byte)
	if !ok {
		logger.Error("info reply type error", "type", fmt.Sprintf("%T", buf))
		return nil, fmt.Errorf("unexpected INFO reply format: %T", buf)
	}

	// Parse the bulk string reply info a typed object.
	info, err := ParseRedisInfo(string(buf))
	if err != nil {
		logger.Error("parse info error", "err", err)
		return nil, fmt.Errorf("parse info: %s", err)
	}

	logger.Info("INFO received")
	return info, nil
}
开发者ID:ably-forks,项目名称:flynn,代码行数:46,代码来源:process.go

示例12: RedisPool

// RedisPool will read env and init a redis pool
func RedisPool() *redis.Pool {
	return &redis.Pool{
		MaxIdle:   100,
		MaxActive: 12000,
		Dial: func() (redis.Conn, error) {
			addr := os.Getenv("REDIS_ADDR")
			port := os.Getenv("REDIS_PORT")
			passwd := os.Getenv("REDIS_PASSWD")
			option := redis.DialPassword(passwd)

			c, err := redis.Dial("tcp", addr+":"+port, option)
			return c, err
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			_, err := c.Do("PING")
			return err
		},
	}
}
开发者ID:killpanda,项目名称:go-db,代码行数:20,代码来源:redis.go

示例13: newPool

// creates a redis connection pool to use
func (r Redis) newPool(server, password string) *redis.Pool {
	return &redis.Pool{
		MaxIdle:     3,
		IdleTimeout: 5 * time.Second,
		Dial: func() (redis.Conn, error) {
			c, err := redis.DialURL(server, redis.DialConnectTimeout(30*time.Second),
				redis.DialWriteTimeout(10*time.Second), redis.DialPassword(password))

			if err != nil {
				return nil, fmt.Errorf("Failed to reach redis - %v", err)
			}
			return c, err
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			_, err := c.Do("PING")
			return err
		},
	}
}
开发者ID:nanopack,项目名称:portal,代码行数:20,代码来源:redis.go

示例14: setPool

// Connection is to connect Redis server
func (rd *RD) setPool(host string, port uint16, pass string) {
	rd.Pool = &redis.Pool{
		MaxIdle:   80,
		MaxActive: 12000, // max number of connections
		Dial: func() (redis.Conn, error) {
			var c redis.Conn
			var err error
			if pass != "" {
				//plus password
				c, err = redis.Dial("tcp", fmt.Sprintf("%s:%d", host, port), redis.DialPassword(pass))
			} else {
				c, err = redis.Dial("tcp", fmt.Sprintf("%s:%d", host, port))
			}
			if err != nil {
				panic(err.Error())
			}
			return c, err
		},
	}
}
开发者ID:hiromaily,项目名称:go-book-teacher,代码行数:21,代码来源:redis.go

示例15: initalPool

func (p *RedisCounterStorage) initalPool() {
	p.pool = &redis.Pool{
		MaxIdle:     p.redisConfig.MaxIdle,
		IdleTimeout: p.redisConfig.IdleTimeout,
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp",
				p.redisConfig.Address,
				redis.DialDatabase(p.redisConfig.Db),
				redis.DialPassword(p.redisConfig.Password))

			if err != nil {
				return nil, err
			}
			return c, err
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			_, err := c.Do("PING")
			return err
		},
		Wait: true,
	}
}
开发者ID:admpub,项目名称:access_limiter,代码行数:22,代码来源:redis_counter_storage.go


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