func (b *BGraphBackend) FindEdges(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 1 {
		client.WriteError(errors.New("*e takes at least 1 parameter (*e vertex [vertex ...])"))
		client.Flush()
		return nil
	}

	vertexEdges := make(map[string]map[string]float64)
	for _, k := range d {
		key := string(k)
		edges := b.db.findEdges(key)
		if edges != nil {
			vertexEdges[key] = edges
		}
	}

	if len(vertexEdges) > 0 {
		client.WriteJson(vertexEdges)
		client.Flush()
	} else {
		client.WriteNull()
		client.Flush()
	}
	return nil
}
Exemple #2
0
func (stats *StatsBackend) SInter(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 2 {
		client.WriteError(errors.New("SINTER takes at least 2 parameters (SINTER key [key ...])"))
		client.Flush()
		return nil
	} else {
		keys := make([]string, len(d))
		for i, v := range d {
			keys[i] = string(v)
		}
		results, err := stats.mem.SInter(keys)
		if err != nil {
			return err
		}

		if results == nil {
			client.WriteNull()
			client.Flush()
			return nil
		}

		client.WriteLen('*', len(results))
		for k, _ := range results {
			client.WriteString(k)
		}
		client.Flush()
		return nil
	}
}
Exemple #3
0
func (stats *StatsBackend) SMembers(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) == 0 {
		client.WriteError(errors.New("SMEMBERS takes 1 parameter (SMEMBERS key)"))
		client.Flush()
		return nil
	} else {
		values, err := stats.mem.SMembers(string(d[0]))
		if err != nil {
			return err
		}

		if values == nil {
			client.WriteNull()
			client.Flush()
			return nil
		}

		client.WriteLen('*', len(values))
		for k, _ := range values {
			client.WriteString(k)
		}
		client.Flush()
		return nil
	}
}
Exemple #4
0
func (stats *StatsBackend) SDiff(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 2 {
		client.WriteError(errors.New("SDIFF requires at least 2 parameters (SDIFF key [key ...])"))
		client.Flush()
		return nil
	} else {
		results, err := stats.mem.SMembers(string(d[0]))
		if err != nil {
			return err
		} else if results == nil {
			client.WriteNull()
			client.Flush()
			return nil
		} else {
			for _, v := range d[1:] {
				results, err = stats.mem.SDiff(results, string(v))
				if err != nil {
					return err
				} else if len(results) == 0 {
					break
				}
			}

			client.WriteLen('*', len(results))
			for k, _ := range results {
				client.WriteString(k)
			}
			client.Flush()
			return nil
		}
	}
}
func (b *BGraphBackend) IntersectEdges(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 2 {
		client.WriteError(errors.New("&e takes at least 2 parameters (&e vertex [vertex ...])"))
		client.Flush()
		return nil
	}

	keys := make([]string, len(d))
	for i, k := range d {
		keys[i] = string(k)
	}

	results := b.db.sumIntersectEdges(keys)
	if results != nil && len(results) > 0 {
		client.WriteJson(results)
		client.Flush()
	} else {
		client.WriteNull()
		client.Flush()
	}

	return nil
}
Exemple #6
0
func (stats *StatsBackend) FlushNil(client server.ProtocolClient) error {
	client.WriteNull()
	client.Flush()
	return nil
}