Beispiel #1
0
func (stats *StatsBackend) SIsMember(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 2 {
		client.WriteError(errors.New("SISMEMBER takes 2 parameters (SISMEMBER key member)"))
		client.Flush()
		return nil
	} else {
		key := string(d[0])
		results := make([]int64, len(d)-1)
		for i, v := range d[1:] {
			result, err := stats.mem.SIsMember(key, string(v))
			if err != nil {
				return err
			}
			results[i] = result
		}

		if len(results) > 1 {
			client.WriteLen('*', len(results))
			for _, v := range results {
				client.WriteInt64(v)
			}
		} else {
			client.WriteInt64(results[0])
		}
		client.Flush()
		return nil
	}
}
Beispiel #2
0
func (stats *StatsBackend) SCard(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 1 {
		client.WriteError(errors.New("SCARD takes at least 1 parameter (SCARD key)"))
		client.Flush()
		return nil
	} else {
		results := make([]int64, len(d))
		for i, v := range d {
			r, err := stats.mem.SCard(string(v))
			if err != nil {
				return err
			} else {
				results[i] = r
			}
		}

		if len(d) > 1 {
			client.WriteLen('*', len(d))
			for _, v := range results {
				client.WriteInt64(v)
			}
		} else {
			client.WriteInt64(results[0])
		}
		client.Flush()
		return nil
	}
}
Beispiel #3
0
func (stats *StatsBackend) FlushInt(i int64, err error, client server.ProtocolClient) error {
	if err != nil {
		return err
	}
	client.WriteInt64(i)
	client.Flush()
	return nil
}