コード例 #1
0
func init() {
	log.Println("Initializing redis client")
	client = redis.NewTCPClient(&redis.Options{
		Addr: ":6379",
	})
	log.Println("Redis up and going")
}
コード例 #2
0
ファイル: output_redis.go プロジェクト: crudbug/packetbeat
func (out *RedisOutputType) PublishIPs(name string, localAddrs []string) error {

	DEBUG("output_redis", "[%s] Publish the IPs %s", name, localAddrs)

	// connect to db
	client := redis.NewTCPClient(&redis.Options{
		Addr:        out.Hostname,
		Password:    out.Password,
		DialTimeout: out.Timeout,
	})
	client.Select(int64(out.DbTopology))

	defer client.Close()

	_, err := client.HSet(name, "ipaddrs", strings.Join(localAddrs, ",")).Result()
	if err != nil {
		ERR("[%s] Fail to set the IP addresses: %s", name, err)
		return err
	}

	_, err = client.Expire(name, out.TopologyExpire).Result()
	if err != nil {
		ERR("[%s] Fail to set the expiration time: %s", name, err)
		return err
	}

	out.UpdateLocalTopologyMap(client)

	return nil
}
コード例 #3
0
ファイル: output_redis.go プロジェクト: crudbug/packetbeat
func (out *RedisOutputType) Connect() error {
	client := redis.NewTCPClient(&redis.Options{
		Addr:        out.Hostname,
		Password:    out.Password,
		DB:          int64(out.Db),
		DialTimeout: out.Timeout,
	})

	_, err := client.Ping().Result()
	if err != nil {
		ERR("Failed connection to Redis. ping returns an error: %s", err)
		return err
	}
	out.Client = client
	out.connected = true

	return nil
}
コード例 #4
0
ファイル: geobin.go プロジェクト: kpettijohn/geobin.io
// starts the redis pump and http server
func main() {
	flag.Parse()
	// TODO: verify if this is actually beneficial
	runtime.GOMAXPROCS(runtime.NumCPU())

	// load up config.json
	conf := loadConfig()

	// redis client
	client := redis.NewTCPClient(&redis.Options{
		Addr:     conf.RedisHost,
		Password: conf.RedisPass,
		DB:       conf.RedisDB,
	})

	if ping := client.Ping(); ping.Err() != nil {
		log.Fatal(ping.Err())
	}

	// redis pubsub connection
	ps := client.PubSub()

	// prepare a socketmap
	sm := NewSocketMap(ps)

	// loop for receiving messages from Redis pubsub, and forwarding them on to relevant ws connection
	go redisPump(ps, sm)

	defer func() {
		ps.Close()
		client.Close()
	}()

	// prepare server
	http.Handle("/", NewGeobinServer(conf, NewRedisWrapper(client), ps, sm))

	// Start up HTTP server
	log.Println("Starting server at", conf.Host, conf.Port)
	err := http.ListenAndServe(fmt.Sprintf("%v:%d", conf.Host, conf.Port), nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}
コード例 #5
0
ファイル: app.go プロジェクト: yukidarake/isucon4
func init() {
	rd = redis.NewTCPClient(&redis.Options{
		Addr: "localhost:6379",
		DB:   0,
	})
}