예제 #1
1
파일: server.go 프로젝트: 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)
	}
}
예제 #2
0
파일: commands_test.go 프로젝트: mc0/okq
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())
	}
}
예제 #3
0
파일: commands_test.go 프로젝트: mc0/okq
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())
}
예제 #4
0
파일: commands_test.go 프로젝트: mc0/okq
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())
}
예제 #5
0
파일: commands_test.go 프로젝트: mc0/okq
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())
	}
}
예제 #6
0
파일: commands_test.go 프로젝트: mc0/okq
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())
}
예제 #7
0
파일: commands_test.go 프로젝트: mc0/okq
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
}