### Set Up Cluster with Primary and Replicas Source: https://microsoft.github.io/garnet/docs/cluster/replication Commands to set up a cluster with one primary and two replicas. It includes getting the primary's ID, assigning slots, setting config epochs, meeting nodes, and replicating the primary. The output shows the cluster nodes state after setup. ```powershell PS C:\Dev> redis-cli -h 192.168.1.26 -p 7000 cluster myid "15373cf386c5090a5f8a25f819c96b04a756381c" PS C:\Dev> redis-cli -h 192.168.1.26 -p 7000 cluster addslotsrange 0 16383 OK PS C:\Dev> redis-cli -h 192.168.1.26 -p 7000 cluster set-config-epoch 1 OK PS C:\Dev> redis-cli -h 192.168.1.26 -p 7001 cluster set-config-epoch 2 OK PS C:\Dev> redis-cli -h 192.168.1.26 -p 7002 cluster set-config-epoch 3 OK PS C:\Dev> redis-cli -h 192.168.1.26 -p 7000 cluster meet 192.168.1.26 7001 OK PS C:\Dev> redis-cli -h 192.168.1.26 -p 7000 cluster meet 192.168.1.26 7002 OK PS C:\Dev> redis-cli -h 192.168.1.26 -p 7001 cluster replicate 15373cf386c5090a5f8a25f819c96b04a756381c OK PS C:\Dev> redis-cli -h 192.168.1.26 -p 7002 cluster replicate 15373cf386c5090a5f8a25f819c96b04a756381c OK PS C:\Dev> redis-cli -h 192.168.1.26 -p 7000 cluster nodes 15373cf386c5090a5f8a25f819c96b04a756381c 192.168.1.26:7000@17000,DESKTOP-BT8KHK1 myself,master - 0 0 1 connected 0-16383 5868649e4205bf6ea97e4b7a12f101c3aed96b71 192.168.1.26:7001@17001,DESKTOP-BT8KHK1 slave 15373cf386c5090a5f8a25f819c96b04a756381c 0 0 4 connected 947692ec7fb4a919ae7d0d7e314e9dcbcbd99774 192.168.1.26:7002@17002,DESKTOP-BT8KHK1 slave 15373cf386c5090a5f8a25f819c96b04a756381c 0 0 5 connected PS C:\Dev> redis-cli -h 192.168.1.26 -p 7002 cluster nodes 947692ec7fb4a919ae7d0d7e314e9dcbcbd99774 192.168.1.26:7002@17002,DESKTOP-BT8KHK1 myself,slave 15373cf386c5090a5f8a25f819c96b04a756381c 0 0 5 connected 15373cf386c5090a5f8a25f819c96b04a756381c 192.168.1.26:7000@17000,DESKTOP-BT8KHK1 master - 0 0 1 connected 0-16383 5868649e4205bf6ea97e4b7a12f101c3aed96b71 192.168.1.26:7001@17001,DESKTOP-BT8KHK1 slave 15373cf386c5090a5f8a25f819c96b04a756381c 0 0 4 connected 947692ec7fb4a919ae7d0d7e314e9dcbcbd99774 192.168.1.26:7002@17002,DESKTOP-BT8KHK1 myself,slave 15373cf386c5090a5f8a25f819c96b04a756381c 0 0 5 connected ``` -------------------------------- ### RI.SET Examples Source: https://microsoft.github.io/garnet/docs/commands/range-index Examples of inserting entries into the Range Index. ```text RI.SET myindex "user:1001" "Alice" RI.SET myindex "emp:042" "Bob,Engineering,L5" ``` -------------------------------- ### Install OpenSSL on Linux Source: https://microsoft.github.io/garnet/docs/security Install the openssl library on Linux distributions using apt. ```bash sudo apt install openssl ``` -------------------------------- ### VEMB example Source: https://microsoft.github.io/garnet/docs/commands/vector-sets Example of retrieving a vector, showing the array of bulk strings. ```bash > VEMB movies dune 1) "0.12" 2) "0.34" 3) "0.56" ... ``` -------------------------------- ### RI.CREATE Examples Source: https://microsoft.github.io/garnet/docs/commands/range-index Three examples of creating a Range Index with different configurations: DISK with cache size and max key length, MEMORY with cache size and record size limits, and DISK with defaults. ```plaintext RI.CREATE myindex DISK CACHESIZE 67108864 MAXKEYLEN 64 RI.CREATE myindex MEMORY CACHESIZE 16777216 MINRECORD 8 MAXRECORD 4096 RI.CREATE myindex DISK ``` -------------------------------- ### RI.GET Example Source: https://microsoft.github.io/garnet/docs/commands/range-index Example of reading a single field from the Range Index. ```text RI.GET myindex "user:1001" ``` -------------------------------- ### Install and run Garnet .NET tool Source: https://microsoft.github.io/garnet/docs/welcome/releases Install Garnet as a global .NET tool and run the server. The commands are prefixed with '>' as shown in the documentation. ```bash > dotnet tool install --global garnet-server > > garnet-server ``` -------------------------------- ### Install Redis CLI on Linux Source: https://microsoft.github.io/garnet/docs/azure/quickstart Installs the Redis CLI on a Linux machine. ```bash sudo apt-get install redis-tools ``` -------------------------------- ### Start Garnet server with NoAuth Source: https://microsoft.github.io/garnet/docs/security Starts a Garnet server with no authentication, the default mode. Accepts any and all connections without requiring credentials. ```bash GarnetServer --auth NoAuth ``` -------------------------------- ### VGETATTR example Source: https://microsoft.github.io/garnet/docs/commands/vector-sets Example of retrieving an attribute, showing the raw attribute bytes as a bulk string. ```bash > VGETATTR movies inception "{\"year\":2010,\"rating\":4.2}" ``` -------------------------------- ### RI.CONFIG Example Response Source: https://microsoft.github.io/garnet/docs/commands/range-index Example array reply from RI.CONFIG showing alternating field-name and value pairs. ```plaintext 1) "storage_backend" 2) "DISK" 3) "cache_size" 4) "67108864" 5) "min_record_size" 6) "8" 7) "max_record_size" 8) "4096" 9) "max_key_len" 10) "64" 11) "leaf_page_size" 12) "4096" ``` -------------------------------- ### JSON.GET examples Source: https://microsoft.github.io/garnet/docs/commands/json Examples for JSON.GET: storing a complex JSON document with JSON.SET, retrieving the entire document with pretty printing, fetching multiple paths, and filtering array elements. Outputs are shown after each command. ```plaintext # Store a complex JSON object JSON.SET example $ '{"name":"John","address":{"city":"London","postal":"SW1A"},"contacts":[{"type":"email","value":"john@example.com"},{"type":"phone","value":"123-456-789"}]}' # Get entire document with pretty printing JSON.GET example . INDENT " " NEWLINE "\n" -> {"name":"John","address":{"city":"London","postal":"SW1A"},"contacts":[{"type":"email","value":"john@example.com"},{"type":"phone","value":"123-456-789"}]} # Get multiple specific paths JSON.GET example .name .address.city .contacts[0].value -> ["John","London","john@example.com"] # Get array elements with filter JSON.GET example .contacts[?(@.type=="email")].value -> ["john@example.com"] ``` -------------------------------- ### Start Garnet server with Password auth Source: https://microsoft.github.io/garnet/docs/security Starts a Garnet server with password authentication. Clients must use the AUTH command with the specified password before sending requests. ```bash GarnetServer --auth Password --password ``` -------------------------------- ### Run GET benchmark in online mode Source: https://microsoft.github.io/garnet/docs/benchmarking/resp-bench Executes the GET command in online mode with the Resp Benchmark tool. Uses GarnetClientSession client, 64 threads, and sets operation percentage to 100. Requires prior MSET preloading. ```bash dotnet run -c Release -f net10.0 -- --op-workload GET --online -b 1 --op-percent 100 -t 64 --client GarnetClientSession --itp 1024 --runtime -1 --dbsize 16777216 --keylength 512 ``` -------------------------------- ### Offline benchmark with GET Source: https://microsoft.github.io/garnet/docs/benchmarking/resp-bench Runs an offline benchmark using the GET command with multiple thread counts and a large database size. ```bash dotnet run -c Release -f net10.0 -- --op GET -t 2,4,8,16 -b 512 --dbsize 10241024 --keylength 1024 ``` -------------------------------- ### Run Resp.benchmark with --help Source: https://microsoft.github.io/garnet/docs/benchmarking/resp-bench Shows how to run the benchmark tool to see available options. Use the --help command line switch to display usage information. ```text > cd Garnet\benchmark\Resp.benchmark > dotnet run -c Release -f net10.0 -- --help ``` -------------------------------- ### XML Documentation Comment Example for DbScan Method Source: https://microsoft.github.io/garnet/docs/dev/onboarding Example of a method summary block comment with parameter descriptions, following the style guide. The method signature is for DbScan in the Garnet store. ```csharp /// /// Iterates the set of keys in the store. /// /// The pattern to apply for filtering /// When true the filter is omitted /// The value of the cursor in the command request /// Value of the cursor returned /// The list of keys from the stores /// The size of the batch of keys /// Type of key to filter out /// public bool DbScan(PinnedSpanByte patternB, bool allKeys, long cursor, out long storeCursor, out List Keys, long count = 10, ReadOnlySpan type = default); ``` -------------------------------- ### WATCH_TXN transaction script example Source: https://microsoft.github.io/garnet/docs/dev/transactions Example of a WATCH_TXN transaction: watches two keys, then executes a MULTI block with GET and SET commands. This demonstrates the optimistic locking pattern used by the WATCH_TXN workload. ```text readPerTxn = 2 writePerTxn = 2 WATCH x1 WATCH x2 MULTI GET x1 GET x2 SET x3 v3 SET x4 v4 EXEC ``` -------------------------------- ### Comment Formatting Example Source: https://microsoft.github.io/garnet/docs/dev/onboarding Shows the required format for comments in Garnet code: a single whitespace after the // and a capital letter at the start. ```plaintext // This comment has good formatting ``` -------------------------------- ### Introduce nodes and configure replica Source: https://microsoft.github.io/garnet/docs/cluster/overview Shows how to introduce the second node to the first using CLUSTER MEET, then configure the second node as a replica of the first using CLUSTER REPLICATE with the master's ID. ```powershell PS C:\Dev> redis-cli -p 7000 cluster meet 127.0.0.1 7001 OK PS C:\Dev> redis-cli -p 7000 cluster nodes d6c7f0c2a2839efad9a6578647d6456f90845836 127.0.0.1:7000@17000,localhost myself,master - 0 0 1 connected 0-16383 c65d29d420960fe5213ccb87ce1f74d7ee6ca4f1 127.0.0.1:7001@17001,localhost master - 638875895159094739 0 2 connected PS C:\Dev> redis-cli -p 7001 cluster nodes c65d29d420960fe5213ccb87ce1f74d7ee6ca4f1 127.0.0.1:7001@17001,localhost myself,master - 0 0 2 connected d6c7f0c2a2839efad9a6578647d6456f90845836 127.0.0.1:7000@17000,localhost master - 638875895161944429 0 1 connected 0-16383 PS C:\Dev> redis-cli -p 7001 cluster replicate $(redis-cli -p 7000 cluster myid) OK PS C:\Dev> redis-cli -p 7000 cluster nodes d6c7f0c2a2839efad9a6578647d6456f90845836 127.0.0.1:7000@17000,localhost myself,master - 0 0 1 connected 0-16383 c65d29d420960fe5213ccb87ce1f74d7ee6ca4f1 127.0.0.1:7001@17001,localhost slave d6c7f0c2a2839efad9a6578647d6456f90845836 638875895309129088 638875895309125478 3 connected PS C:\Dev> redis-cli -p 7001 cluster nodes c65d29d420960fe5213ccb87ce1f74d7ee6ca4f1 127.0.0.1:7001@17001,localhost myself,slave d6c7f0c2a2839efad9a6578647d6456f90845836 0 0 3 connected d6c7f0c2a2839efad9a6578647d6456f90845836 127.0.0.1:7000@17000,localhost master - 638875895311833070 638875895311830232 1 connected 0-16383 PS C:\Dev> ``` -------------------------------- ### GET Source: https://microsoft.github.io/garnet/docs/commands/raw-string Gets the value of a string key. ```APIDOC ## GET key ### Description Gets the value of key. If the key does not exist nil is returned. ### Syntax GET key ### Parameters - **key** (string) - Required - The key to get. ### Response One of the following: - Bulk string reply: the value of the key. - Nil reply: if the key does not exist. ``` -------------------------------- ### RI.DEL Example Source: https://microsoft.github.io/garnet/docs/commands/range-index Example of deleting a field from the Range Index. ```text RI.DEL myindex "user:1001" ``` -------------------------------- ### Garnet.conf format example Source: https://microsoft.github.io/garnet/docs/getting-started/configuration Shows the general structure of a redis.conf-style configuration file, where each line is a keyword followed by arguments. ```text keyword argument1 argument2 argument3 ... argumentN ``` -------------------------------- ### HELLO command syntax Source: https://microsoft.github.io/garnet/docs/commands/generic Switches to a different protocol, optionally authenticating and setting the connection's name, or provides a contextual client report. When called with the optional protover argument, it also accepts AUTH and SETNAME options. Returns a map reply of server properties, or a simple error reply if the protover does not exist. ```plaintext HELLO [protover [AUTH username password] [SETNAME clientname]] ``` -------------------------------- ### RI.RANGE Examples Source: https://microsoft.github.io/garnet/docs/commands/range-index Examples of scanning entries within a specific range. ```text RI.RANGE myindex "user:1000" "user:2000" RI.RANGE myindex "a" "z" FIELDS KEY RI.RANGE myindex "emp:001" "emp:100" FIELDS BOTH ``` -------------------------------- ### Correct ETag Usage Example Source: https://microsoft.github.io/garnet/docs/commands/garnet-specific-commands Shows the correct way to use ETag commands on ETag-managed keys and normal commands on non-ETag keys. Mixing them results in undefined behavior. ```text # ETag keys — use only ETag commands SETWITHETAG etag:user:1 "data" # Initialize with ETag GETWITHETAG etag:user:1 # Read with ETag SETIFMATCH etag:user:1 "new" 1 # Conditional update # Non-ETag keys — use normal commands SET user:2 "data" GET user:2 APPEND user:2 " more" ``` -------------------------------- ### Run the Garnet server Source: https://microsoft.github.io/garnet/docs/dev/onboarding Starts the Garnet server with a 4 GB memory size and 64 MB index size, with trace logging enabled. ```bash cd /main/GarnetServer/ dotnet run -c Debug -f net10.0 -- --logger-level Trace -m 4g -i 64m ``` -------------------------------- ### RI.SCAN Response Example Source: https://microsoft.github.io/garnet/docs/commands/range-index Example of the array response format when using FIELDS BOTH. ```text 1) 1) "user:1000" 2) "Alice" 2) 1) "user:1001" 2) "Bob" ``` -------------------------------- ### Command line option: --loadmodulecs Source: https://microsoft.github.io/garnet/docs/extensions/module Load a module at server startup using the --loadmodulecs option. The first token is the module path, and remaining tokens are arguments. The entire specification must be wrapped in double quotes. ```bash --loadmodulecs "/path/to/MyModule.dll arg0 arg1" ``` -------------------------------- ### Range Index Example Session Source: https://microsoft.github.io/garnet/docs/commands/range-index A sequence of commands demonstrating the creation of a Range Index, setting and retrieving values, scanning, ranging, and deleting keys. ```text > RI.CREATE r1 DISK CACHESIZE 33554432 MINRECORD 8 +OK > RI.SET r1 "emp:001" "Alice,Engineering,L5" +OK > RI.SET r1 "emp:002" "Bob,Sales,L3" +OK > RI.SET r1 "emp:010" "Charlie,Engineering,L7" +OK > RI.GET r1 "emp:002" "Bob,Sales,L3" > RI.SCAN r1 "emp:001" COUNT 2 FIELDS BOTH 1) 1) "emp:001" 2) "Alice,Engineering,L5" 2) 1) "emp:002" 2) "Bob,Sales,L3" > RI.RANGE r1 "emp:001" "emp:010" FIELDS KEY 1) "emp:001" 2) "emp:002" 3) "emp:010" > RI.DEL r1 "emp:002" (integer) 1 > RI.EXISTS r1 (integer) 1 > TYPE r1 rangeindex > DEL r1 (integer) 1 > RI.EXISTS r1 (integer) 0 ``` -------------------------------- ### Install Linux dependencies for local device library Source: https://microsoft.github.io/garnet/docs/dev/onboarding Install required dependencies for running the local device library on Linux. This command installs g++, libaio-dev, uuid-dev, and libtbb-dev using apt. ```bash sudo apt install -y g++ libaio-dev uuid-dev libtbb-dev ``` -------------------------------- ### CLUSTER BANLIST Example Source: https://microsoft.github.io/garnet/docs/commands/cluster Example invocation of CLUSTER BANLIST showing the response format. ```text 127.0.0.1:7000> cluster banlist 1) "ad9e5b8bde5ffb0cf7a3372fe0345f765186983f : 57" ``` -------------------------------- ### KeyDB 6.3.4 server startup command Source: https://microsoft.github.io/garnet/docs/benchmarking/results-resp-bench Command to start KeyDB 6.3.4 with specified bind, port, and performance options. Disables persistence and enables 16 server threads with affinity. ```bash ./keydb-server \ --bind $host \ --port $port \ --logfile "" \ --protected-mode no \ --save "" \ --appendonly no \ --server-threads 16 \ --server-thread-affinity true ``` -------------------------------- ### VREM example Source: https://microsoft.github.io/garnet/docs/commands/vector-sets Example of removing an element from a Vector Set, showing the integer reply. ```bash > VREM movies inception (integer) 1 ``` -------------------------------- ### HELLO Source: https://microsoft.github.io/garnet/docs/commands/generic Switches protocol version, optionally authenticates and sets client name. ```APIDOC ## HELLO ### Description Switch to a different protocol, optionally authenticating and setting the connection's name, or provide a contextual client report. ### Syntax ``` HELLO [protover [AUTH username password] [SETNAME clientname]] ``` ### Options - `AUTH `: directly authenticate the connection in addition to switching to the specified protocol version. - `SETNAME `: equivalent to calling CLIENT SETNAME. ### Resp Reply Map reply: a list of server properties. Simple error reply: if the protover requested does not exist. ``` -------------------------------- ### Enable client-side command registration in garnet.conf Source: https://microsoft.github.io/garnet/docs/dev/custom-commands Configuration example for enabling client-side command registration. Set EnableModuleCommand to "local" and provide a list of allowed paths in ExtensionBinPaths. Assemblies can be loaded from any directory level under these paths. By default, only digitally signed assemblies are allowed; set ExtensionAllowUnsignedAssemblies to true to remove that requirement. ```json { "EnableModuleCommand": "local", "ExtensionBinPaths": ["/first/path", "/second/path"] } ``` -------------------------------- ### Garnet server startup command Source: https://microsoft.github.io/garnet/docs/benchmarking/results-resp-bench Command to run the Garnet server with specified bind, port, and options. Uses net10.0 framework and disables pubsub and object storage with a 1GB index. ```bash dotnet run -c Release --framework=net10.0 --project Garnet/main/GarnetServer -- \ --bind $host \ --port $port \ --no-pubsub \ --no-obj \ --index 1g ```