|
| 1 | +function put_config() |
| 2 | + local fio = require('fio') |
| 3 | + local cluster_config_handle = fio.open('../../source.yaml') |
| 4 | + local cluster_config = cluster_config_handle:read() |
| 5 | + |
| 6 | + -- Connect to a config.storage and put the config. |
| 7 | + local storage_client = config.storage_client.connect({ |
| 8 | + '127.0.0.1:4401', |
| 9 | + '127.0.0.1:4402', |
| 10 | + '127.0.0.1:4403', |
| 11 | + }) |
| 12 | + local response = storage_client:put('/myapp/config/all', cluster_config) |
| 13 | + |
| 14 | + -- Put a config to a configured config.storage cluster. |
| 15 | + response = config.storage_client:put('/myapp/config/all', cluster_config) |
| 16 | + |
| 17 | + cluster_config_handle:close() |
| 18 | + |
| 19 | + return response |
| 20 | +end |
| 21 | + |
| 22 | +function get_config_by_path() |
| 23 | + -- Connect to a config.storage and get /myapp/config/all. |
| 24 | + local storage_client = config.storage_client.connect({ |
| 25 | + '127.0.0.1:4401', |
| 26 | + '127.0.0.1:4402', |
| 27 | + '127.0.0.1:4403', |
| 28 | + }) |
| 29 | + local response = storage_client:get('/myapp/config/all') |
| 30 | + |
| 31 | + -- Get /myapp/config/all from a configured config.storage cluster. |
| 32 | + response = config.storage_client:get('/myapp/config/all') |
| 33 | + return response |
| 34 | +end |
| 35 | + |
| 36 | +function get_config_by_prefix() |
| 37 | + -- Connect to a config.storage and get values with a /myapp/ prefix. |
| 38 | + local storage_client = config.storage_client.connect({ |
| 39 | + '127.0.0.1:4401', |
| 40 | + '127.0.0.1:4402', |
| 41 | + '127.0.0.1:4403', |
| 42 | + }) |
| 43 | + local response = storage_client:get('/myapp/') |
| 44 | + |
| 45 | + -- Get values prefixed /myapp/ from a configured config.storage cluster. |
| 46 | + response = config.storage_client:get('/myapp/') |
| 47 | + return response |
| 48 | +end |
| 49 | + |
| 50 | +function make_txn_request() |
| 51 | + -- Connect to a config.storage and execute an atomic request. |
| 52 | + local storage_client = config.storage_client.connect({ |
| 53 | + '127.0.0.1:4401', |
| 54 | + '127.0.0.1:4402', |
| 55 | + '127.0.0.1:4403', |
| 56 | + }) |
| 57 | + local response = storage_client:txn({ |
| 58 | + predicates = { { 'value', '==', 'v0', '/myapp/config/all' } }, |
| 59 | + on_success = { { 'put', '/myapp/config/all', 'v1' } }, |
| 60 | + on_failure = { { 'get', '/myapp/config/all' } } |
| 61 | + }) |
| 62 | + |
| 63 | + -- Execute an atomic request on a configured config.storage cluster. |
| 64 | + response = config.storage_client:txn({ |
| 65 | + predicates = { { 'value', '==', 'v0', '/myapp/config/all' } }, |
| 66 | + on_success = { { 'put', '/myapp/config/all', 'v1' } }, |
| 67 | + on_failure = { { 'get', '/myapp/config/all' } } |
| 68 | + }) |
| 69 | + |
| 70 | + |
| 71 | + -- end-marker -- |
| 72 | + |
| 73 | + return response |
| 74 | +end |
| 75 | + |
| 76 | +function delete_config() |
| 77 | + -- Connect to a config.storage and delete a key. |
| 78 | + local storage_client = config.storage_client.connect({ |
| 79 | + '127.0.0.1:4401', |
| 80 | + '127.0.0.1:4402', |
| 81 | + '127.0.0.1:4403', |
| 82 | + }) |
| 83 | + local response = storage_client:delete('/myapp/config/all') |
| 84 | + |
| 85 | + -- Delete a key on a configured config.storage cluster. |
| 86 | + response = config.storage_client:delete('/myapp/config/all') |
| 87 | + |
| 88 | + return response |
| 89 | +end |
| 90 | + |
| 91 | +function delete_all_configs() |
| 92 | + -- Connect to a config.storage and delete all keys. |
| 93 | + local storage_client = config.storage_client.connect({ |
| 94 | + '127.0.0.1:4401', |
| 95 | + '127.0.0.1:4402', |
| 96 | + '127.0.0.1:4403', |
| 97 | + }) |
| 98 | + local response = storage_client:delete('/') |
| 99 | + |
| 100 | + -- Delete all keys from a configured config.storage cluster. |
| 101 | + response = config.storage_client:delete('/') |
| 102 | + return response |
| 103 | +end |
0 commit comments