Beispiel #1
1
Datei: server.go Projekt: mc0/okq
func serveClient(client *clients.Client) {
	conn := client.Conn
	rr := redis.NewRespReader(conn)

outer:
	for {
		var command string
		var args []string

		m := rr.Read()
		if m.IsType(redis.IOErr) {
			log.L.Debug(client.Sprintf("client connection error %q", m.Err))
			if len(client.Queues) > 0 {
				consumers.UpdateQueues(client, []string{})
			}
			client.Close()
			return
		}

		parts, err := m.Array()
		if err != nil {
			log.L.Debug(client.Sprintf("error parsing to array: %q", err))
			continue outer
		}
		for i := range parts {
			val, err := parts[i].Str()
			if err != nil {
				log.L.Debug(client.Sprintf("invalid command part %#v: %s", parts[i], err))
				invalidCmdResp.WriteTo(conn)
				continue outer
			}
			if i == 0 {
				command = val
			} else {
				args = append(args, val)
			}
		}

		log.L.Debug(client.Sprintf("%s %#v", command, args))
		commands.Dispatch(client, command, args)
	}
}
Beispiel #2
0
func readAndAssertQStatus(t *T, client *clients.Client, expected []queueInfo) {
	rr := redis.NewRespReader(client.Conn)
	m := rr.Read()
	require.Nil(t, m.Err, "stack:\n%s", debug.Stack())

	arr, err := m.Array()
	require.Nil(t, err, "stack:\n%s", debug.Stack())
	require.Equal(t, len(expected), len(arr), "stack:\n%s", debug.Stack())

	for i := range expected {
		infoArr, err := arr[i].Array()
		require.Nil(t, err, "stack:\n%s", debug.Stack())
		assert.Equal(t, 4, len(infoArr), "stack:\n%s", debug.Stack())

		queueName, err := infoArr[0].Str()
		require.Nil(t, err, "stack:\n%s", debug.Stack())
		assert.Equal(t, expected[i].queueName, queueName, "stack:\n%s", debug.Stack())

		totalCount, err := infoArr[1].Int64()
		require.Nil(t, err, "stack:\n%s", debug.Stack())
		assert.Equal(t, expected[i].totalCount, totalCount, "stack:\n%s", debug.Stack())

		processingCount, err := infoArr[2].Int64()
		require.Nil(t, err, "stack:\n%s", debug.Stack())
		assert.Equal(t, expected[i].processingCount, processingCount, "stack:\n%s", debug.Stack())

		consumerCount, err := infoArr[3].Int64()
		require.Nil(t, err, "stack:\n%s", debug.Stack())
		assert.Equal(t, expected[i].consumerCount, consumerCount, "stack:\n%s", debug.Stack())
	}
}
Beispiel #3
0
func readAndAssertInt(t *T, client *clients.Client, expected int64) {
	rr := redis.NewRespReader(client.Conn)
	m := rr.Read()
	require.Nil(t, m.Err, "stack:\n%s", debug.Stack())
	i, err := m.Int64()
	require.Nil(t, err, "stack:\n%s", debug.Stack())
	assert.Equal(t, expected, i, "m: %v stack:\n%s", m, debug.Stack())
}
Beispiel #4
0
func readAndAssertStr(t *T, client *clients.Client, expected string) {
	rr := redis.NewRespReader(client.Conn)
	m := rr.Read()
	require.Nil(t, m.Err, "stack:\n%s", debug.Stack())
	s, err := m.Str()
	require.Nil(t, err, "stack:\n%s", debug.Stack())
	assert.Equal(t, expected, s, "m: %v stack:\n%s", m, debug.Stack())
}
Beispiel #5
0
func readAndAssertArr(t *T, client *clients.Client, expected []string) {
	rr := redis.NewRespReader(client.Conn)
	m := rr.Read()
	require.Nil(t, m.Err, "stack:\n%s", debug.Stack())

	arr, err := m.Array()
	require.Nil(t, err, "stack:\n%s", debug.Stack())
	require.Equal(t, len(expected), len(arr), "stack:\n%s", debug.Stack())

	for i := range expected {
		s, err := arr[i].Str()
		require.Nil(t, err, "stack:\n%s", debug.Stack())
		assert.Equal(t, expected[i], s, "m: %v stack:\n%s", m, debug.Stack())
	}
}
Beispiel #6
0
func readAndAssertNil(t *T, client *clients.Client) {
	rr := redis.NewRespReader(client.Conn)
	m := rr.Read()
	require.Nil(t, m.Err, "stack:\n%s", debug.Stack())
	assert.Equal(t, true, m.IsType(redis.Nil), "m: %v stack:\n%s", m, debug.Stack())
}
Beispiel #7
0
func read(t *T, client *clients.Client) *redis.Resp {
	rr := redis.NewRespReader(client.Conn)
	m := rr.Read()
	require.Nil(t, m.Err, "stack:\n%s", debug.Stack())
	return m
}