Esempio n. 1
0
func MyCassandraSave(cp gossie.ConnectionPool, data *ExampleData) error {
	mapping, _ := gossie.NewMapping(&ExampleData{})

	b := cp.Batch()
	b.Insert(mapping, data)
	return b.Run()
}
Esempio n. 2
0
func MyCassandraLoad(cp gossie.ConnectionPool, id string) (*ExampleData, error) {
	mapping, _ := gossie.NewMapping(&ExampleData{})

	query := cp.Query(mapping)
	result, err := query.Get(id)
	if err != nil {
		return nil, err
	}
	data := &ExampleData{}
	err = result.Next(data)
	return data, err
}
Esempio n. 3
0
// getColumnFamily starts a read in a goroutine and returns a channel.
func getColumnFamily(cf string, pool gossie.ConnectionPool, rowKey string) <-chan rowResult {
	outChan := make(chan rowResult)

	go func() {
		glog.V(3).Infoln("Reading data for " + cf + " ...")
		row, err := pool.Reader().Cf(cf).Get([]byte(rowKey))
		if err != nil {
			outChan <- rowResult{nil, err}
		}
		outChan <- rowResult{row, nil}
	}()

	return outChan
}
Esempio n. 4
0
// getColumnFamilyRange starts a range read in a goroutine and returns a channel.
func getColumnFamilyRange(cf string, pool gossie.ConnectionPool, startPrefix string,
	endPrefix string, maxResults int) <-chan rowResults {
	outChan := make(chan rowResults)

	go func() {
		glog.V(3).Infoln("Reading data for " + cf + " ...")
		rows, err := pool.Reader().Cf(cf).ReturnNilRows(true).RangeGet(
			&gossie.Range{Start: []byte(startPrefix), End: []byte(endPrefix), Count: maxResults})
		if err != nil {
			outChan <- rowResults{nil, err}
		}
		outChan <- rowResults{rows, nil}
	}()

	return outChan
}