本文整理匯總了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))
}
示例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
},
}
}
示例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)
}
示例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
},
}
}
示例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
}
示例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)
}
示例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
},
}
}
示例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:
}
}
}
示例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")
}
}
示例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))
}
示例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
}
示例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
},
}
}
示例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
},
}
}
示例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
},
}
}
示例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,
}
}