Sha256: 4caa4031cbab917bcd313e0e979541b02bf8cbb2a360fcfbc4969f81b790b12b

Contents?: true

Size: 965 Bytes

Versions: 4

Compression:

Stored size: 965 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

4 entries across 4 versions & 1 rubygems

Version Path
flapjack-1.0.0rc6 src/flapjack/transport.go
flapjack-1.0.0rc5 src/flapjack/transport.go
flapjack-1.0.0rc3 src/flapjack/transport.go
flapjack-1.0.0rc2 src/flapjack/transport.go