Skip to content

Commit 1fcd14e

Browse files
committed
more proxy examples
1 parent 94a5e8e commit 1fcd14e

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

content/features/proxy/examples.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,39 @@ Please see
3434
[REPLICATE.md](https://github.com/memcached/memcached-proxylibs/blob/main/lib/routelib/REPLICATE.md)
3535
for more details on what replication means in memcached.
3636

37+
```lua
38+
pools{
39+
-- We create an anonymous set of 3 pools, each with one server.
40+
-- This lets us seamlessly expand the total size of the cache by adding
41+
-- servers to each pool without changing anything else.
42+
set_main = {
43+
{ backends = { "127.1.0.1:11211" } },
44+
{ backends = { "127.1.0.2:11211" } },
45+
{ backends = { "127.1.0.3:11211" } },
46+
},
47+
}
48+
49+
routes{
50+
cmap = {
51+
-- override specific commands to fetch from just one server for
52+
-- performance reasons.
53+
get = route_failover{
54+
children = "set_main",
55+
stats = true, -- get extra stats counters in `stats proxy`
56+
miss = true, -- failover if miss, not just for down server
57+
shuffle = true, -- each proxy will have a different order
58+
},
59+
-- if gat/gets/mg/etc are used override here.
60+
},
61+
-- by default, copy commands to all servers
62+
default = route_allfastest{
63+
child = "main",
64+
},
65+
}
66+
```
67+
68+
### Prefix router
69+
3770
```lua
3871
-- In this example we logically split our cache where by default keys are
3972
-- spread across a pool of servers to maximize available memory. Then, a small
@@ -85,3 +118,123 @@ routes{
85118
},
86119
}
87120
```
121+
122+
### Command map
123+
124+
```lua
125+
-- if you don't want to route based on prefix, but instead just based on the
126+
-- command used, replace map with cmap when building routes{}
127+
pools{
128+
foo = {
129+
backends = {
130+
"127.0.0.1:11214",
131+
"127.0.0.1:11215",
132+
}
133+
},
134+
bar = {
135+
backends = {
136+
"127.0.0.1:11216",
137+
}
138+
},
139+
}
140+
141+
routes{
142+
cmap = {
143+
get = route_direct{
144+
child = "foo",
145+
},
146+
},
147+
default = route_allfastest{
148+
children = { "bar" }
149+
},
150+
}
151+
```
152+
153+
### Route by listener port with tags
154+
155+
```lua
156+
-- it's possible to have different route trees based on the listener port.
157+
-- this is useful if you want to route to different pools by port alone, or
158+
-- have different prefix trees for different services.
159+
--
160+
-- memcached must be started like:
161+
-- -l 127.0.0.1:12051 -l tag_b_:127.0.0.1:12052 -l tag_cccc_:127.0.0.1:12053
162+
-- this gives a default listener on 12051, "b" tag for 12052, and "cccc" tag
163+
-- for 12053.
164+
pools{
165+
foo = {
166+
backends = {
167+
"127.0.0.1:11214",
168+
}
169+
},
170+
bar = {
171+
backends = {
172+
{ host = "127.0.0.1", port = 11215, retrytimeout = 5 }
173+
}
174+
},
175+
baz = {
176+
backends = {
177+
"127.0.0.1:11216",
178+
}
179+
},
180+
}
181+
182+
-- no supplied tag makes this the "default" router.
183+
routes{
184+
default = route_direct{
185+
child = "foo",
186+
}
187+
}
188+
189+
-- this route tree is only executed if a client is connected to port 12052
190+
routes{
191+
tag = "b",
192+
default = route_direct{
193+
child = "bar"
194+
}
195+
}
196+
197+
-- this route tree is only executed if a client is connected to port 12053
198+
routes{
199+
tag = "cccc",
200+
default = route_direct{
201+
child = "baz"
202+
}
203+
}
204+
```
205+
206+
### Nested route handlers
207+
208+
```lua
209+
-- A route handler can accept another route handler for any child type entry.
210+
-- This lets you freely compose complex behaviors from simpler route handlers.
211+
pools{
212+
one = {
213+
backends = {
214+
"127.0.0.1:11214",
215+
"127.0.0.1:11215",
216+
}
217+
},
218+
two = {
219+
backends = {
220+
"127.0.0.1:11216",
221+
}
222+
},
223+
three = {
224+
backends = {
225+
"127.0.0.1:11217",
226+
}
227+
},
228+
}
229+
230+
routes{
231+
map = {
232+
foo = route_split{
233+
child_a = "foo",
234+
child_b = route_allfastest{
235+
children = { "two", "three" }
236+
},
237+
},
238+
},
239+
}
240+
```

0 commit comments

Comments
 (0)