-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path2020-09-02-mutiny-redis.adoc.po
267 lines (225 loc) · 14 KB
/
2020-09-02-mutiny-redis.adoc.po
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# SOME DESCRIPTIVE TITLE
# Copyright (C) YEAR Free Software Foundation, Inc.
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2022-05-12 15:52+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. type: YAML Front Matter: title
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy, no-wrap
msgid "Using Redis with Mutiny - Composing asynchronous actions"
msgstr "在Mutiny中使用Redis - 组成异步行动"
#. type: YAML Front Matter: synopsis
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy, no-wrap
msgid "How to compose asynchronous actions with Mutiny"
msgstr "如何用Mutiny编排异步行动"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "I got an interesting question from a user about Redis and Mutiny. While the problem was not specifically about Redis and could be applied to many other APIs, I found the context amusing."
msgstr "我从一个用户那里得到了一个关于Redis和Mutiny的有趣问题。虽然这个问题并不是专门针对Redis的,也可以应用于其他许多API,但我发现这个问题的背景很有趣。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "Enrico, the user, wanted to do something like this:"
msgstr "用户Enrico想做这样的事情。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "Enrico is using the Mutiny variant of the Vert.x Redis Client."
msgstr "Enrico正在使用Vert.x Redis客户端的Mutiny变体。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "This client offers a few methods to help us with our problem:"
msgstr "这个客户提供了一些方法来帮助我们解决这个问题。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "the `RedisClient.keys(pattern)` method returning `Uni<JsonArray>`. This array contains the list of keys matching a pattern passed to the `keys` method. To simplify this post, let's use: `keys(\"*\")` returning all the keys."
msgstr " `RedisClient.keys(pattern)` 方法返回 `Uni<JsonArray>` 。这个数组包含了与传递给 `keys` 方法的模式相匹配的键的列表。为了简化这个帖子,让我们使用: `keys(\"*\")` ,返回所有的键。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "the `RedisClient.hgetall(key)` method returning a `Uni<JsonObject>`. This method retrieves the object associated with the passed key."
msgstr " `RedisClient.hgetall(key)` 方法返回一个 `Uni<JsonObject>` 。该方法检索与所传递的键相关的对象。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "Both methods are asynchronous (they return `Uni`), and we need to call the second one for each retrieved key. In other words, we need to iterate over the set of keys, and for each key to invoke an asynchronous action. Finally, we want to collect the result of these asynchronous actions into a `JsonArray`."
msgstr "这两个方法都是异步的(它们返回 `Uni` ),我们需要为每个检索到的键调用第二个方法。换句话说,我们需要遍历键的集合,并为每个键调用一个异步的动作。最后,我们要将这些异步操作的结果收集到一个 `JsonArray` 。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "Let's start with the beginning; we need the Redis Client instance:"
msgstr "让我们从头开始;我们需要Redis客户端实例。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "Note that in Quarkus, you should use the Redis extension directly, which exposes a similar API. Enrico wanted to use the Vert.x Redis Client directly."
msgstr "注意,在Quarkus中,你应该直接使用Redis扩展,它暴露了一个类似的API。Enrico想直接使用Vert.x Redis客户端。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "Now that we have our client, let's retrieve the list of keys:"
msgstr "现在我们有了客户端,让我们检索一下键的列表。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "That produces the `JsonArray`, but we want a stream of keys. Again, it's an asynchronous method. The returned `Uni` receives the array when it's available. Once received (`onItem`), we can create a stream out of this array:"
msgstr "这产生了 `JsonArray` ,但我们想要一个键的流。同样,这是一个异步方法。当数组可用时,返回的 `Uni` 接收数组。一旦收到( `onItem` ),我们可以从这个数组中创建一个流。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "This snippet:"
msgstr "这个片段。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "retrieves the `JsonArray` containing the keys"
msgstr "检索包含键的 `JsonArray` "
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "creates a `Multi` streaming these keys, it's a `Multi<Object>` as a `JsonArray` is extending `Iterable<Object>`"
msgstr "创建一个 `Multi` ,将这些键分流,它是一个 `Multi<Object>` ,因为一个 `JsonArray` ,是扩展的。 `Iterable<Object>` "
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "maps the items from this `Multi` to `String`"
msgstr "将这个 `Multi` 中的项目映射到 `String` "
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "At this point, we have a stream of (String) keys. So, we are done with step 1."
msgstr "在这一点上,我们有一个(String)键的流。所以,我们已经完成了第1步。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "Now, step 2: for each key, we want to retrieve the associated object."
msgstr "现在,第二步:对于每个键,我们要检索相关的对象。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "So let's use the `hgetall` method:"
msgstr "因此,让我们使用 `hgetall` 方法。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "This snippet requires a bit of an explanation."
msgstr "这个片段需要做一些解释。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "For each item of the stream `keys`, we call `hgetall`, which produces a `Uni<JsonObject>`."
msgstr "对于数据流中的每一项 `keys` ,我们调用 `hgetall` ,从而产生一个 `Uni<JsonObject>` 。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "So, we want to transform our key into a Uni (*transformToUni*)."
msgstr "所以,我们要把我们的键转化为Uni *(transformToUni* )。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "When you have a stream of items and need to invoke an asynchronous action for each item, you must choose how you will merge the results. Mutiny provides two strategies:"
msgstr "当你有一个项目流并需要为每个项目调用一个异步动作时,你必须选择如何合并结果。Mutiny提供了两种策略。"
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "*merge -* as soon as the item produced by the `Uni` is received we send it downstream"
msgstr "*合并 -* 一旦收到 `Uni` 生产的物品,我们就将其发送到下游"
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "*concatenate* - we preserve the order of the input stream to be sure that the items are sent downstream in the same order"
msgstr "*连接* - 我们保留输入流的顺序,以确保项目以相同的顺序向下发送"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "Let's illustrate this. Imagine we have the keys `1`, `2`, `3` and to the stream `{1, 2, 3}`. Also, let's consider that in our Redis database, the key `1` is associated to `A`, `2` to `B` and `3` to `C`."
msgstr "让我们来说明这一点。想象一下,我们有键 `1` , `2` , `3` 和到流 `{1, 2, 3}` 。另外,让我们考虑一下,在我们的Redis数据库中,键 `1` 与 `A` , `2` 与 `B` , `3` 与 `C` 。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "If you use the *merge* strategy, we are retrieving the associated objects in an undetermined order. We can end up with `{A, C, B}` or `{B, A, C}`. It depends on many factors, such as the latency, scheduling, load and so on. However, it also means we can retrieve all the associated objects concurrently and produce the resulting stream without taking care of the order."
msgstr "如果你使用 *合并* 策略,我们是以不确定的顺序检索相关对象。我们最终可以得到 `{A, C, B}` 或 `{B, A, C}` 。这取决于许多因素,如延迟、调度、负载等等。然而,这也意味着我们可以同时检索所有相关的对象,并产生结果流,而不考虑顺序。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "If you use the *concatenate* strategy, it preserves the order from the input stream. So, it will always produce `{A, B, C}`. While it may be desirable, it may reduce the ability to retrieve the object concurrently, as Mutiny has to *wait* for all the retrieval of all the previous objects. For example, if Mutiny receives `C` first, it needs to wait for `A` and `B` before sending `C` downstream."
msgstr "如果你使用 *连接* 策略,它将保留输入流的顺序。所以,它将总是产生 `{A, B, C}` 。虽然这可能是可取的,但它可能会降低并发检索对象的能力,因为Mutiny必须 *等待* 所有之前的对象的检索。例如,如果Mutiny先收到 `C` ,它需要等待 `A` 和 `B` ,然后再向下游发送 `C` 。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "In our context, let's not preserve the order and use the *merge* strategy. So we use `transformToUniAndMerge`."
msgstr "在我们的环境中,让我们不保留顺序,使用 *合并* 策略。所以我们使用 `transformToUniAndMerge` 。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "If you run the code multiple times, you might see order changes in the resulting array."
msgstr "如果你多次运行该代码,你可能会看到结果数组中的顺序变化。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "Ok, step 2 done. Let's focus on the final steps: accumulate the objects into a `JsonArray`, and produce a `Uni<JsonArray>`, containing all the objects. Mutiny provides methods to gather items from a stream into lists, maps, sets, but there is no built-in `JsonArray` support. Fortunately, Mutiny offers a method that you can use to collect items in any structure:"
msgstr "好了,第二步完成了。让我们专注于最后的步骤:将对象累积到一个 `JsonArray` ,并产生一个 `Uni<JsonArray>` ,包含所有的对象。Mutiny提供了从流中收集项目到列表、地图、集合的方法,但是没有内置的 `JsonArray` 支持。幸运的是,Mutiny提供了一种方法,你可以用它来收集任何结构中的项目。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "`collectItems().in` allows accumulating the items in your own structure. It takes two parameters: a supplier of the structure, called only once, and a bi-consumer taking the structure and the item to add, called for each item."
msgstr " `collectItems().in` 允许在你自己的结构中积累项目。它需要两个参数:一个是结构的供应商,只被调用一次,另一个是获取结构和要添加的项目的双消费者,为每个项目调用。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "Here we go, we have everything to solve Enrico's question."
msgstr "在这里,我们有一切可以解决恩里克的问题。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "The *all in one* code is the following:"
msgstr " *一体化* 的代码如下。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "In this snippet, there are a few interesting patterns:"
msgstr "在这个片段中,有几个有趣的模式。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "When you have a collection, and you want to iterate on it with Mutiny, transform it into a `Multi`"
msgstr "当你有一个集合,并且你想用Mutiny对它进行迭代时,把它转化为一个 `Multi` "
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "When you execute asynchronous action for each item of a stream, think about *merge* vs. *concatenate.* Use the one that makes sense for you."
msgstr "在对数据流中的每个项目执行异步操作时,请考虑 *合并* 与 *连接的问题。* 请使用对您有意义的操作 *。*"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "To accumulate items into a structure, use `collectItems`, it offers many methods to produce your structure of choice."
msgstr "要将物品堆积成一个结构,请使用 `collectItems` ,它提供了多种方法来制作您所选择的结构。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "If you want to see this code in action, check this https://gist.github.com/cescoffier/e8c8a18897f9e5ca15f1378876a1bd93[gist]. You even can run it directly with JBang:"
msgstr "如果您想看看这段代码的实际运行情况,请查看此 link:https://gist.github.com/cescoffier/e8c8a18897f9e5ca15f1378876a1bd93[gist] 。你甚至可以直接用 JBang 运行它:"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "You can replace *merge* with *concatenate* to see the difference."
msgstr "您可以将 *合并* 替换为 *连接* ,以了解两者的区别。"
#. type: Plain text
#: _posts/2020-09-02-mutiny-redis.adoc
#, fuzzy
msgid "Enjoy!"
msgstr "请慢用"