예제 #1
0
func (c *redisCache) connect() {
	c.mutex.Lock()
	defer c.mutex.Unlock()
	logger.Printf("connecting")
	redis, err := goredis.DialURL(c.url)
	if err != nil {
		logger.Panicf("connecting failed: %s", err)
	}
	c.redis = redis
}
예제 #2
0
// NewRedisStorage checks config, creates the path and initializes a RedisStorage
func newRedisStorage(u *url.URL) (storageAdapter, error) {
	client, err := goredis.DialURL(strings.Replace(u.String(), "redis+", "", -1))
	if err != nil {
		return nil, err
	}

	return &RedisStorage{
		conn:   client,
		prefix: u.Query().Get("prefix"),
	}, nil
}
예제 #3
0
func connectRedis() {
	var err error
	redisClient, err = goredis.DialURL(conf.RedisURL)
	if err != nil {
		log.WithFields(logrus.Fields{
			"url":  conf.RedisURL,
			"host": hostname,
		}).Panic("Unable to connect to Redis")
		os.Exit(1)
	}
}
예제 #4
0
func getRedisConnection(request *messaging.ObjectRequest) (client *goredis.Redis, isError bool, errorMessage string) {

	isError = false
	client, err := goredis.DialURL("tcp://@" + request.Configuration.ServerConfiguration["REDIS"]["Host"] + ":" + request.Configuration.ServerConfiguration["REDIS"]["Port"] + "/0?timeout=10s&maxidle=1")
	if err != nil {
		isError = true
		errorMessage = err.Error()
		request.Log("Error! Can't connect to server!error")

	}
	request.Log("Reusing existing GoRedis connection")
	return
}
예제 #5
0
func getRedisExcelConnection(request *messaging.ObjectRequest) (client *goredis.Redis, isError bool, errorMessage string) {

	isError = false

	client, err := goredis.DialURL("tcp://@127.0.0.1:6379/0?timeout=10s&maxidle=1")
	if err != nil {
		isError = true
		errorMessage = err.Error()
		request.Log("Error! Can't connect to server!error")

	}
	request.Log("Reusing existing GoRedis connection")
	return
}
예제 #6
0
func init() {
	var err error
	log.Out = os.Stderr
	log.Formatter = &logrus.TextFormatter{ForceColors: true}

	cfg = config.Load()

	if cfg.Papertrail.Port != 0 {
		hook, err := logrus_papertrail.NewPapertrailHook(cfg.Papertrail.Host, cfg.Papertrail.Port, "GoBuilder Frontend")
		if err != nil {
			log.Panic("Unable to create papertrail connection")
			os.Exit(1)
		}

		log.Hooks.Add(hook)
	}

	redisClient, err = goredis.DialURL(cfg.RedisURL)
	if err != nil {
		log.WithFields(logrus.Fields{
			"url": cfg.RedisURL,
		}).Panic("Unable to connect to Redis")
		os.Exit(1)
	}

	sessionStoreAuthenticationKey := cfg.Session.AuthKey
	if sessionStoreAuthenticationKey == "" {
		sessionStoreAuthenticationKey = string(securecookie.GenerateRandomKey(32))
		log.Warn("The cookie authentication key was autogenerated. This will break sessions!")
	}
	sessionStoreEncryptionKey := cfg.Session.EncryptKey
	if sessionStoreEncryptionKey == "" {
		sessionStoreEncryptionKey = string(securecookie.GenerateRandomKey(32))
		log.Warn("The cookie encryption key was autogenerated. This will break sessions!")
	}

	sessionStore = sessions.NewCookieStore(
		[]byte(sessionStoreAuthenticationKey),
		[]byte(sessionStoreEncryptionKey),
	)

	gob.Register(&flashContext{})
}
예제 #7
0
파일: main.go 프로젝트: scraperwiki/cobalt
func main() {
	const N_WORKERS = 4

	url := os.ExpandEnv("tcp://*****:*****@${REDIS_SERVER}:6379/0?timeout=10s&maxidle=1")
	client, err := redis.DialURL(url)

	switch err := err.(type) {
	case *net.OpError:
		if err.Err.Error() == "connection refused" {
			log.Fatal("Connection refused. Aborting.")
		}
	}
	// if syscall.ECONNREFUSED.

	e := err.(*net.OpError).Err.(syscall.Errno)
	log.Println("conn:", e.Temporary(), e.Timeout(), e.Error())

	check(err)

	workQ := make(chan string, 100)

	for i := 0; i < N_WORKERS; i++ {
		go Worker(workQ)
	}

	pubsub, err := client.PubSub()
	check(err)

	err = pubsub.PSubscribe("production.cobalt.*")
	check(err)

	for {
		result, err := pubsub.Receive()
		check(err)

		event := result[0]

		if event != "pmessage" {
			continue
		}
		pattern, match, payload := result[1], result[2], result[3]

		_, _ = pattern, match

		m := &Message{}
		err = json.Unmarshal([]byte(payload), &m)
		if err != nil {
			log.Printf("Failed to unmarshal payload %q", err)
			continue
		}

		// log.Println(result)
		log.Printf("update hook boxes: %q", m.Boxes)

		for _, box := range m.Boxes {
			if !UpdateHookExists(box) {
				continue
			}
			log.Printf("qLen = %v", len(workQ))
			workQ <- box
		}
	}

	// for work := range ReadFromRedisQ() {
	// 	workQ <- work
	// }
}