diff --git a/content/commands/del.md b/content/commands/del.md index 902c666d86..dfef37357c 100644 --- a/content/commands/del.md +++ b/content/commands/del.md @@ -71,14 +71,6 @@ A key is ignored if it does not exist. (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 09a074ce4e..74abcb7aaa 100644 --- a/content/commands/exists.md +++ b/content/commands/exists.md @@ -64,23 +64,13 @@ The user should be aware that if the same existing key is mentioned in the argum ## 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" -EXISTS key1 -EXISTS nosuchkey -SET key2 "World" -EXISTS key1 key2 nosuchkey +> 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 a370727454..30006dcfa8 100644 --- a/content/commands/expire.md +++ b/content/commands/expire.md @@ -158,20 +158,6 @@ are now fixed. (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 %}} - ## Pattern: Navigation session Imagine you have a web service and you are interested in the latest N pages diff --git a/content/commands/get.md b/content/commands/get.md index e8d010ce54..c2ffb761a3 100644 --- a/content/commands/get.md +++ b/content/commands/get.md @@ -53,15 +53,14 @@ only handles string values. ## Examples -{{% redis-cli %}} -GET nonexisting -SET mykey "Hello" -GET mykey -{{% /redis-cli %}} - -### Code examples - -{{< 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 6d7eba2c9f..174b9b4b4e 100644 --- a/content/commands/hdel.md +++ b/content/commands/hdel.md @@ -64,22 +64,14 @@ If `key` does not exist, it is treated as an empty hash and this command returns ## 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 0285f43a01..b61c2a8264 100644 --- a/content/commands/hexpire.md +++ b/content/commands/hexpire.md @@ -120,26 +120,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 9dee028b01..327cc022ec 100644 --- a/content/commands/hget.md +++ b/content/commands/hget.md @@ -62,14 +62,6 @@ Returns the value associated with `field` in the hash stored at `key`. (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 b5e59f3703..f59be77b37 100644 --- a/content/commands/hgetall.md +++ b/content/commands/hgetall.md @@ -65,14 +65,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 d0af86311e..fb966e8626 100644 --- a/content/commands/hmget.md +++ b/content/commands/hmget.md @@ -69,14 +69,6 @@ a non-existing `key` will return a list of `nil` values. > {{< /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 d99fe1a019..3eddfa546a 100644 --- a/content/commands/hset.md +++ b/content/commands/hset.md @@ -88,17 +88,6 @@ If `key` doesn't exist, a new key holding a hash is created. 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 bc9f70534c..7266013b41 100644 --- a/content/commands/hvals.md +++ b/content/commands/hvals.md @@ -61,14 +61,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 7236986910..9caaa81919 100644 --- a/content/commands/incr.md +++ b/content/commands/incr.md @@ -76,14 +76,6 @@ representation of the integer. "11" {{< /clients-example >}} -Give this command a try in the interactive console: - -{{% redis-cli %}} -SET mykey "10" -INCR mykey -GET mykey -{{% /redis-cli %}} - ## Pattern: Counter The counter pattern is the most obvious thing you can do with Redis atomic diff --git a/content/commands/info.md b/content/commands/info.md index 66d58c46be..576ddab21c 100644 --- a/content/commands/info.md +++ b/content/commands/info.md @@ -72,15 +72,9 @@ 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 >}} -Give these commands a try in the interactive console: - -{{% redis-cli %}} -INFO -{{% /redis-cli %}} - ## Notes Please note depending on the version of Redis some of the fields have been diff --git a/content/commands/keys.md b/content/commands/keys.md index 150a432cd7..20e3694d74 100644 --- a/content/commands/keys.md +++ b/content/commands/keys.md @@ -90,14 +90,6 @@ To use pattern with hash tag, see [Hash tags]({{< relref "operate/oss_and_stack/ 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 7555c57193..aadab894bf 100644 --- a/content/commands/llen.md +++ b/content/commands/llen.md @@ -60,14 +60,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 969f1eb998..0b77d4dcf6 100644 --- a/content/commands/lpop.md +++ b/content/commands/lpop.md @@ -78,15 +78,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 24c7d2f385..4229e3215c 100644 --- a/content/commands/lpush.md +++ b/content/commands/lpush.md @@ -79,14 +79,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 13516cf5b8..5f882718e1 100644 --- a/content/commands/lrange.md +++ b/content/commands/lrange.md @@ -101,18 +101,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 %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/mget.md b/content/commands/mget.md index 968bf03c69..5dbaf107b4 100644 --- a/content/commands/mget.md +++ b/content/commands/mget.md @@ -71,14 +71,6 @@ Because of this, the operation never fails. 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 7c6b5355b1..3649a624a1 100644 --- a/content/commands/rpop.md +++ b/content/commands/rpop.md @@ -78,15 +78,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 477eeda749..968b33b239 100644 --- a/content/commands/rpush.md +++ b/content/commands/rpush.md @@ -80,14 +80,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 7eb57eca75..fb85c39bbc 100644 --- a/content/commands/sadd.md +++ b/content/commands/sadd.md @@ -74,14 +74,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 cff7dc2b82..6741a8d11e 100644 --- a/content/commands/set.md +++ b/content/commands/set.md @@ -165,16 +165,14 @@ A hash digest is a fixed-size numerical representation of a string value, comput ## Examples -{{% redis-cli %}} -SET mykey "Hello" -GET mykey - -SET anotherkey "will expire in a minute" EX 60 -{{% /redis-cli %}} - -### Code examples - -{{< 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 >}} ## Patterns diff --git a/content/commands/smembers.md b/content/commands/smembers.md index ba30701ff5..b3ad632d2c 100644 --- a/content/commands/smembers.md +++ b/content/commands/smembers.md @@ -63,14 +63,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 97f0244f85..f70480f354 100644 --- a/content/commands/ttl.md +++ b/content/commands/ttl.md @@ -75,14 +75,6 @@ See also the [`PTTL`]({{< relref "/commands/pttl" >}}) command that returns the (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 c24276cf74..b5394a5d76 100644 --- a/content/commands/zadd.md +++ b/content/commands/zadd.md @@ -186,15 +186,6 @@ If the user inserts all the elements in a sorted set with the same score (for ex 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 %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | diff --git a/content/commands/zrange.md b/content/commands/zrange.md index 5a63659bab..d0b68553f7 100644 --- a/content/commands/zrange.md +++ b/content/commands/zrange.md @@ -231,15 +231,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 %}} - ## Redis Software and Redis Cloud compatibility | Redis
Software | Redis
Cloud | Notes | 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 1c7a00d8b2..a76e4c223f 100644 --- a/layouts/partials/tabbed-clients-example.html +++ b/layouts/partials/tabbed-clients-example.html @@ -39,6 +39,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 +80,22 @@ {{ if and (gt $redisCommandsLineLimitInt 0) (gt $estimatedVisualLineCount $redisCommandsLineLimitInt) }} {{ $hasCliTrim = true }} {{ end }} - {{ $redisCliContent := highlight $trimmedRedisCommands "plaintext" "linenos=false" }} + {{/* Render the redis-cli tab as an interactive terminal (form.redis-cli is + picked up by cli.js and executed inline). Only redis-cli is interactive; + other language tabs stay as static highlighted code. */}} + {{ $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 }} + {{/* 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) }} @@ -127,8 +156,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 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 fd9553d09d..b4f7b99578 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 */}}