### Install and Start Memcached Source: https://context7.com/memcached/memcached.github.io/llms.txt Install Memcached using OS package managers or build from source. Start the server with memory limits, listen address, port, and thread count. Optionally disable UDP for security. ```bash # Debian/Ubuntu apt-get install memcached # Redhat/Fedora yum install memcached # macOS brew install memcached # From source (with TLS and proxy support) wget https://memcached.org/latest tar -zxf memcached-x.x.x.tar.gz cd memcached-x.x.x ./configure --prefix=/usr/local/memcached --enable-tls --enable-proxy make && make test && sudo make install # Start memcached: 64MB memory limit, localhost only, 4 threads memcached -m 64 -l 127.0.0.1 -p 11211 -t 4 # Disable UDP to prevent DDoS amplification (default in 1.5.6+) # /etc/memcached.conf -U 0 --listen 127.0.0.1 ``` -------------------------------- ### Basic Command Examples Source: https://github.com/memcached/memcached.github.io/blob/main/content/protocols/meta.md Illustrates the basic request and response structure for set, get, and delete commands in the Meta Text Protocol. ```text set request: ms foo 2 T90 F1 hi response: HD get request: mg foo t f v response: VA 2 t78 f1 hi delete request: md foo response: HD ``` -------------------------------- ### Memcached Slab Class Configuration Example Source: https://github.com/memcached/memcached.github.io/blob/main/content/serverguide/performance.md Displays the default slab class configurations when starting memcached with verbose logging. This output shows the chunk size and the number of chunks per page for each slab class, illustrating how memory is divided for different item sizes. ```bash $ ./memcached -vv slab class 1: chunk size 80 perslab 13107 slab class 2: chunk size 104 perslab 10082 slab class 3: chunk size 136 perslab 7710 slab class 4: chunk size 176 perslab 5957 slab class 5: chunk size 224 perslab 4681 slab class 6: chunk size 280 perslab 3744 slab class 7: chunk size 352 perslab 2978 slab class 8: chunk size 440 perslab 2383 slab class 9: chunk size 552 perslab 1899 slab class 10: chunk size 696 perslab 1506 [...etc...] ``` -------------------------------- ### Memcached Binary Protocol Append Example Source: https://github.com/memcached/memcached.github.io/blob/main/content/protocols/binary.md This example demonstrates the binary format for appending '!' to the key 'Hello'. It details the header fields, key, and value. ```text Byte/ 0 | 1 | 2 | 3 | / | | | | |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7| +---------------+---------------+---------------+---------------+ 0| 0x80 | 0x0e | 0x00 | 0x05 | +---------------+---------------+---------------+---------------+ 4| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 8| 0x00 | 0x00 | 0x00 | 0x06 | +---------------+---------------+---------------+---------------+ 12| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 16| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 20| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 24| 0x48 ('H') | 0x65 ('e') | 0x6c ('l') | 0x6c ('l') | +---------------+---------------+---------------+---------------+ 28| 0x6f ('o') | 0x21 ('!') | +---------------+---------------+ Total 30 bytes (24 byte header, 5 byte key, 1 byte value) Field (offset) (value) Magic (0) : 0x80 Opcode (1) : 0x0e Key length (2,3) : 0x0005 Extra length (4) : 0x00 Data type (5) : 0x00 VBucket (6,7) : 0x0000 Total body (8-11) : 0x00000006 Opaque (12-15): 0x00000000 CAS (16-23): 0x0000000000000000 Extras : None Key (24-28): The textual string "Hello" Value (29) : "!" ``` -------------------------------- ### Memcached SASL Authentication Setup Source: https://github.com/memcached/memcached.github.io/blob/main/content/releasenotes/ReleaseNotes145.md Demonstrates setting up SASL authentication for Memcached. This involves creating a configuration file, a password database, and exporting environment variables before starting the server. ```bash echo "mech_list: plain" > memcached.conf echo "myname:mypass" > /tmp/memcached-sasl-db export MEMCACHED_SASL_PWDB=/tmp/memcached-sasl-db export SASL_CONF_PATH=`pwd`/memcached.conf ./memcached -S -v ``` -------------------------------- ### Pipelining with Standard Get Source: https://github.com/memcached/memcached.github.io/blob/main/content/protocols/meta.md Demonstrates pipelining multiple 'get' commands in the standard text protocol. Responses reflect the requested key, allowing differentiation. ```text get bar foooooooooooooooooooooooooooooooo baz VALUE foooooooooooooooooooooooooooooooo 0 2 hi END ``` ```text get foooooooooooooooooooooooooooooooo VALUE foooooooooooooooooooooooooooooooo 0 2 hi END ``` -------------------------------- ### Start Memcached Servers and Proxy Source: https://context7.com/memcached/memcached.github.io/llms.txt Launches multiple Memcached backend servers and a proxy server configured with a Lua routing library. Ensure the proxy is started with the correct configuration file. ```bash ./memcached -l localhost -p 11212 & ./memcached -l localhost -p 11213 & ./memcached -l localhost -p 11214 & ./memcached -l localhost -p 11211 -o proxy_config=routelib,proxy_arg=config.lua & ``` -------------------------------- ### Install Memcached with Proxy Enabled Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/proxy/install.md Install the proxy-enabled Memcached on your system using sudo. ```bash sudo make install ``` -------------------------------- ### Basic Steps Shortcode Example Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/shortcodes/steps.md Demonstrates the basic structure of the steps shortcode with three steps. Each step is defined by an H3 header. ```go-html-template {{% steps %}} ### Step 1 This is the first step. ### Step 2 This is the second step. ### Step 3 This is the third step. {{% /steps %}} ``` -------------------------------- ### Build Memcached from Source Source: https://github.com/memcached/memcached.github.io/blob/main/content/serverguide/_index.md Steps to download, extract, configure, compile, and install Memcached from its source code. Ensure you have the necessary build dependencies installed first. ```bash wget https://memcached.org/latest [you might need to rename the file] tar -zxf memcached-x.x.x.tar.gz cd memcached-x.x.x ./configure --prefix=/usr/local/memcached make && make test && sudo make install ``` -------------------------------- ### Initialize New Hugo Site Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/getting-started.md Use this command to create a new Hugo site with YAML configuration. Ensure Hugo is installed. ```shell hugo new site my-site --format=yaml ``` -------------------------------- ### Verify Proxy Feature Installation Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/proxy/install.md Confirm that Memcached has been installed with proxy features enabled by checking its help output. ```bash memcached --help | grep proxy ``` -------------------------------- ### Binary Encoded Keys Example Source: https://github.com/memcached/memcached.github.io/blob/main/content/protocols/meta.md Demonstrates storing and retrieving items with non-ASCII keys by BASE64 encoding them. The example uses Japanese characters for the key. ```text ms 44OG44K544OI 2 b hi mg 44OG44K544OI b v k VA 2 k44OG44K544OI b hi ``` -------------------------------- ### Memcached Binary Protocol: incr Command Example Source: https://github.com/memcached/memcached.github.io/blob/main/content/protocols/binary.md Shows the binary representation of an incr command for a key 'counter' with a delta of 1 and an initial value of 0, expiring in two hours. This example details the header, extras, key, and total byte count. ```text Byte/ 0 | 1 | 2 | 3 | / | | | | |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7| +---------------+---------------+---------------+---------------+ 0| 0x80 | 0x05 | 0x00 | 0x07 | +---------------+---------------+---------------+---------------+ 4| 0x14 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 8| 0x00 | 0x00 | 0x00 | 0x1b | +---------------+---------------+---------------+---------------+ 12| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 16| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 20| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 24| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 28| 0x00 | 0x00 | 0x00 | 0x01 | +---------------+---------------+---------------+---------------+ 32| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 36| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 40| 0x00 | 0x00 | 0x1c | 0x20 | +---------------+---------------+---------------+---------------+ 44| 0x63 ('c') | 0x6f ('o') | 0x75 ('u') | 0x6e ('n') | +---------------+---------------+---------------+---------------+ 48| 0x74 ('t') | 0x65 ('e') | 0x72 ('r') | +---------------+---------------+---------------+ Total 51 bytes (24 byte header, 20 byte extras, 7 byte key) Field (offset) (value) Magic (0) : 0x80 Opcode (1) : 0x05 Key length (2,3) : 0x0007 Extra length (4) : 0x14 Data type (5) : 0x00 VBucket (6,7) : 0x0000 Total body (8-11) : 0x0000001b Opaque (12-15): 0x00000000 CAS (16-23): 0x0000000000000000 Extras : delta (24-31): 0x0000000000000001 initial (32-39): 0x0000000000000000 expiration (40-43): 0x00001c20 Key : Textual string "counter" Value : None ``` -------------------------------- ### Install Build Dependencies on Redhat/Fedora Source: https://github.com/memcached/memcached.github.io/blob/main/content/serverguide/_index.md Install necessary packages for building Memcached from source on Redhat-based systems. This includes libevent development files. ```bash yum install libevent-devel ``` -------------------------------- ### Basic Cards Example Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/shortcodes/cards.md Demonstrates the basic usage of the cards shortcode with different card configurations, including icons and tags. ```html {{< cards >}} {{< card link="../callout" title="Callout" icon="warning" >}} {{< card link="../callout" title="Card with tag" icon="tag" tag="custom tag" >}} {{< card link="/" title="No Icon" >}} {{< /cards >}} ``` ```html {{< cards >}} {{< card link="/" title="Image Card" image="https://github.com/user-attachments/assets/71b7e3ec-1a8d-4582-b600-5425c6cc0407" subtitle="Internet Image" >}} {{< card link="/" title="Local Image" image="/images/card-image-unprocessed.jpg" subtitle="Raw image under static directory." >}} {{< card link="/" title="Local Image" image="images/space.jpg" subtitle="Image under assets directory, Hugo processed." method="Resize" options="600x q80 webp" >}} {{< /cards >}} ``` -------------------------------- ### Memcached Binary Protocol Example Source: https://github.com/memcached/memcached.github.io/blob/main/content/protocols/binary.md Illustrates the structure of a Memcached binary protocol request, showing extras, key, and value. ```text Extras : None Key : None Value : 0x0000000000000000 ``` -------------------------------- ### Build and Test Memcached Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/proxy/quickstart.md Compile Memcached from source and run its test suite. Ensure development packages are installed if errors occur. ```bash make make test ``` -------------------------------- ### Memcached Binary Protocol: incr Response Example (Key Not Found) Source: https://github.com/memcached/memcached.github.io/blob/main/content/protocols/binary.md Illustrates the binary response from Memcached when an incr command is issued for a key that does not exist. The response includes the initial value as specified in the command. This example shows the header and value structure. ```text Byte/ 0 | 1 | 2 | 3 | / | | | | |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7| +---------------+---------------+---------------+---------------+ 0| 0x81 | 0x05 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 4| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 8| 0x00 | 0x00 | 0x00 | 0x08 | +---------------+---------------+---------------+---------------+ 12| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 16| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 20| 0x00 | 0x00 | 0x00 | 0x05 | +---------------+---------------+---------------+---------------+ 24| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ 28| 0x00 | 0x00 | 0x00 | 0x00 | +---------------+---------------+---------------+---------------+ Total 32 bytes (24 byte header, 8 byte value) Field (offset) (value) Magic (0) : 0x81 Opcode (1) : 0x05 Key length (2,3) : 0x0000 Extra length (4) : 0x00 Data type (5) : 0x00 Status (6,7) : 0x0000 Total body (8-11) : 0x00000008 Opaque (12-15): 0x00000000 CAS (16-23): 0x0000000000000005 ``` -------------------------------- ### Start Memcached with TLS Encryption Source: https://context7.com/memcached/memcached.github.io/llms.txt Enable TLS encryption on all interfaces. Specify certificate and key paths. ```bash memcached -Z \ -o ssl_chain_cert=/etc/memcached/cert.pem \ -o ssl_key=/etc/memcached/key.pem ``` -------------------------------- ### Usage Example - Basic Details Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/shortcodes/details.md This markdown demonstrates the basic usage of the details shortcode, including its title and content. ```markdown {{%/* details title="Details" */%}} This is the content of the details. Markdown is **supported**. {{%/* /details */%}} ``` -------------------------------- ### Launch Memcached in Proxy Mode Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/proxy/quickstart.md Start a third Memcached server in proxy mode, pointing to the generated Lua configuration file. ```bash ./memcached -l localhost -p 11211 -o proxy_config=routelib,proxy_arg=config.lua & ``` -------------------------------- ### Full Example Memcached Proxy Configuration Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/proxy/configure.md Demonstrates a comprehensive configuration file including verbose mode, overridden settings, multiple backend pools, and defined routes with a default catch-all. Use this as a template for your own configurations. ```lua -- Turn on the route library's verbose mode. verbose(true) -- Override a handful of default settings for proxy behavior. settings { backend_connect_timeout = 3, pool_options = { filter = "tags", filter_conf = "{}" } } -- Define two backend pools of Memcached servers. Each pool has three nodes. pools { main_pool = { backend_options = { connecttimeout = 5 }, backends = { "192.0.2.1", "192.0.2.2", "192.0.2.3:11212", } }, customer_pool = { backends = { "203.0.113.1", "203.0.113.10", { host = "203.0.113.20", port = 11212, connecttimeout = 10 }, }, }, } -- Define two routes, each of which maps to one of the pools defined earliers. -- And then define a default catch-all route. routes { map = { -- Handle keys that start with "main/" main = route_direct { child = "main_pool", }, cust = cmdmap{ -- Handle only SET commands for keys with the prefix with "cust" set = route_direct { child = "customer_pool", }, }, }, -- Handle keys that don't have a mapped prefix. default = route_direct { child = "main_pool" }, } ``` -------------------------------- ### SASL Authentication (Binary Protocol) Source: https://context7.com/memcached/memcached.github.io/llms.txt Guides on configuring and using SASL authentication with the Memcached binary protocol, including server setup, user creation, and the specific binary opcodes for SASL operations. ```APIDOC ## SASL Authentication (Binary Protocol) SASL provides client authentication (not encryption) using the binary protocol. Requires memcached built with `--enable-sasl` and a SASL password database. Enable with `-S` on the server; this forces binary protocol and requires authentication before any command. ### Configuration and Usage 1. **Check SASL support**: ```bash memcached -h | grep sasl # -S, --enable-sasl turn on Sasl authentication ``` 2. **Create a user**: ```bash saslpasswd2 -a memcached -c cacheuser # (prompts for password) ``` 3. **Start memcached with SASL**: ```bash memcached -S -vvvv # Output: Initialized SASL. ``` 4. **Verify SASL library**: ```bash ldd $(which memcached) | grep -i sasl # libsasl2.so.3 => /lib64/libsasl2.so.3 ``` ### SASL Binary Protocol Commands - **Opcode 0x20**: List Mechanisms (no key, no value) - **Opcode 0x21**: Start Auth (key=mechanism e.g. "PLAIN", value=auth data) - **Opcode 0x22**: Auth Step (key=mechanism, value=next step data) ### SASL Status Codes - **0x20**: Authentication required / not successful - **0x21**: Further authentication steps required (multi-step mechanisms) ``` -------------------------------- ### Command Map for Routing Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/proxy/examples.md Utilize command-based routing to direct specific commands to different backend pools, offering an alternative to prefix-based routing. This example routes 'get' commands to the 'foo' pool and others to the 'bar' pool. ```lua pools{ foo = { backends = { "127.0.0.1:11214", "127.0.0.1:11215", } }, bar = { backends = { "127.0.0.1:11216", } }, } outes{ cmap = { get = route_direct{ child = "foo", }, }, default = route_allfastest{ children = { "bar" } }, } ``` -------------------------------- ### Example Memcached Proxy Commands Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/proxy/run.md Demonstrates launching a Memcached proxy using the built-in routelib or a custom one, along with a configuration file and listening on a specific port. The trailing '&' runs the process in the background. ```bash # Using the builtin routelib memcached -o proxy_config=routelib,proxy_arg=$HOME/my_config.lua -p 11212 & # Manually using a modified or newer routelib memcached -o proxy_config=$HOME/routelib.lua,proxy_arg=$HOME/my_config.lua -p 11212 & ``` -------------------------------- ### Retrieval Commands: get, gets Source: https://context7.com/memcached/memcached.github.io/llms.txt Commands to retrieve data from Memcached. 'get' retrieves the value and flags, while 'gets' also returns the CAS token for use with the 'cas' command. ```APIDOC ## get [ ...] ### Description Retrieves the value and flags for one or more specified keys. ### Method GET ### Endpoint N/A (Text Protocol) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` get user:42 ``` ### Response #### Success Response (200) VALUE \r\n\r\nEND #### Response Example ``` VALUE user:42 0 15 {"name":"Carol"} END ``` ## gets [ ...] ### Description Retrieves the value, flags, and CAS token for one or more specified keys. The CAS token is used for compare-and-swap operations. ### Method GETS ### Endpoint N/A (Text Protocol) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` gets user:42 ``` ### Response #### Success Response (200) VALUE \r\n\r\nEND #### Response Example ``` VALUE user:42 0 15 99 {"name":"Carol"} END ``` ``` -------------------------------- ### Recommended Memcached Startup Options Source: https://github.com/memcached/memcached.github.io/blob/main/content/releasenotes/ReleaseNotes1429.md For optimal performance and features in Memcached 1.4.29, it is recommended to start the server with the 'modern' option. This allows for memory reassignment and improves the LRU algorithm. ```bash memcached -o modern ``` -------------------------------- ### Memcached Text Protocol: Retrieval Commands Source: https://context7.com/memcached/memcached.github.io/llms.txt Retrieve items using 'get' or 'gets'. 'get' returns the value and flags. 'gets' returns the value, flags, and a CAS token for compare-and-swap operations. ```text # get one or multiple keys get user:42 # VALUE user:42 0 15 # {"name":"Carol"} # END get user:42 user:43 session:abc # VALUE user:42 0 15 # {"name":"Carol"} # VALUE session:abc 0 5 # hello # END # (user:43 is not returned, indicating a cache miss) # gets: same as get, but includes CAS identifier gets user:42 # VALUE user:42 0 15 99 # {"name":"Carol"} # END # 99 is the CAS token for subsequent cas commands ``` -------------------------------- ### Meta Get (mg) Source: https://context7.com/memcached/memcached.github.io/llms.txt Rich item retrieval with flags. Replaces GET, GETS, TOUCH, GAT, and GATS with a single composable `mg` command. ```APIDOC ## Meta Get (mg): Rich Item Retrieval with Flags The Meta protocol replaces GET, GETS, TOUCH, GAT, and GATS with a single composable `mg` command. Flags are single characters that request specific behaviors and metadata. No separate multi-key interface exists; pipeline multiple `mg` commands instead. ### Syntax `mg [flags]\r\n` ### Response `VA [token_flags]\r\n\r\n` or `EN\r\n` (miss) or `HD\r\n` (no value) ### Examples #### Standard GET equivalent (request flags + value): ``` mg foo f v\r\n # VA 5 f30\r\n # hello\r\n ``` #### GETS equivalent (add CAS token): ``` mg foo f c v\r\n # VA 5 f30 c42\r\n # hello\r\n ``` #### TOUCH (update TTL, no value returned): ``` mg foo T90\r\n # HD\r\n ``` #### GAT (get and touch in one round-trip): ``` mg foo f v T90\r\n # VA 5 f30\r\n # hello\r\n ``` #### Request access metadata: h=was ever fetched, l=seconds since last access, t=TTL remaining ``` mg foo v h l t\r\n # VA 5 h1 l3 t87\r\n # hello\r\n ``` #### Pipeline multiple keys with quiet mode (q) and opaque token (O) to avoid key reflection overhead: ``` mg key1 v q O1\r\nmg key2 v q O2\r\nmg key3 v q O3\r\nmn\r\n # VA 5 O1\r\nhello\r\n # VA 3 O3\r\nfoo\r\n # MN\r\n # (key2 was a miss; suppressed by q flag. MN marks end of pipeline) ``` ``` -------------------------------- ### Start Memcached Server with TLS Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/tls.md Enable TLS and specify certificate and key paths for the memcached server. Use `-Z` for TLS and `ssl_chain_cert` and `ssl_key` for file paths. ```bash memcached -Z -o ssl_chain_cert=/home/user/cert,ssl_key=/home/user/key ``` -------------------------------- ### Meta Get (mg): Rich Item Retrieval Source: https://context7.com/memcached/memcached.github.io/llms.txt Replaces GET, GETS, TOUCH, GAT, GATS. Use flags for specific behaviors and metadata. Pipeline multiple commands for efficiency. ```bash # Syntax: mg [flags]\r\n # Response: VA [token_flags]\r\n\r\n or EN\r\n (miss) or HD\r\n (no value) # Standard GET equivalent (request flags + value): mg foo f v\r\n # VA 5 f30\r\n # hello\r\n # GETS equivalent (add CAS token): mg foo f c v\r\n # VA 5 f30 c42\r\n # hello\r\n # TOUCH (update TTL, no value returned): mg foo T90\r\n # HD\r\n # GAT (get and touch in one round-trip): mg foo f v T90\r\n # VA 5 f30\r\n # hello\r\n # Request access metadata: h=was ever fetched, l=seconds since last access, t=TTL remaining mg foo v h l t\r\n # VA 5 h1 l3 t87\r\n # hello\r\n # Pipeline multiple keys with quiet mode (q) and opaque token (O) to avoid key reflection overhead: mg key1 v q O1\r\nmg key2 v q O2\r\nmg key3 v q O3\r\nmn\r\n # VA 5 O1\r\nhello\r\n # VA 3 O3\r\nfoo\r\n # MN\r\n # (key2 was a miss; suppressed by q flag. MN marks end of pipeline) ``` -------------------------------- ### FileTree Component Example Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/shortcodes/filetree.md Demonstrates how to use the FileTree component to display a directory structure. Use this to visualize file hierarchies within your documentation. ```html {{< filetree/container >}} {{< filetree/folder name="content" >}} {{< filetree/file name="_index.md" >}} {{< filetree/folder name="docs" state="closed" >}} {{< filetree/file name="_index.md" >}} {{< filetree/file name="introduction.md" >}} {{< filetree/file name="introduction.fr.md" >}} {{< /filetree/folder >}} {{< /filetree/folder >}} {{< filetree/file name="hugo.toml" >}} {{< /filetree/container >}} ``` -------------------------------- ### Avoid N+1 Memcached Gets with Pipelined Gets Source: https://github.com/memcached/memcached.github.io/blob/main/content/userguide/faq.md This code demonstrates an anti-pattern of fetching individual items from Memcached in a loop. Instead, use pipelined gets to reduce network roundtrips and processing overhead. Fetching multiple items at once is more efficient. ```perl my @post_ids = fetch_all_posts($thread_id); my @post_entries = () for my $post_id (@post_ids) { push(@post_entries, $memc->get($post_id)); } # Yay I have all my post entries! ``` -------------------------------- ### Create Backend Object (Short Form) Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/proxy/api-reference.md Use the short form to create a backend object with a label, host, and port. IP addresses are recommended over hostnames for performance. ```lua -- create a backend object from a short description mcp.backend(label, host|ip, port) -- label: uniquely identify this backend object so it may be reused -- host|ip: is the hostname or IP address of the server, though IP addresses are -- strongly recommended as of this writing since DNS lookups can cause -- performance issues. -- port: is the service port the server is listening on. -- The `label` of a backend gives it a unique cache id. If a backend has the -- same label and options during reload, the underlying connections are reused. ``` -------------------------------- ### Gets (Get with CAS) Source: https://github.com/memcached/memcached.github.io/blob/main/content/protocols/meta.md Shows how to retrieve an item's flags, value, and CAS value for conditional updates. ```text mg foo f c v VA 2 f30 c3 -- also gets the CAS value back hi ``` -------------------------------- ### Basic Icon Usage Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/shortcodes/icon.md Demonstrates how to use the icon shortcode with predefined icon names. Available icons are listed in `data/icons.yaml`. ```html {{< icon "academic-cap" >}} ``` ```html {{< icon "cake" >}} ``` ```html {{< icon "gift" >}} ``` ```html {{< icon "sparkles" >}} ``` -------------------------------- ### Markdown Blockquote Example Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/markdown.md Use blockquotes to emphasize quoted text. This example includes attribution and a footnote reference. ```markdown > Don't communicate by sharing memory, share memory by communicating.
> — Rob Pike[^1] [^1]: The above quote is excerpted from Rob Pike's [talk](https://www.youtube.com/watch?v=PAAkCSZUG1c) during Gopherfest, November 18, 2015. ``` -------------------------------- ### Install Memcached on Mac with Homebrew Source: https://github.com/memcached/memcached.github.io/blob/main/content/serverguide/_index.md Use brew to install Memcached on macOS. Homebrew is a popular package manager for Mac. ```bash brew install memcached ``` -------------------------------- ### Create Initial Content Pages Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/getting-started.md Generate the basic content files for your site's home and documentation sections. ```shell hugo new content/_index.md hugo new content/docs/_index.md ``` -------------------------------- ### Markdown Nested List Example Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/markdown.md Nest lists by indenting sub-items. This example shows a nested list for fruits and dairy. ```markdown * Fruit * Apple * Orange * Banana * Dairy * Milk * Cheese ``` -------------------------------- ### Initialize Memcached Client (Pseudocode) Source: https://github.com/memcached/memcached.github.io/blob/main/content/userguide/_index.md Initializes a Memcached client object with server details. Ensure this is done once per request or persisted to avoid issues. ```pseudocode # pseudocode memcli = new Memcache memcli:add_server('10.0.0.10:11211') ``` -------------------------------- ### Markdown Table Example Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/markdown.md Hugo supports tables for structured data presentation. This example shows a simple two-column table. ```markdown | Name | Age | |--------|------| | Bob | 27 | | Alice | 23 | ``` -------------------------------- ### Install Memcached on Redhat/Fedora Source: https://github.com/memcached/memcached.github.io/blob/main/content/serverguide/_index.md Use yum to install Memcached on Redhat-based systems like Fedora. This method handles dependencies automatically. ```bash yum install memcached ``` -------------------------------- ### Run Memcached Proxy with Configuration Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/proxy/run.md Launches the proxy-enabled Memcached binary with specified route library and configuration paths. Replace placeholders with your actual file paths and add any additional Memcached flags as needed. ```bash memcached -o proxy_config={{}}ROUTE_LIBRARY_PATH{{}},proxy_arg={{}}CONFIGURATION_PATH{{}} {{}}FURTHER_ARGUMENTS{{>}} ``` -------------------------------- ### Launch Backend Memcached Servers Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/proxy/quickstart.md Start two ordinary Memcached servers on specified ports (11212 and 11213) using the built binary. ```bash ./memcached -l localhost -p 11212 & ./memcached -l localhost -p 11213 & ``` -------------------------------- ### Install Memcached on Debian/Ubuntu Source: https://github.com/memcached/memcached.github.io/blob/main/content/serverguide/_index.md Use apt-get to install Memcached on Debian-based systems like Ubuntu. This method handles dependencies automatically. ```bash apt-get install memcached ``` -------------------------------- ### Markdown Image with Caption Example Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/markdown.md Add a title attribute to an image for a tooltip or caption. This example includes a caption for the landscape image. ```markdown ![landscape](https://picsum.photos/800/600 "Unsplash Landscape") ``` -------------------------------- ### Get with Flags and Value Source: https://github.com/memcached/memcached.github.io/blob/main/content/protocols/meta.md Demonstrates fetching an item's flags and value using the 'mg' command. Add 'k' to retrieve the key as well. ```text mg foo f v -- ask for client flags, value VA 2 f30 -- get length, client flags, value hi ``` -------------------------------- ### Markdown Image Example Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/markdown.md Embed images using the `![alt text](url)` syntax. This example shows a basic landscape image. ```markdown ![landscape](https://picsum.photos/800/600) ``` -------------------------------- ### Markdown Unordered List Example Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/markdown.md Create unordered lists using asterisks, hyphens, or plus signs. This example uses asterisks. ```markdown * List item * Another item * And another item ``` -------------------------------- ### Add Hextra Theme via Hugo Modules Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/getting-started.md Initialize Hugo modules and add the Hextra theme. This is the recommended method for managing themes. Requires Git and Go. ```shell # initialize hugo module cd my-site hugo mod init github.com/username/my-site # add Hextra theme hugo mod get github.com/imfing/hextra ``` -------------------------------- ### Preview Site Locally Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/getting-started.md Start a local Hugo development server to preview your site. The `--buildDrafts` flag includes draft content, and `--disableFastRender` ensures a full rebuild. ```shell hugo server --buildDrafts --disableFastRender ``` -------------------------------- ### Gutter Example Configuration Source: https://github.com/memcached/memcached.github.io/blob/main/content/features/proxy/examples.md Defines backend server lists and routing rules for failover. It includes a 'main' pool, a dedicated 'gutter' pool, and an alternative 'gutter_same' pool that reuses main backends with a different key hashing seed. This configuration is used to reroute requests from failed servers to a backup. ```lua local be_list = { "127.0.0.1:11214", "127.0.0.1:11215", "127.0.0.1:11216", } pools{ main = { backends = be_list, }, -- for one example, we use a dedicated gutter pool. This server will be -- idle unless another server has failed or is being serviced. gutter = { backends = { "127.1.0.0.1:11311" } }, -- in this example, we reuse the main set of backends, but change the key -- hashing seed so keys will map to the list of backends differently. This -- can minimize server maintenance while avoiding having idle "gutter" -- servers. -- The downside is keys may map to the same place, especially if you have -- a small list of backends. This can be partly mitigated by having -- multiple gutters with different seeds and failing several times. -- There may still be keys that fail but they will hopefully be few and -- the service can survive until the cache node is restored. -- -- To use this, replace "gutter" below with "gutter_same" gutter_same = { options = { seed = "failover" }, backends = be_list, }, } routes{ cmap = { set = route_failover{ children = { "main", route_ttl{ ttl = 300, child = "gutter" } }, stats = true, miss = false, -- do not fail over on miss, only errors! -- do not shuffle the pool list, either! }, -- repeat this for add, cas, ms, as necessary }, -- we handle the rest of the commands with a default failover to gutter. default = route_failover{ children = { "main", "gutter" }, }, } ``` -------------------------------- ### Markdown Ordered List Example Source: https://github.com/memcached/memcached.github.io/blob/main/themes/hextra/exampleSite/content/docs/guide/markdown.md Create ordered lists using numbers followed by periods. This example shows a basic three-item list. ```markdown 1. First item 2. Second item 3. Third item ``` -------------------------------- ### Tune Extstore Parameters Source: https://context7.com/memcached/memcached.github.io/llms.txt Configure various Extstore tuning options, including item size, page size, write buffer size, IO threads, TTL, fragmentation, and compaction behavior. ```bash memcached -m 4096 \ -o ext_path=/data/extstore:100G \ -o ext_item_size=1024 \ -o ext_page_size=64 \ -o ext_wbuf_size=8 \ -o ext_threads=2 \ -o ext_low_ttl=2400 \ -o ext_max_frag=0.5 \ -o ext_drop_unread=true \ -o ext_recache_rate=2000 ``` -------------------------------- ### Install Build Dependencies on Debian/Ubuntu Source: https://github.com/memcached/memcached.github.io/blob/main/content/serverguide/_index.md Install necessary packages for building Memcached from source on Debian-based systems. This includes build tools and libevent development files. ```bash apt-get install build-essential libevent-dev ``` -------------------------------- ### Select Hash Algorithm at Starttime Source: https://github.com/memcached/memcached.github.io/blob/main/content/releasenotes/ReleaseNotes1418.md Specify a hash algorithm when starting Memcached. Murmur3 is initially added and may offer performance improvements. ```bash -o hash_algorithm=murmur3 ```