| 1 |
|
%% Copyright (c) 2022 Peter Morgan <peter.james.morgan@gmail.com> |
| 2 |
|
%% |
| 3 |
|
%% Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
|
%% you may not use this file except in compliance with the License. |
| 5 |
|
%% You may obtain a copy of the License at |
| 6 |
|
%% |
| 7 |
|
%% http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
|
%% |
| 9 |
|
%% Unless required by applicable law or agreed to in writing, software |
| 10 |
|
%% distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
|
%% See the License for the specific language governing permissions and |
| 13 |
|
%% limitations under the License. |
| 14 |
|
|
| 15 |
|
|
| 16 |
|
-module(mcd). |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
-export([priv_consult/1]). |
| 20 |
|
-export([priv_dir/0]). |
| 21 |
|
-export([start/0]). |
| 22 |
|
-export_type([int16/0]). |
| 23 |
|
-export_type([int32/0]). |
| 24 |
|
-export_type([int64/0]). |
| 25 |
|
-export_type([int8/0]). |
| 26 |
|
-export_type([protocol/0]). |
| 27 |
|
-export_type([uint16/0]). |
| 28 |
|
-export_type([uint32/0]). |
| 29 |
|
-export_type([uint64/0]). |
| 30 |
|
-export_type([uint8/0]). |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
-type int16() :: -32_768..32_767. |
| 34 |
|
-type int32() :: -2_147_483_648..2_147_483_647. |
| 35 |
|
-type int64() :: -9_223_372_036_854_775_808..9_223_372_036_854_775_807. |
| 36 |
|
-type int8() :: -128..127. |
| 37 |
|
-type uint16() :: 0..65_535. |
| 38 |
|
-type uint32() :: 0..4_294_967_295. |
| 39 |
|
-type uint64() :: 0..18_446_744_073_709_551_615. |
| 40 |
|
-type uint8() :: 0..255. |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
-type protocol() :: text_protocol() |
| 44 |
|
| meta_protocol() |
| 45 |
|
| binary_protocol(). |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
-type text_protocol() :: #{command := text_command()}. |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
-type text_command() :: set |
| 52 |
|
| add |
| 53 |
|
| get |
| 54 |
|
| replace |
| 55 |
|
| append |
| 56 |
|
| prepend. |
| 57 |
|
|
| 58 |
|
-type meta_command() :: mg |
| 59 |
|
| ms |
| 60 |
|
| md. |
| 61 |
|
|
| 62 |
|
-type meta_protocol() :: #{meta := meta_command(), |
| 63 |
|
key := binary(), |
| 64 |
|
flags := [meta_flag()]}. |
| 65 |
|
|
| 66 |
|
-type meta_flag() :: base64 |
| 67 |
|
| cas |
| 68 |
|
| {cas, uint32()} |
| 69 |
|
| flags |
| 70 |
|
| {flags, uint32()} |
| 71 |
|
| hit |
| 72 |
|
| invalidate |
| 73 |
|
| key_as_token |
| 74 |
|
| last_accessed |
| 75 |
|
| {mode, binary()} |
| 76 |
|
| {vivify, uint32()} |
| 77 |
|
| {opaque, binary()} |
| 78 |
|
| noreply |
| 79 |
|
| {remaining, uint32()} |
| 80 |
|
| size |
| 81 |
|
| ttl |
| 82 |
|
| {ttl, uint32()} |
| 83 |
|
| dont_bump_lru |
| 84 |
|
| value. |
| 85 |
|
|
| 86 |
|
-type binary_protocol() :: #{header := binary_header(), |
| 87 |
|
extra => any(), |
| 88 |
|
key => binary(), |
| 89 |
|
value => binary()}. |
| 90 |
|
|
| 91 |
|
-type binary_header() :: binary_request_header() |
| 92 |
|
| binary_response_header(). |
| 93 |
|
|
| 94 |
|
-type binary_request_header() :: #{magic := binary_magic(), |
| 95 |
|
opcode := binary_opcode(), |
| 96 |
|
data_type := binary_data_type(), |
| 97 |
|
vbucket_id := uint32(), |
| 98 |
|
opaque := uint32(), |
| 99 |
|
cas := uint32()}. |
| 100 |
|
|
| 101 |
|
-type binary_response_header() :: #{magic := binary_magic(), |
| 102 |
|
opcode := binary_opcode(), |
| 103 |
|
data_type := binary_data_type(), |
| 104 |
|
status := binary_status(), |
| 105 |
|
opaque := uint32(), |
| 106 |
|
cas := uint32()}. |
| 107 |
|
|
| 108 |
|
-type binary_magic() :: request | response. |
| 109 |
|
|
| 110 |
|
-type binary_data_type() :: raw. |
| 111 |
|
|
| 112 |
|
-type binary_opcode() :: get |
| 113 |
|
| set |
| 114 |
|
| add |
| 115 |
|
| replace |
| 116 |
|
| delete |
| 117 |
|
| increment |
| 118 |
|
| decrement |
| 119 |
|
| quit |
| 120 |
|
| flush |
| 121 |
|
| getq |
| 122 |
|
| no_op |
| 123 |
|
| version |
| 124 |
|
| getk |
| 125 |
|
| getkq |
| 126 |
|
| append |
| 127 |
|
| prepend |
| 128 |
|
| stat |
| 129 |
|
| setq |
| 130 |
|
| addq |
| 131 |
|
| replaceq |
| 132 |
|
| deleteq |
| 133 |
|
| incrementq |
| 134 |
|
| decrementq |
| 135 |
|
| quitq |
| 136 |
|
| flushq |
| 137 |
|
| appendq |
| 138 |
|
| prependq |
| 139 |
|
| verbosity |
| 140 |
|
| touch |
| 141 |
|
| gat |
| 142 |
|
| gatq |
| 143 |
|
| sasl_list_mechs |
| 144 |
|
| sasl_auth |
| 145 |
|
| sasl_step |
| 146 |
|
| rget |
| 147 |
|
| rset |
| 148 |
|
| rsetq |
| 149 |
|
| rappend |
| 150 |
|
| rappendq |
| 151 |
|
| rprepend |
| 152 |
|
| rprependq |
| 153 |
|
| rdelete |
| 154 |
|
| rdeleteq |
| 155 |
|
| rincr |
| 156 |
|
| rincrq |
| 157 |
|
| rdecr |
| 158 |
|
| rdecrq |
| 159 |
|
| set_vbucket |
| 160 |
|
| get_vbucket |
| 161 |
|
| del_vbucket |
| 162 |
|
| tap_connect |
| 163 |
|
| tap_mutation |
| 164 |
|
| tap_delete |
| 165 |
|
| tap_flush |
| 166 |
|
| tap_opaque |
| 167 |
|
| tap_vbucket_set |
| 168 |
|
| tap_checkpoint_start |
| 169 |
|
| tap_checkpoint_end. |
| 170 |
|
|
| 171 |
|
-type binary_status() :: no_error |
| 172 |
|
| key_not_found |
| 173 |
|
| key_exists |
| 174 |
|
| value_too_large |
| 175 |
|
| invalid_arguments |
| 176 |
|
| item_not_stored |
| 177 |
|
| incrdecr_on_nonnumeric_value |
| 178 |
|
| the_vbucket_belongs_to_another_server |
| 179 |
|
| authentication_error |
| 180 |
|
| authentication_continue |
| 181 |
|
| unknown_command |
| 182 |
|
| out_of_memory |
| 183 |
|
| not_supported |
| 184 |
|
| internal_error |
| 185 |
|
| busy |
| 186 |
|
| temporary_failure. |
| 187 |
|
|
| 188 |
|
|
| 189 |
|
start() -> |
| 190 |
11 |
application:ensure_all_started(?MODULE). |
| 191 |
|
|
| 192 |
|
|
| 193 |
|
priv_dir() -> |
| 194 |
26 |
code:priv_dir(?MODULE). |
| 195 |
|
|
| 196 |
|
|
| 197 |
|
priv_consult(Filename) -> |
| 198 |
26 |
phrase_file:consult(filename:join(priv_dir(), Filename)). |