Skip to content

Instantly share code, notes, and snippets.

@jeffscottbrown
Created November 16, 2018 13:34
Show Gist options
  • Select an option

  • Save jeffscottbrown/f3f5e0b1e79457babf6fa5b04a35ba4e to your computer and use it in GitHub Desktop.

Select an option

Save jeffscottbrown/f3f5e0b1e79457babf6fa5b04a35ba4e to your computer and use it in GitHub Desktop.
private Function<String, Mono<? extends Orders>> keyToOrder(RedisReactiveCommands<String, String> commands) {
return { key ->
Flux<KeyValue<String, String>> values = commands.hmget(key, "price", "description")
Map map = [:]
return values.reduce(map, (all, keyValue)= {all.put(keyValue.getKey(), keyValue.getValue())
return all
}).map({entries -> ConvertibleValues.of(entries)})
.flatMap({entries ->
String description = entries.get("description", String.class).orElseThrow({ new IllegalStateException("No description")})
BigDecimal price = entries.get("price", BigDecimal.class).orElseThrow({new IllegalStateException("No price")})
Flowable<Item> findItemFlowable = itemClient.find(key).toFlowable()
return Mono.from(findItemFlowable).map({item -> new Orders(item, description, price)})
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment