コード例 #1
0
ファイル: redis.go プロジェクト: crazyfacka/redis-nom
func apples(name string, addr string, master bool) {
	var role string
	if master {
		role = "master"
	} else {
		role = "slave"
	}

	client := redis.NewClient(&redis.Options{
		Addr: addr,
	})

	if err := client.Ping().Err(); err != nil {
		l2n.Printf("Error connecting to %s '%s' of pod %s\n", role, addr, name)
		pd("Error connecting to "+role, map[string]interface{}{
			"Pod":     name,
			"Address": addr,
		})
		return
	}

	setRedisClientName(client)

	l2n.Printf("Connected to Redis '%s' @ %s", name, addr)

	ticker := time.NewTicker(time.Second * 30)
	for range ticker.C {
		blob := getInfoAsBlob(client)
		for _, section := range infoSections {
			dispatcher.Publish("redis-"+role, addr, section, blob[section])
		}
	}

	l2n.Printf("Shouldn't be here - Stopped checking %s", name)
}
コード例 #2
0
ファイル: sentinel.go プロジェクト: crazyfacka/redis-nom
func bananas(addr string) {
	var err error
	var psub *redis.PubSub

	client := redis.NewClient(&redis.Options{
		Addr: addr,
	})

	if err = client.Ping().Err(); err != nil {
		l2n.Printf("Error talking with sentinel @ %s", addr)
		pd("Error connecting to sentinel", map[string]interface{}{
			"Addr": addr,
		})
		return
	}

	setRedisClientName(client)

	if psub, err = client.PSubscribe("*"); err != nil {
		l2n.Printf("Error subscribing to * from sentinel @ %s", addr)
		pd("Error subscribing to sentinel", map[string]interface{}{
			"Addr":  addr,
			"Topic": "*",
		})
		return
	}

	l2n.Printf("Subscribed to * from %s", addr)

	defer psub.Close()

	for {
		if msg, err := psub.ReceiveMessage(); err == nil {
			dispatcher.Publish("sentinel", addr, msg.Channel, msg.Payload)
		} else {
			time.Sleep(100 * time.Millisecond)
		}
	}
}