diff --git a/content/commands/del.md b/content/commands/del.md index 26517ddc97..6f4afb1099 100644 --- a/content/commands/del.md +++ b/content/commands/del.md @@ -79,14 +79,6 @@ One or more keys to delete. (integer) 2 {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -SET key1 "Hello" -SET key2 "World" -DEL key1 key2 key3 -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/exists.md b/content/commands/exists.md index 19d793ef88..30ca248ee6 100644 --- a/content/commands/exists.md +++ b/content/commands/exists.md @@ -72,28 +72,13 @@ One or more keys to check for existence. A repeated key is counted once per occu ## Examples {{< clients-example set="cmds_generic" step="exists" description="Foundational: Check if one or more keys exist using EXISTS (returns count of existing keys, useful for conditional logic)" difficulty="beginner" >}} -SET key1 "Hello" -"OK" -EXISTS key1 -(integer) 1 -EXISTS nosuchkey -(integer) 0 -SET key2 "World" -"OK" -EXISTS key1 key2 nosuchkey -(integer) 2 +> SET key1 "Hello" +> EXISTS key1 +> EXISTS nosuchkey +> SET key2 "World" +> EXISTS key1 key2 nosuchkey {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -SET key1 "Hello" -EXISTS key1 -EXISTS nosuchkey -SET key2 "World" -EXISTS key1 key2 nosuchkey -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/expire.md b/content/commands/expire.md index c60a672021..021ba45638 100644 --- a/content/commands/expire.md +++ b/content/commands/expire.md @@ -171,20 +171,6 @@ Set the expiry only when the new expiry is less than the current one. A non-vola (integer) 10 {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -SET mykey "Hello" -EXPIRE mykey 10 -TTL mykey -SET mykey "Hello World" -TTL mykey -EXPIRE mykey 10 XX -TTL mykey -EXPIRE mykey 10 NX -TTL mykey -{{% /redis-cli %}} - ## Details ### Refreshing expires diff --git a/content/commands/get.md b/content/commands/get.md index b65d3f2efc..f1967349dd 100644 --- a/content/commands/get.md +++ b/content/commands/get.md @@ -61,13 +61,14 @@ The name of the key. ## Examples -{{% redis-cli %}} -GET nonexisting -SET mykey "Hello" -GET mykey -{{% /redis-cli %}} -  -{{< clients-example set="set_and_get" step="get" description="Foundational: Retrieve the string value of a key using GET (returns nil if key doesn't exist)" difficulty="beginner" />}} +{{< clients-example set="set_and_get" step="get" description="Foundational: Retrieve the string value of a key using GET (returns nil if key doesn't exist)" difficulty="beginner" >}} +> GET nonexisting +(nil) +> SET mykey "Hello" +"OK" +> GET mykey +"Hello" +{{< /clients-example >}} ## Redis Software and Redis Cloud compatibility diff --git a/content/commands/hdel.md b/content/commands/hdel.md index e5198c9ef2..5b73a2aedc 100644 --- a/content/commands/hdel.md +++ b/content/commands/hdel.md @@ -78,22 +78,14 @@ One or more fields to delete from the hash. ## Examples {{< clients-example set="cmds_hash" step="hdel" description="Foundational: Delete one or more fields from a hash using HDEL (returns count of deleted fields, ignores non-existent fields)" difficulty="beginner" >}} -HSET myhash field1 "foo" +> HSET myhash field1 "foo" (integer) 1 -HDEL myhash field1 +> HDEL myhash field1 (integer) 1 -HDEL myhash field2 +> HDEL myhash field2 (integer) 0 {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -HSET myhash field1 "foo" -HDEL myhash field1 -HDEL myhash field2 -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/hexpire.md b/content/commands/hexpire.md index d0fa19a685..bc4b02efc9 100644 --- a/content/commands/hexpire.md +++ b/content/commands/hexpire.md @@ -156,26 +156,17 @@ Starting with Redis 8, Redis Search has enhanced behavior when handling expiring ## Examples {{< clients-example set="cmds_hash" step="hexpire" description="Field expiration: Set TTL on individual hash fields using HEXPIRE with conditional options (NX, XX, GT, LT) when you need fine-grained control over field lifecycle" difficulty="intermediate" >}} -HEXPIRE no-key 20 NX FIELDS 2 field1 field2 +> HEXPIRE no-key 20 NX FIELDS 2 field1 field2 (nil) -HSET mykey field1 "hello" field2 "world" +> HSET mykey field1 "hello" field2 "world" (integer) 2 -HEXPIRE mykey 10 FIELDS 3 field1 field2 field3 +> HEXPIRE mykey 10 FIELDS 3 field1 field2 field3 1) (integer) 1 2) (integer) 1 3) (integer) -2 -HGETALL mykey +> HGETALL mykey {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -HEXPIRE no-key 20 NX FIELDS 2 field1 field2 -HSET mykey field1 "hello" field2 "world" -HEXPIRE mykey 10 FIELDS 3 field1 field2 field3 -HGETALL mykey -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/hget.md b/content/commands/hget.md index 993571fcf8..da823925bc 100644 --- a/content/commands/hget.md +++ b/content/commands/hget.md @@ -76,14 +76,6 @@ The field whose value to retrieve. (nil) {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -HSET myhash field1 "foo" -HGET myhash field1 -HGET myhash field2 -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/hgetall.md b/content/commands/hgetall.md index 7d5b4c30eb..e98f2365ff 100644 --- a/content/commands/hgetall.md +++ b/content/commands/hgetall.md @@ -73,14 +73,6 @@ redis> HGETALL myhash 4) "World" {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -HSET myhash field1 "Hello" -HSET myhash field2 "World" -HGETALL myhash -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/hmget.md b/content/commands/hmget.md index a1309a0668..4fa8215e00 100644 --- a/content/commands/hmget.md +++ b/content/commands/hmget.md @@ -85,14 +85,6 @@ One or more fields whose values to retrieve. > {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -HSET myhash field1 "Hello" -HSET myhash field2 "World" -HMGET myhash field1 field2 nofield -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/hset.md b/content/commands/hset.md index 56c388b48a..a38940ed52 100644 --- a/content/commands/hset.md +++ b/content/commands/hset.md @@ -102,17 +102,6 @@ One or more field-value pairs to set in the hash. 6) "World" {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -HSET myhash field1 "Hello" -HGET myhash field1 -HSET myhash field2 "Hi" field3 "World" -HGET myhash field2 -HGET myhash field3 -HGETALL myhash -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/hvals.md b/content/commands/hvals.md index ced7581711..31c0bb86bc 100644 --- a/content/commands/hvals.md +++ b/content/commands/hvals.md @@ -69,14 +69,6 @@ redis> HVALS myhash 2) "World" {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -HSET myhash field1 "Hello" -HSET myhash field2 "World" -HVALS myhash -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/incr.md b/content/commands/incr.md index 923139fadd..d8713a176d 100644 --- a/content/commands/incr.md +++ b/content/commands/incr.md @@ -84,14 +84,6 @@ The name of the key. "11" {{< /clients-example >}} -Give this command a try in the interactive console: - -{{% redis-cli %}} -SET mykey "10" -INCR mykey -GET mykey -{{% /redis-cli %}} - ## Details ### Pattern: counter diff --git a/content/commands/info.md b/content/commands/info.md index e107b8241e..1e454ed4db 100644 --- a/content/commands/info.md +++ b/content/commands/info.md @@ -72,7 +72,7 @@ It can also take the following values: When no parameter is provided, the `default` option is assumed. {{< clients-example set="cmds_servermgmt" step="info" description="Foundational: Get server information and statistics using INFO (supports optional section filtering, returns key-value pairs)" difficulty="beginner" >}} -INFO +> INFO {{< /clients-example >}} ## Optional arguments diff --git a/content/commands/keys.md b/content/commands/keys.md index 3f8c5b586d..ecd82a89f6 100644 --- a/content/commands/keys.md +++ b/content/commands/keys.md @@ -103,14 +103,6 @@ To use pattern with a hash tag, see [Hash tags]({{< relref "operate/oss_and_stac 3) "firstname" {{< /clients-example >}} -Give these commands a try in the interactive console: -{{% redis-cli %}} -MSET firstname Jack lastname Stuntman age 35 -KEYS *name* -KEYS a?? -KEYS * -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/llen.md b/content/commands/llen.md index 147889a024..80a5965e60 100644 --- a/content/commands/llen.md +++ b/content/commands/llen.md @@ -68,14 +68,6 @@ redis> LLEN mylist (integer) 2 {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -LPUSH mylist "World" -LPUSH mylist "Hello" -LLEN mylist -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/lpop.md b/content/commands/lpop.md index 694a85043b..3f5615ab25 100644 --- a/content/commands/lpop.md +++ b/content/commands/lpop.md @@ -94,15 +94,6 @@ redis> LRANGE mylist 0 -1 2) "five" {{< /clients-example>}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -RPUSH mylist "one" "two" "three" "four" "five" -LPOP mylist -LPOP mylist 2 -LRANGE mylist 0 -1 -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/lpush.md b/content/commands/lpush.md index 547b7b5301..240a442b00 100644 --- a/content/commands/lpush.md +++ b/content/commands/lpush.md @@ -93,14 +93,6 @@ redis> LRANGE mylist 0 -1 2) "world" {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -LPUSH mylist "world" -LPUSH mylist "hello" -LRANGE mylist 0 -1 -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/lrange.md b/content/commands/lrange.md index 95891c188f..410c9a2c01 100644 --- a/content/commands/lrange.md +++ b/content/commands/lrange.md @@ -106,18 +106,6 @@ redis> LRANGE mylist 5 10 (empty array) {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -RPUSH mylist "one" -RPUSH mylist "two" -RPUSH mylist "three" -LRANGE mylist 0 0 -LRANGE mylist -3 2 -LRANGE mylist -100 100 -LRANGE mylist 5 10 -{{% /redis-cli %}} - ## Details ### Consistency with range functions in various programming languages diff --git a/content/commands/mget.md b/content/commands/mget.md index b42f531358..fdf9a7dd1d 100644 --- a/content/commands/mget.md +++ b/content/commands/mget.md @@ -78,14 +78,6 @@ One or more keys whose values to retrieve. 3) (nil) {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -SET key1 "Hello" -SET key2 "World" -MGET key1 key2 nonexisting -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/rpop.md b/content/commands/rpop.md index 3f6ff0d11c..1038c2a4f4 100644 --- a/content/commands/rpop.md +++ b/content/commands/rpop.md @@ -94,15 +94,6 @@ redis> LRANGE mylist 0 -1 2) "two" {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -RPUSH mylist "one" "two" "three" "four" "five" -RPOP mylist -RPOP mylist 2 -LRANGE mylist 0 -1 -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/rpush.md b/content/commands/rpush.md index 5a4ecd7b3e..01f02c231a 100644 --- a/content/commands/rpush.md +++ b/content/commands/rpush.md @@ -94,14 +94,6 @@ redis> LRANGE mylist 0 -1 2) "world" {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -RPUSH mylist "hello" -RPUSH mylist "world" -LRANGE mylist 0 -1 -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/sadd.md b/content/commands/sadd.md index cbb555448a..c9a1941b7b 100644 --- a/content/commands/sadd.md +++ b/content/commands/sadd.md @@ -88,14 +88,6 @@ redis> SMEMBERS myset 2) "World" {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -SADD myset "Hello" "World" -SADD myset "World" -SMEMBERS myset -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/set.md b/content/commands/set.md index 5376b5b9cd..b6cf626c48 100644 --- a/content/commands/set.md +++ b/content/commands/set.md @@ -233,14 +233,14 @@ Note: Since the `SET` command options can replace [`SETNX`]({{< relref "/command ## Examples -{{% redis-cli %}} -SET mykey "Hello" -GET mykey - -SET anotherkey "will expire in a minute" EX 60 -{{% /redis-cli %}} -  -{{< clients-example set="set_and_get" step="set" description="Foundational: Set the string value of a key using SET (creates key if needed, overwrites existing value, supports expiration options)" difficulty="beginner" />}} +{{< clients-example set="set_and_get" step="set" description="Foundational: Set the string value of a key using SET (creates key if needed, overwrites existing value, supports expiration options)" difficulty="beginner" >}} +> SET mykey "Hello" +"OK" +> GET mykey +"Hello" +> SET anotherkey "will expire in a minute" EX 60 +"OK" +{{< /clients-example >}} ## Details diff --git a/content/commands/smembers.md b/content/commands/smembers.md index 1a92a0e152..123050a819 100644 --- a/content/commands/smembers.md +++ b/content/commands/smembers.md @@ -71,14 +71,6 @@ redis> SMEMBERS myset 2) "World" {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -SADD myset "Hello" -SADD myset "World" -SMEMBERS myset -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/ttl.md b/content/commands/ttl.md index af2a98f70d..660ec15316 100644 --- a/content/commands/ttl.md +++ b/content/commands/ttl.md @@ -83,14 +83,6 @@ The name of the key. (integer) 10 {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -SET mykey "Hello" -EXPIRE mykey 10 -TTL mykey -{{% /redis-cli %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/zadd.md b/content/commands/zadd.md index ed7be4cd93..85c94071d0 100644 --- a/content/commands/zadd.md +++ b/content/commands/zadd.md @@ -192,15 +192,6 @@ Increment the member's score by `score` instead of setting it, behaving like `ZI 8) "3" {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -ZADD myzset 1 "one" -ZADD myzset 1 "uno" -ZADD myzset 2 "two" 3 "three" -ZRANGE myzset 0 -1 WITHSCORES -{{% /redis-cli %}} - ## Details ### Range of integer scores that can be expressed precisely diff --git a/content/commands/zrange.md b/content/commands/zrange.md index c62aaddca8..b0c5423ce3 100644 --- a/content/commands/zrange.md +++ b/content/commands/zrange.md @@ -181,15 +181,6 @@ This example shows how to query the sorted set by score, excluding the value `1` 1) "three" {{< /clients-example >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -ZADD myzset 1 "one" 2 "two" 3 "three" -ZRANGE myzset 0 -1 -ZRANGE myzset 2 3 -ZRANGE myzset -2 -1 -{{% /redis-cli %}} - ## Details ### Common behavior and options diff --git a/content/develop/data-types/json/path.md b/content/develop/data-types/json/path.md index 7ab5becf42..189ef2e19a 100644 --- a/content/develop/data-types/json/path.md +++ b/content/develop/data-types/json/path.md @@ -117,7 +117,7 @@ The following JSONPath examples use this JSON document, which stores details abo First, create the JSON document in your database: -{{< clients-example set="json_tutorial" step="set_bikes" description="Setup: Create a complex JSON document with nested objects and arrays to use in JSONPath examples" max_lines="10" >}} +{{< clients-example set="json_tutorial" step="set_bikes" description="Setup: Create a complex JSON document with nested objects and arrays to use in JSONPath examples" max_lines="10" prereq="true" >}} > JSON.SET bikes:inventory $ '{ "inventory": { "mountain_bikes": [ { "id": "bike:1", "model": "Phoebe", "description": "This is a mid-travel trail slayer that is a fantastic daily driver or one bike quiver. The Shimano Claris 8-speed groupset gives plenty of gear range to tackle hills and there\'s room for mudguards and a rack too. This is the bike for the rider who wants trail manners with low fuss ownership.", "price": 1920, "specs": {"material": "carbon", "weight": 13.1}, "colors": ["black", "silver"] }, { "id": "bike:2", "model": "Quaoar", "description": "Redesigned for the 2020 model year, this bike impressed our testers and is the best all-around trail bike we\'ve ever tested. The Shimano gear system effectively does away with an external cassette, so is super low maintenance in terms of wear and tear. All in all it\'s an impressive package for the price, making it very competitive.", "price": 2072, "specs": {"material": "aluminium", "weight": 7.9}, "colors": ["black", "white"] }, { "id": "bike:3", "model": "Weywot", "description": "This bike gives kids aged six years and older a durable and uberlight mountain bike for their first experience on tracks and easy cruising through forests and fields. A set of powerful Shimano hydraulic disc brakes provide ample stopping ability. If you\'re after a budget option, this is one of the best bikes you could get.", "price": 3264, "specs": {"material": "alloy", "weight": 13.8} } ], "commuter_bikes": [ { "id": "bike:4", "model": "Salacia", "description": "This bike is a great option for anyone who just wants a bike to get about on With a slick-shifting Claris gears from Shimano\'s, this is a bike which doesn\'t break the bank and delivers craved performance. It\'s for the rider who wants both efficiency and capability.", "price": 1475, "specs": {"material": "aluminium", "weight": 16.6}, "colors": ["black", "silver"] }, { "id": "bike:5", "model": "Mimas", "description": "A real joy to ride, this bike got very high scores in last years Bike of the year report. The carefully crafted 50-34 tooth chainset and 11-32 tooth cassette give an easy-on-the-legs bottom gear for climbing, and the high-quality Vittoria Zaffiro tires give balance and grip.It includes a low-step frame , our memory foam seat, bump-resistant shocks and conveniently placed thumb throttle. Put it all together and you get a bike that helps redefine what can be done for this price.", "price": 3941, "specs": {"material": "alloy", "weight": 11.6} } ] }}' {{< /clients-example >}} @@ -127,14 +127,14 @@ The following examples use the [`JSON.GET`]({{< relref "commands/json.get/" >}}) You can use the wildcard operator `*` to return a list of all items in the inventory: -{{< clients-example set="json_tutorial" step="get_bikes" description="Wildcard queries: Use the * operator to retrieve all items in a collection when you need to access all elements at a specific level" buildsUpon="set_bikes" >}} +{{< clients-example set="json_tutorial" step="get_bikes" description="Wildcard queries: Use the * operator to retrieve all items in a collection when you need to access all elements at a specific level" buildsUpon="set_bikes" needs_prereq="true" >}} > JSON.GET bikes:inventory $.inventory.* "[[{\"id\":\"bike:1\",\"model\":\"Phoebe\",\"description\":\"This is a mid-travel trail slayer... {{< /clients-example >}} For some queries, multiple paths can produce the same results. For example, the following paths return the names of all mountain bikes: -{{< clients-example set="json_tutorial" step="get_mtnbikes" description="Array element access: Use bracket notation and array subscripts to access specific array elements or all elements with [*] when you need to retrieve values from arrays" difficulty="intermediate" buildsUpon="get_bikes" >}} +{{< clients-example set="json_tutorial" step="get_mtnbikes" description="Array element access: Use bracket notation and array subscripts to access specific array elements or all elements with [*] when you need to retrieve values from arrays" difficulty="intermediate" buildsUpon="get_bikes" needs_prereq="true" >}} > JSON.GET bikes:inventory $.inventory.mountain_bikes[*].model "[\"Phoebe\",\"Quaoar\",\"Weywot\"]" > JSON.GET bikes:inventory '$.inventory["mountain_bikes"][*].model' @@ -145,14 +145,14 @@ For some queries, multiple paths can produce the same results. For example, the The recursive descent operator `..` can retrieve a field from multiple sections of a JSON document. The following example returns the names of all inventory items: -{{< clients-example set="json_tutorial" step="get_models" description="Recursive descent: Use the .. operator to search for a field at any depth in the JSON document when you need to find values across multiple nesting levels" difficulty="intermediate" buildsUpon="get_mtnbikes" >}} +{{< clients-example set="json_tutorial" step="get_models" description="Recursive descent: Use the .. operator to search for a field at any depth in the JSON document when you need to find values across multiple nesting levels" difficulty="intermediate" buildsUpon="get_mtnbikes" needs_prereq="true" >}} > JSON.GET bikes:inventory $..model "[\"Phoebe\",\"Quaoar\",\"Weywot\",\"Salacia\",\"Mimas\"]" {{< /clients-example >}} You can use an array slice to select a range of elements from an array. This example returns the names of the first 2 mountain bikes: -{{< clients-example set="json_tutorial" step="get2mtnbikes" description="Array slicing: Use [start:end] syntax to select a range of array elements when you need to retrieve a subset of items from an array" difficulty="intermediate" buildsUpon="get_mtnbikes" >}} +{{< clients-example set="json_tutorial" step="get2mtnbikes" description="Array slicing: Use [start:end] syntax to select a range of array elements when you need to retrieve a subset of items from an array" difficulty="intermediate" buildsUpon="get_mtnbikes" needs_prereq="true" >}} > JSON.GET bikes:inventory $..mountain_bikes[0:2].model "[\"Phoebe\",\"Quaoar\"]" {{< /clients-example >}} @@ -177,14 +177,14 @@ as `/.*foo.*/`. In the following example, the filter only returns mountain bikes with a price less than 3000 and a weight less than 10: -{{< clients-example set="json_tutorial" step="filter1" description="Filter expressions: Use ?() with comparison and logical operators to select elements matching specific conditions when you need to query based on multiple criteria" difficulty="advanced" buildsUpon="get_models" >}} +{{< clients-example set="json_tutorial" step="filter1" description="Filter expressions: Use ?() with comparison and logical operators to select elements matching specific conditions when you need to query based on multiple criteria" difficulty="advanced" buildsUpon="get_models" needs_prereq="true" >}} > JSON.GET bikes:inventory '$..mountain_bikes[?(@.price < 3000 && @.specs.weight < 10)]' "[{\"id\":\"bike:2\",\"model\":\"Quaoar\",\"description\":\"Redesigned for the 2020 model year... {{< /clients-example >}} This example filters the inventory for the model names of bikes made from alloy: -{{< clients-example set="json_tutorial" step="filter2" description="Equality filters: Use == operator in filter expressions to select elements with specific field values when you need to find items matching exact criteria" difficulty="advanced" buildsUpon="filter1" >}} +{{< clients-example set="json_tutorial" step="filter2" description="Equality filters: Use == operator in filter expressions to select elements with specific field values when you need to find items matching exact criteria" difficulty="advanced" buildsUpon="filter1" needs_prereq="true" >}} > JSON.GET bikes:inventory '$..[?(@.specs.material == "alloy")].model' "[\"Weywot\",\"Mimas\"]" {{< /clients-example >}} @@ -193,7 +193,7 @@ This example, valid from version v2.4.2 onwards, filters only bikes whose materi "al-" using regex match. Note that this match is case-insensitive because of the prefix `(?i)` in the regular expression pattern `"(?i)al"`: -{{< clients-example set="json_tutorial" step="filter3" description="Regex filters: Use =~ operator with regular expressions in filter expressions to match patterns in string values when you need flexible pattern-based filtering" difficulty="advanced" buildsUpon="filter2" >}} +{{< clients-example set="json_tutorial" step="filter3" description="Regex filters: Use =~ operator with regular expressions in filter expressions to match patterns in string values when you need flexible pattern-based filtering" difficulty="advanced" buildsUpon="filter2" needs_prereq="true" >}} JSON.GET bikes:inventory '$..[?(@.specs.material =~ "(?i)al")].model' "[\"Quaoar\",\"Weywot\",\"Salacia\",\"Mimas\"]" {{< /clients-example >}} @@ -203,7 +203,7 @@ For example, we can add a string property named `regex_pat` to each mountain bik with the value `"(?i)al"` to match the material, as in the previous example. We can then match `regex_pat` against the bike's material: -{{< clients-example set="json_tutorial" step="filter4" description="Dynamic regex filters: Use regex patterns stored in JSON properties to filter elements when you need to apply patterns defined within the document itself" difficulty="advanced" buildsUpon="filter3" >}} +{{< clients-example set="json_tutorial" step="filter4" description="Dynamic regex filters: Use regex patterns stored in JSON properties to filter elements when you need to apply patterns defined within the document itself" difficulty="advanced" buildsUpon="filter3" needs_prereq="true" >}} > JSON.SET bikes:inventory $.inventory.mountain_bikes[0].regex_pat '"(?i)al"' OK > JSON.SET bikes:inventory $.inventory.mountain_bikes[1].regex_pat '"(?i)al"' @@ -220,7 +220,7 @@ You can also use JSONPath queries when you want to update specific sections of a For example, you can pass a JSONPath to the [`JSON.SET`]({{< relref "commands/json.set/" >}}) command to update a specific field. This example changes the price of the first item in the headphones list: -{{< clients-example set="json_tutorial" step="update_bikes" description="Bulk updates: Use JSONPath with JSON.NUMINCRBY to update multiple numeric values across the document when you need to apply arithmetic operations to multiple fields" difficulty="intermediate" buildsUpon="get_bikes" >}} +{{< clients-example set="json_tutorial" step="update_bikes" description="Bulk updates: Use JSONPath with JSON.NUMINCRBY to update multiple numeric values across the document when you need to apply arithmetic operations to multiple fields" difficulty="intermediate" buildsUpon="get_bikes" needs_prereq="true" >}} > JSON.GET bikes:inventory $..price "[1920,2072,3264,1475,3941]" > JSON.NUMINCRBY bikes:inventory $..price -100 @@ -231,7 +231,7 @@ For example, you can pass a JSONPath to the [`JSON.SET`]({{< relref "commands/js You can use filter expressions to update only JSON elements that match certain conditions. The following example sets the price of any bike to 1500 if its price is already less than 2000: -{{< clients-example set="json_tutorial" step="update_filters1" description="Conditional updates: Use filter expressions with JSON.SET to update only elements matching specific conditions when you need selective modifications" difficulty="advanced" buildsUpon="filter1" >}} +{{< clients-example set="json_tutorial" step="update_filters1" description="Conditional updates: Use filter expressions with JSON.SET to update only elements matching specific conditions when you need selective modifications" difficulty="advanced" buildsUpon="filter1" needs_prereq="true" >}} > JSON.SET bikes:inventory '$.inventory.*[?(@.price<2000)].price' 1500 OK > JSON.GET bikes:inventory $..price @@ -240,7 +240,7 @@ OK JSONPath queries also work with other JSON commands that accept a path as an argument. For example, you can add a new color option for a set of headphones with [`JSON.ARRAPPEND`]({{< relref "commands/json.arrappend/" >}}): -{{< clients-example set="json_tutorial" step="update_filters2" description="Array updates with filters: Use JSON.ARRAPPEND with filter expressions to add elements to arrays matching conditions when you need to modify collections selectively" difficulty="advanced" buildsUpon="update_filters1" >}} +{{< clients-example set="json_tutorial" step="update_filters2" description="Array updates with filters: Use JSON.ARRAPPEND with filter expressions to add elements to arrays matching conditions when you need to modify collections selectively" difficulty="advanced" buildsUpon="update_filters1" needs_prereq="true" >}} > JSON.ARRAPPEND bikes:inventory '$.inventory.*[?(@.price<2000)].colors' '"pink"' 1) (integer) 3 2) (integer) 3 diff --git a/layouts/develop/single.html b/layouts/develop/single.html index 77511c978f..52e6fa0fb5 100644 --- a/layouts/develop/single.html +++ b/layouts/develop/single.html @@ -1,5 +1,6 @@ {{ define "head" }} + {{ end }} {{ define "main" }} diff --git a/layouts/partials/tabbed-clients-example.html b/layouts/partials/tabbed-clients-example.html index 46db0ae721..44584c3678 100644 --- a/layouts/partials/tabbed-clients-example.html +++ b/layouts/partials/tabbed-clients-example.html @@ -9,6 +9,8 @@ {{ $cliFooterLinkText := .Scratch.Get "cli_footer_link_text" }} {{ $cliFooterLinkUrl := .Scratch.Get "cli_footer_link_url" }} {{ $showFooter := .Scratch.Get "show_footer" | default true }} +{{/* runnable defaults to true; "false" renders a static, non-executable cli tab */}} +{{ $runnable := ne (.Scratch.Get "runnable") "false" }} {{/* Parse buildsUpon parameter into an array */}} {{ $buildsUponStr := .Scratch.Get "buildsUpon" }} @@ -39,6 +41,20 @@ {{ warnf "[tabbed-clients-example] Example not found %q for %q" $id $.Page }} {{ end }} +{{/* Extract executable CLI commands (lines starting with "> " or "redis> ") for Try It button */}} +{{ $tryItCommands := slice }} +{{ if (ne (trim $redisCommands "\n") "") }} + {{ range $line := split (trim $redisCommands "\n") "\n" }} + {{ $trimmedLine := trim $line " " }} + {{ if hasPrefix $trimmedLine "redis> " }} + {{ $tryItCommands = $tryItCommands | append (strings.TrimPrefix "redis> " $trimmedLine) }} + {{ else if hasPrefix $trimmedLine "> " }} + {{ $tryItCommands = $tryItCommands | append (strings.TrimPrefix "> " $trimmedLine) }} + {{ end }} + {{ end }} +{{ end }} + + {{ $tabs := slice }} {{/* Render redis-cli example from inner content if any */}} {{ if (ne (trim $redisCommands "\n") "") }} @@ -66,7 +82,33 @@ {{ if and (gt $redisCommandsLineLimitInt 0) (gt $estimatedVisualLineCount $redisCommandsLineLimitInt) }} {{ $hasCliTrim = true }} {{ end }} - {{ $redisCliContent := highlight $trimmedRedisCommands "plaintext" "linenos=false" }} + {{/* Render the redis-cli tab. When runnable (default) it is an interactive + terminal (form.redis-cli is picked up by cli.js and executed inline). + When runnable="false" (e.g. unsafe blocking commands like BRPOP) it is + rendered as a static, non-executable code block with no "Try it" button. + Only redis-cli is interactive; other language tabs stay static. */}} + {{ $redisCliContent := "" }} + {{ if $runnable }} + {{ $cliCommandLines := $tryItCommands }} + {{ if eq (len $cliCommandLines) 0 }} + {{ range $line := $redisCommandLines }} + {{ $trimmedCliLine := trim $line " \t\r" }} + {{ if $trimmedCliLine }}{{ $cliCommandLines = $cliCommandLines | append $trimmedCliLine }}{{ end }} + {{ end }} + {{ end }} + {{ $cliJoined := delimit $cliCommandLines "\n" }} + {{ $cliFormInner := htmlEscape $cliJoined }} + {{ $cliSourceAttr := replace (htmlEscape $cliJoined) "\n" " " }} + {{ $redisCliContent = printf "
\n%s\n
" $cliSourceAttr $cliFormInner | safeHTML }} + {{ else }} + {{/* Mirror the interactive terminal's structure (div.redis-cli > pre) so it + inherits the same styling and avoids prose's default
 margins.
+             cli.js/codetabs.js only target form.redis-cli, so this stays static. */}}
+        {{ $staticInner := htmlEscape $trimmedRedisCommands }}
+        {{ $redisCliContent = printf "
%s
" $staticInner | safeHTML }} + {{ end }} + {{/* Trimming applies to static code blocks; the interactive terminal manages its own height. */}} + {{ $hasCliTrim = false }} {{ $cliTab := dict "title" "redis-cli" "displayName" $cliTabName "content" $redisCliContent "limit" $redisCommandsLineLimit "limitInt" $redisCommandsLineLimitInt "lineCount" $redisCommandLineCount "visualLineCount" $estimatedVisualLineCount "hasCliTrim" $hasCliTrim "customFooterLinkText" $cliFooterLinkText "customFooterLinkUrl" $cliFooterLinkUrl }} {{ if gt (len $commands) 0 }} {{ $cliTab = merge $cliTab (dict "commands" $commands) }} @@ -187,8 +229,19 @@ {{ end }} {{ end }} -{{ $params := dict "id" (printf "%s-step%s" $id $step) "tabs" $tabs "showFooter" $showFooter "exampleId" $step "description" $description "difficulty" $difficulty }} +{{ $isPrereq := eq (.Scratch.Get "prereq") "true" }} +{{ $needsPrereq := eq (.Scratch.Get "needs_prereq") "true" }} +{{ $params := dict "id" (printf "%s-step%s" $id $step) "tabs" $tabs "showFooter" $showFooter "exampleId" $step "description" $description "difficulty" $difficulty "exampleSet" $id }} {{ if gt (len $buildsUpon) 0 }} {{ $params = merge $params (dict "buildsUpon" $buildsUpon) }} {{ end }} +{{ if and $runnable (gt (len $tryItCommands) 0) }} + {{ $params = merge $params (dict "tryItCommands" $tryItCommands) }} +{{ end }} +{{ if $isPrereq }} + {{ $params = merge $params (dict "isPrereq" true) }} +{{ end }} +{{ if $needsPrereq }} + {{ $params = merge $params (dict "needsPrereq" true) }} +{{ end }} {{ partial "tabs/wrapper.html" $params }} diff --git a/layouts/partials/tabs/wrapper.html b/layouts/partials/tabs/wrapper.html index 1d449e0b24..c12dd14acb 100644 --- a/layouts/partials/tabs/wrapper.html +++ b/layouts/partials/tabs/wrapper.html @@ -9,6 +9,10 @@ {{ $description := .description }} {{ $difficulty := .difficulty }} {{ $buildsUpon := .buildsUpon }} +{{ $tryItCommands := .tryItCommands }} +{{ $isPrereq := .isPrereq }} +{{ $needsPrereq := .needsPrereq }} +{{ $exampleSet := .exampleSet }} {{- /* Build metadata map for each language/client combination */ -}} {{- $codetabsMeta := dict -}} @@ -71,7 +75,7 @@ {{- if $exampleId -}} - + {{- end -}}
@@ -101,6 +105,21 @@
+ {{/* "Try it" button - opens redis.io/cli with pre-populated commands */}} + {{ if $tryItCommands }} + + {{ end }} {{/* BinderHub "Run in browser" link - shown conditionally based on current tab's binderId */}}