Sha256: 5cd0c9fec71eda22ef7846e484b83edad2b938da977886171bfb2de55f162429

Contents?: true

Size: 972 Bytes

Versions: 25

Compression:

Stored size: 972 Bytes

Contents

package flapjack

import (
	"encoding/json"
	"github.com/garyburd/redigo/redis"
)

// Transport is a representation of a Redis connection.
type Transport struct {
	Address    string
	Database   int
	Connection redis.Conn
}

// Dial establishes a connection to Redis, wrapped in a Transport.
func Dial(address string, database int) (Transport, error) {
	// Connect to Redis
	conn, err := redis.Dial("tcp", address)
	if err != nil {
		return Transport{}, err
	}

	// Switch database
	conn.Do("SELECT", database)

	transport := Transport{
		Address:    address,
		Database:   database,
		Connection: conn,
	}
	return transport, nil
}

// Send takes an event and sends it over a transport.
func (t Transport) Send(event Event) (interface{}, error) {
	err := event.IsValid()
	if err == nil {
		data, _ := json.Marshal(event)
		reply, err := t.Connection.Do("LPUSH", "events", data)
		if err != nil {
			return nil, err
		}

		return reply, nil
	} else {
		return nil, err
	}
}

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
flapjack-2.0.0rc1 src/flapjack/transport.go
flapjack-2.0.0b1 src/flapjack/transport.go
flapjack-1.6.0 src/flapjack/transport.go
flapjack-1.6.0rc4 src/flapjack/transport.go
flapjack-1.6.0rc3 src/flapjack/transport.go
flapjack-1.6.0rc2 src/flapjack/transport.go
flapjack-1.6.0rc1 src/flapjack/transport.go
flapjack-1.5.0 src/flapjack/transport.go
flapjack-1.5.0rc1 src/flapjack/transport.go
flapjack-1.4.0 src/flapjack/transport.go
flapjack-1.4.0rc1 src/flapjack/transport.go
flapjack-1.3.0 src/flapjack/transport.go
flapjack-1.3.0rc3 src/flapjack/transport.go
flapjack-1.3.0rc2 src/flapjack/transport.go
flapjack-1.3.0rc1 src/flapjack/transport.go
flapjack-1.2.2 src/flapjack/transport.go
flapjack-1.2.1 src/flapjack/transport.go
flapjack-1.2.1rc3 src/flapjack/transport.go
flapjack-1.2.1rc2 src/flapjack/transport.go
flapjack-1.2.1rc1 src/flapjack/transport.go