|
| 1 | ++++ |
| 2 | +title = 'Configuration Examples' |
| 3 | +weight = 35 |
| 4 | ++++ |
| 5 | + |
| 6 | +This page includes configuration files for common use cases. |
| 7 | + |
| 8 | +For several more examples demonstrating various circumstances and topologies, see [the `examples` directory in the route library source](https://github.com/memcached/memcached-proxylibs/tree/main/lib/routelib/examples) |
| 9 | + |
| 10 | +### Basic consistent hashing to pool of servers |
| 11 | + |
| 12 | +```lua |
| 13 | +-- Minimal configuration. |
| 14 | +-- No high level routing: just hash keys against the pool's list of backends. |
| 15 | +-- This should be equivalent to a standard memcached client. |
| 16 | + |
| 17 | +pools{ |
| 18 | + main = { |
| 19 | + backends = { |
| 20 | + "127.0.0.1:11214", |
| 21 | + "127.0.0.1:11215", |
| 22 | + } |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +routes{ |
| 27 | + default = route_direct{ child = "main" } |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +### Basic replication for availability or speed |
| 32 | + |
| 33 | +Please see |
| 34 | +[REPLICATE.md](https://github.com/memcached/memcached-proxylibs/blob/main/lib/routelib/REPLICATE.md) |
| 35 | +for more details on what replication means in memcached. |
| 36 | + |
| 37 | +```lua |
| 38 | +-- In this example we logically split our cache where by default keys are |
| 39 | +-- spread across a pool of servers to maximize available memory. Then, a small |
| 40 | +-- set of highly accessed "hot" keys are replicated across multiple servers |
| 41 | + |
| 42 | +pools{ |
| 43 | + main = { |
| 44 | + backends = { |
| 45 | + "127.0.0.1:11211", |
| 46 | + "127.0.0.2:11211", |
| 47 | + "127.0.0.3:11211", |
| 48 | + "127.0.0.4:11211", |
| 49 | + "127.0.0.5:11211", |
| 50 | + } |
| 51 | + }, |
| 52 | + -- These could even be a subset of the same servers listed above, however |
| 53 | + -- we have to describe it as three pools with one backend in each. |
| 54 | + set_hot = { |
| 55 | + { backends = { "127.1.0.1:11211" } }, |
| 56 | + { backends = { "127.1.0.2:11211" } }, |
| 57 | + { backends = { "127.1.0.3:11211" } }, |
| 58 | + }, |
| 59 | +} |
| 60 | + |
| 61 | +-- keys with prefix "hot/" get routed to a special handler. |
| 62 | +routes{ |
| 63 | + map = { |
| 64 | + hot = cmdmap{ |
| 65 | + -- send all commands to all pools by default |
| 66 | + -- only wait for one response before returning result |
| 67 | + all = route_allfastest{ |
| 68 | + children = "set_hot" |
| 69 | + }, |
| 70 | + -- override specific commands to fetch from just one server for |
| 71 | + -- performance reasons. |
| 72 | + get = route_failover{ |
| 73 | + children = "set_hot", |
| 74 | + stats = true, |
| 75 | + miss = true, -- failover if miss, not just for down server |
| 76 | + shuffle = true, -- each proxy will have a different order |
| 77 | + }, |
| 78 | + -- if gat/gets/mg/etc are used override here. |
| 79 | + }, |
| 80 | + }, |
| 81 | + -- by default, all commands map to exactly one server within the larger |
| 82 | + -- pool. |
| 83 | + default = route_direct{ |
| 84 | + child = "main", |
| 85 | + }, |
| 86 | +} |
| 87 | +``` |
0 commit comments