Exemplo n.º 1
0
func (rc *RedisCache) connectInit() (redis.Conn, error) {
	c, err := redis.Dial("tcp", rc.conninfo)
	if err != nil {
		return nil, err
	}
	return c, nil
}
Exemplo n.º 2
0
// init redis session
// savepath like redis server addr,pool size,password
// e.g. 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 rp.poollist.Get().Err()
}
Exemplo n.º 3
0
Arquivo: redis.go Projeto: kanbl/beego
// connect to redis.
func (rc *RedisCache) connectInit() {
	// initialize a new pool
	rc.p = &redis.Pool{
		MaxIdle:     3,
		IdleTimeout: 180 * time.Second,
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp", rc.conninfo)
			if err != nil {
				return nil, err
			}
			return c, nil
		},
	}
}
Exemplo n.º 4
0
//Test connect function
func TestConnect(host_info HostInfo, chan_result chan HostInfo) {
	host := host_info.host
	port := host_info.port
	reply := host_info.reply
	is_vul := false
	c, err := redis.Dial("tcp", host+":"+port)
	// _, err := redis.DialTimeout("tcp", host+":"+port, 2*time.Second, 2*time.Second, 2*time.Second)
	if err == nil {
		s, err := redis.String(c.Do("ping"))
		if err == nil {
			is_vul = true
			reply = s
		}
	}

	host_info.is_vul = is_vul
	host_info.reply = reply
	chan_result <- host_info

}