From 89c6f2fae302342fa8a83149c4d556ccf6906a12 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 29 Jul 2025 09:36:40 +0100 Subject: [PATCH 1/5] DOC-5503 David's local examples build --- build/local_examples.py | 158 +++++++++++++++++++ build/make.py | 17 +- layouts/partials/tabbed-clients-example.html | 6 +- 3 files changed, 170 insertions(+), 11 deletions(-) create mode 100644 build/local_examples.py diff --git a/build/local_examples.py b/build/local_examples.py new file mode 100644 index 0000000000..20ac1dd2f0 --- /dev/null +++ b/build/local_examples.py @@ -0,0 +1,158 @@ +#!/usr/bin/env python3 +""" +Local Examples Processor + +This script processes local examples from the local_examples/ directory +and integrates them into the existing examples system. + +Works like remote examples - each file contains an EXAMPLE: header +and can be any supported language. +""" + +import os +import glob +import shutil +import logging +from typing import Dict, Any + +from components.example import Example +from components.util import mkdir_p +from components.structured_data import load_dict, dump_dict + + +# File extension to language mapping +EXTENSION_TO_LANGUAGE = { + '.py': 'python', + '.js': 'node.js', + '.go': 'go', + '.cs': 'c#', + '.java': 'java', + '.php': 'php' +} + +# Language to client name mapping (from config.toml clientsExamples) +LANGUAGE_TO_CLIENT = { + 'python': 'Python', + 'node.js': 'Node.js', + 'go': 'Go', + 'c#': 'C#', + 'java': 'Java-Sync', # Default to sync, could be overridden + 'php': 'PHP', + 'redisvl': 'RedisVL' +} + + +def get_language_from_extension(filename: str) -> str: + """Get language from file extension.""" + _, ext = os.path.splitext(filename) + return EXTENSION_TO_LANGUAGE.get(ext.lower()) + + +def get_client_name_from_language(language: str) -> str: + """Get client name from language.""" + return LANGUAGE_TO_CLIENT.get(language, language.title()) + + +def get_example_id_from_file(path: str) -> str: + """Extract example ID from the first line of a file.""" + try: + with open(path, 'r') as f: + first_line = f.readline().strip() + if 'EXAMPLE:' in first_line: + return first_line.split(':')[1].strip() + except Exception as e: + logging.error(f"Error reading example ID from {path}: {e}") + return None + + +def process_local_examples(local_examples_dir: str = 'local_examples', + examples_dir: str = 'examples', + examples_json: str = 'data/examples.json') -> None: + """ + Process local examples and integrate them into the examples system. + + Works like remote examples - each file contains an EXAMPLE: header + and can be any supported language. + + Args: + local_examples_dir: Directory containing local example source files + examples_dir: Target directory for processed examples + examples_json: Path to examples.json file + """ + + if not os.path.exists(local_examples_dir): + logging.info(f"Local examples directory {local_examples_dir} not found, skipping") + return + + # Load existing examples data + examples_data = {} + if os.path.exists(examples_json): + examples_data = load_dict(examples_json) + + # Process each file in local_examples directory + for filename in os.listdir(local_examples_dir): + source_file = os.path.join(local_examples_dir, filename) + + if not os.path.isfile(source_file): + continue + + # Get language from file extension + language = get_language_from_extension(filename) + if not language: + logging.warning(f"Unknown file extension for: {filename}") + continue + + # Get example ID from file content + example_id = get_example_id_from_file(source_file) + if not example_id: + logging.warning(f"No EXAMPLE: header found in {filename}") + continue + + logging.info(f"Processing local example: {example_id} ({language})") + + # Create target directory + target_dir = os.path.join(examples_dir, example_id) + mkdir_p(target_dir) + + # Initialize example data + if example_id not in examples_data: + examples_data[example_id] = {} + + # Copy file to target directory with local_ prefix + base_name = os.path.splitext(filename)[0] + ext = os.path.splitext(filename)[1] + target_filename = f"local_{base_name}{ext}" + target_file = os.path.join(target_dir, target_filename) + shutil.copy2(source_file, target_file) + + # Process with Example class + example = Example(language, target_file) + + # Get client name + client_name = get_client_name_from_language(language) + + # Create metadata + example_metadata = { + 'source': source_file, + 'language': language, + 'target': target_file, + 'highlight': example.highlight, + 'hidden': example.hidden, + 'named_steps': example.named_steps, + 'sourceUrl': None # Local examples don't have source URLs + } + + examples_data[example_id][client_name] = example_metadata + logging.info(f"Processed {client_name} example for {example_id}") + + # Save updated examples data + dump_dict(examples_json, examples_data) + logging.info(f"Updated examples data saved to {examples_json}") + + +if __name__ == '__main__': + logging.basicConfig(level=logging.INFO, + format='%(levelname)s: %(message)s') + + process_local_examples() + print("Local examples processing complete") diff --git a/build/make.py b/build/make.py index b278806553..7e423cce9f 100644 --- a/build/make.py +++ b/build/make.py @@ -1,10 +1,12 @@ import argparse from datetime import datetime import logging +import sys import tempfile from components.component import All from components.util import mkdir_p +from local_examples import process_local_examples def parse_args() -> argparse.Namespace: @@ -30,20 +32,19 @@ def parse_args() -> argparse.Namespace: ARGS = parse_args() mkdir_p(ARGS.tempdir) - # Configure logging BEFORE creating objects - log_level = getattr(logging, ARGS.loglevel.upper()) - logging.basicConfig( - level=log_level, - format='%(message)s %(filename)s:%(lineno)d - %(funcName)s', - force=True # Force reconfiguration in case logging was already configured - ) - # Load settings ALL = All(ARGS.stack, None, ARGS.__dict__) # Make the stack + logging.basicConfig( + level=ARGS.loglevel, format=f'{sys.argv[0]}: %(levelname)s %(asctime)s %(message)s') print(f'Applying all configured components"{ALL._name}"') start = datetime.now() ALL.apply() + + # Process local examples + print('Processing local examples') + process_local_examples() + total = datetime.now() - start print(f'+OK ({total.microseconds / 1000} ms)') diff --git a/layouts/partials/tabbed-clients-example.html b/layouts/partials/tabbed-clients-example.html index 3c79ea69ce..c21d057c6c 100644 --- a/layouts/partials/tabbed-clients-example.html +++ b/layouts/partials/tabbed-clients-example.html @@ -21,15 +21,15 @@ {{ $clientConfig := index $.Site.Params.clientsconfig $client }} {{ $language := index $example "language" }} {{ $quickstartSlug := index $clientConfig "quickstartSlug" }} - + {{ if and ($example) (or (eq $lang "") (strings.Contains $lang $client)) }} {{ $examplePath := index $example "target" }} {{ $options := printf "linenos=false" }} - + {{ if and (ne $step "") (isset $example "named_steps") (isset $example.named_steps $step) }} {{ $options = printf "%s,hl_lines=%s" $options (index $example.named_steps $step) }} {{ else }} - {{ if isset $example "highlight" }} + {{ if and (isset $example "highlight") (index $example "highlight") }} {{ $options = printf "%s,hl_lines=%s" $options (delimit (index $example "highlight") " ") }} {{ end }} {{ end }} From 52063a7e01c2116f5e8f2e8505b7717a53ae929c Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 29 Jul 2025 10:24:53 +0100 Subject: [PATCH 2/5] DOC-5503 New param to override default tab name --- layouts/partials/tabbed-clients-example.html | 3 ++- layouts/partials/tabs/wrapper.html | 2 +- layouts/shortcodes/clients-example.html | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/layouts/partials/tabbed-clients-example.html b/layouts/partials/tabbed-clients-example.html index c21d057c6c..e1255587bb 100644 --- a/layouts/partials/tabbed-clients-example.html +++ b/layouts/partials/tabbed-clients-example.html @@ -3,6 +3,7 @@ {{ $lang := .Scratch.Get "lang" }} {{ $redisCommands := .Scratch.Get "redisCommands" }} {{ $redisCommandsLineLimit := (or (.Scratch.Get "maxLines") 100) }} +{{ $cliTabName := (or (.Scratch.Get "cli_tab_name") ">_ Redis CLI") }} {{ if not (isset $.Site.Data.examples $id) }} {{ warnf "[tabbed-clients-example] Example not found %q for %q" $id $.Page }} @@ -12,7 +13,7 @@ {{/* Render redis-cli example from inner content if any */}} {{ if (ne (trim $redisCommands "\n") "") }} {{ $redisCliContent := highlight (trim $redisCommands "\n") "plaintext" (printf "linenos=false,hl_lines=1-%d" $redisCommandsLineLimit ) }} - {{ $tabs = $tabs | append (dict "title" "redis-cli" "content" $redisCliContent "limit" $redisCommandsLineLimit) }} + {{ $tabs = $tabs | append (dict "title" "redis-cli" "displayName" $cliTabName "content" $redisCliContent "limit" $redisCommandsLineLimit) }} {{ end }} {{ $clientExamples := index $.Site.Data.examples $id }} diff --git a/layouts/partials/tabs/wrapper.html b/layouts/partials/tabs/wrapper.html index bf9c18e536..3768d03ed7 100644 --- a/layouts/partials/tabs/wrapper.html +++ b/layouts/partials/tabs/wrapper.html @@ -21,7 +21,7 @@ hover:text-redis-red-600 rounded rounded-mx transition duration-150 ease-in-out" title="Open example" for="{{ $tid }}"> {{ if eq (index $tab "title") "redis-cli" }} - {{ $cliName }} + {{ or (index $tab "displayName") $cliName }} {{ else }} {{ index $tab "title" }} {{ end }} diff --git a/layouts/shortcodes/clients-example.html b/layouts/shortcodes/clients-example.html index fd56cb9c04..7d327fd690 100644 --- a/layouts/shortcodes/clients-example.html +++ b/layouts/shortcodes/clients-example.html @@ -2,5 +2,6 @@ {{ .Scratch.Set "step" (.Get 1) }} {{ .Scratch.Set "lang" (.Get 2) }} {{ .Scratch.Set "maxLines" (.Get 3) }} +{{ .Scratch.Set "cli_tab_name" (.Get 4) }} {{ .Scratch.Set "redisCommands" .Inner }} {{ partial "tabbed-clients-example.html" . }} From bc372f6fc18413ff016bbcedea6e0b1656826600 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 29 Jul 2025 11:21:25 +0100 Subject: [PATCH 3/5] DOC-5503 allow custom name and link for first tab --- layouts/partials/tabbed-clients-example.html | 6 ++- layouts/partials/tabs/wrapper.html | 56 +++++++++++++------- layouts/shortcodes/clients-example.html | 2 + 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/layouts/partials/tabbed-clients-example.html b/layouts/partials/tabbed-clients-example.html index e1255587bb..5d77838ad5 100644 --- a/layouts/partials/tabbed-clients-example.html +++ b/layouts/partials/tabbed-clients-example.html @@ -4,6 +4,8 @@ {{ $redisCommands := .Scratch.Get "redisCommands" }} {{ $redisCommandsLineLimit := (or (.Scratch.Get "maxLines") 100) }} {{ $cliTabName := (or (.Scratch.Get "cli_tab_name") ">_ Redis CLI") }} +{{ $cliFooterLinkText := .Scratch.Get "cli_footer_link_text" }} +{{ $cliFooterLinkUrl := .Scratch.Get "cli_footer_link_url" }} {{ if not (isset $.Site.Data.examples $id) }} {{ warnf "[tabbed-clients-example] Example not found %q for %q" $id $.Page }} @@ -13,7 +15,7 @@ {{/* Render redis-cli example from inner content if any */}} {{ if (ne (trim $redisCommands "\n") "") }} {{ $redisCliContent := highlight (trim $redisCommands "\n") "plaintext" (printf "linenos=false,hl_lines=1-%d" $redisCommandsLineLimit ) }} - {{ $tabs = $tabs | append (dict "title" "redis-cli" "displayName" $cliTabName "content" $redisCliContent "limit" $redisCommandsLineLimit) }} + {{ $tabs = $tabs | append (dict "title" "redis-cli" "displayName" $cliTabName "content" $redisCliContent "limit" $redisCommandsLineLimit "customFooterLinkText" $cliFooterLinkText "customFooterLinkUrl" $cliFooterLinkUrl) }} {{ end }} {{ $clientExamples := index $.Site.Data.examples $id }} @@ -41,5 +43,5 @@ {{ end }} {{ end }} -{{ $params := dict "id" (printf "%s-step%s" $id $step) "tabs" $tabs "showFooter" (eq $lang "") }} +{{ $params := dict "id" (printf "%s-step%s" $id $step) "tabs" $tabs "showFooter" true }} {{ partial "tabs/wrapper.html" $params }} diff --git a/layouts/partials/tabs/wrapper.html b/layouts/partials/tabs/wrapper.html index 3768d03ed7..d90996b429 100644 --- a/layouts/partials/tabs/wrapper.html +++ b/layouts/partials/tabs/wrapper.html @@ -54,24 +54,44 @@ diff --git a/local_examples/HashExample.cs b/local_examples/HashExample.cs new file mode 100644 index 0000000000..80ad6ac749 --- /dev/null +++ b/local_examples/HashExample.cs @@ -0,0 +1,142 @@ +// EXAMPLE: hash_tutorial +// HIDE_START + +using NRedisStack.Tests; +using StackExchange.Redis; + +//REMOVE_START +namespace Doc; +[Collection("DocsTests")] +//REMOVE_END +public class HashExample +// REMOVE_START +: AbstractNRedisStackTest, IDisposable +// REMOVE_END +{ + // REMOVE_START + public HashExample(EndpointsFixture fixture) : base(fixture) { } + + [SkippableFact] + // REMOVE_END + public void run() + { + //REMOVE_START + // This is needed because we're constructing ConfigurationOptions in the test before calling GetConnection + SkipIfTargetConnectionDoesNotExist(EndpointsFixture.Env.Standalone); + var _ = GetCleanDatabase(EndpointsFixture.Env.Standalone); + //REMOVE_END + var muxer = ConnectionMultiplexer.Connect("localhost:6379"); + var db = muxer.GetDatabase(); + db.KeyDelete("bike:1"); + //HIDE_END + //STEP_START set_get_all + // Zuggle + db.HashSet("bike:1", new HashEntry[] + { + new HashEntry("model", "Deimos"), + new HashEntry("brand", "Ergonom"), + new HashEntry("type", "Enduro bikes"), + new HashEntry("price", 4972) + }); + + Console.WriteLine("Hash Created"); + // Hash Created + + var model = db.HashGet("bike:1", "model"); + Console.WriteLine($"Model: {model}"); + // Model: Deimos + + var price = db.HashGet("bike:1", "price"); + Console.WriteLine($"Price: {price}"); + // Price: 4972 + + var bike = db.HashGetAll("bike:1"); + Console.WriteLine("bike:1"); + Console.WriteLine(string.Join("\n", bike.Select(b => $"{b.Name}: {b.Value}"))); + // Bike:1: + // model: Deimos + // brand: Ergonom + // type: Enduro bikes + // price: 4972 + //STEP_END + + //REMOVE_START + Assert.Equal(4, bike.Length); + Assert.Equal("Deimos", model); + Assert.Equal(4972, price); + //REMOVE_END + + //STEP_START hmget + var values = db.HashGet("bike:1", new RedisValue[] { "model", "price" }); + Console.WriteLine(string.Join(" ", values)); + // Deimos 4972 + //REMOVE_START + Assert.Equal("Deimos", values[0]); + Assert.Equal(4972, values[1]); + //REMOVE_END + //STEP_END + + //STEP_START hincrby + var newPrice = db.HashIncrement("bike:1", "price", 100); + Console.WriteLine($"New price: {newPrice}"); + //REMOVE_START + Assert.Equal(5072, newPrice); + //REMOVE_END + // New price: 5072 + + newPrice = db.HashIncrement("bike:1", "price", -100); + Console.WriteLine($"New price: {newPrice}"); + //REMOVE_START + Assert.Equal(4972, newPrice); + //REMOVE_END + // New price: 4972 + //STEP_END + + //STEP_START incrby_get_mget + var rides = db.HashIncrement("bike:1", "rides"); + Console.WriteLine($"Rides: {rides}"); + //REMOVE_START + Assert.Equal(1, rides); + //REMOVE_END + // Rides: 1 + + rides = db.HashIncrement("bike:1", "rides"); + Console.WriteLine($"Rides: {rides}"); + //REMOVE_START + Assert.Equal(2, rides); + //REMOVE_END + // Rides: 2 + + rides = db.HashIncrement("bike:1", "rides"); + Console.WriteLine($"Rides: {rides}"); + //REMOVE_START + Assert.Equal(3, rides); + //REMOVE_END + // Rides: 3 + + var crashes = db.HashIncrement("bike:1", "crashes"); + Console.WriteLine($"Crashes: {crashes}"); + //REMOVE_START + Assert.Equal(1, crashes); + //REMOVE_END + // Crashes: 1 + + var owners = db.HashIncrement("bike:1", "owners"); + Console.WriteLine($"Owners: {owners}"); + //REMOVE_START + Assert.Equal(1, owners); + //REMOVE_END + // Owners: 1 + + var stats = db.HashGet("bike:1", new RedisValue[] { "crashes", "owners" }); + Console.WriteLine($"Bike stats: crashes={stats[0]}, owners={stats[1]}"); + //REMOVE_START + Assert.Equal(1, stats[0]); + Assert.Equal(1, stats[1]); + //REMOVE_END + // Bike stats: crashes=1, owners=1 + //STEP_END + //HIDE_START + } +} +//HIDE_END \ No newline at end of file diff --git a/local_examples/local_hash_demo.py b/local_examples/local_hash_demo.py new file mode 100644 index 0000000000..37af26cd7b --- /dev/null +++ b/local_examples/local_hash_demo.py @@ -0,0 +1,25 @@ +# EXAMPLE: local_hash_demo +# HIDE_START +import redis + +r = redis.Redis(host="localhost", port=6379, db=0, decode_responses=True) +# HIDE_END + +# STEP_START hset_hget +res = r.hset("user:1000", "name", "John Smith") +print(res) +# >>> 1 +res = r.hset("user:1000", mapping={"email": "john@example.com", "age": "30"}) +print(res) +# >>> 2 +res = r.hget("user:1000", "name") +print(res) +# >>> John Smith +res = r.hgetall("user:1000") +print(res) +# >>> {'name': 'John Smith', 'email': 'john@example.com', 'age': '30'} +# REMOVE_START +assert res["name"] == "John Smith" +r.delete("user:1000") +# REMOVE_END +# STEP_END diff --git a/local_examples/local_list_demo.go b/local_examples/local_list_demo.go new file mode 100644 index 0000000000..29d154328b --- /dev/null +++ b/local_examples/local_list_demo.go @@ -0,0 +1,42 @@ +// EXAMPLE: local_list_demo +// HIDE_START +package main + +import ( + "context" + "fmt" + "github.com/go-redis/redis/v8" +) + +func main() { + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + }) + ctx := context.Background() +// HIDE_END + + // STEP_START lpush_lrange + err := rdb.LPush(ctx, "mylist", "world").Err() + if err != nil { + panic(err) + } + + err = rdb.LPush(ctx, "mylist", "hello").Err() + if err != nil { + panic(err) + } + + vals, err := rdb.LRange(ctx, "mylist", 0, -1).Result() + if err != nil { + panic(err) + } + fmt.Println(vals) + // >>> [hello world] + // REMOVE_START + rdb.Del(ctx, "mylist") + // REMOVE_END + // STEP_END + +// HIDE_START +} +// HIDE_END diff --git a/local_examples/local_string_demo.js b/local_examples/local_string_demo.js new file mode 100644 index 0000000000..2118f655eb --- /dev/null +++ b/local_examples/local_string_demo.js @@ -0,0 +1,36 @@ +// EXAMPLE: local_string_demo +// HIDE_START +const redis = require('redis'); +const client = redis.createClient(); + +await client.connect(); +// HIDE_END + +// STEP_START set_get +let res = await client.set('mykey', 'Hello Redis!'); +console.log(res); +// >>> OK +res = await client.get('mykey'); +console.log(res); +// >>> Hello Redis! +// REMOVE_START +console.assert(res === 'Hello Redis!'); +await client.del('mykey'); +// REMOVE_END +// STEP_END + +// STEP_START incr +res = await client.set('counter', '10'); +console.log(res); +// >>> OK +res = await client.incr('counter'); +console.log(res); +// >>> 11 +res = await client.incrBy('counter', 5); +console.log(res); +// >>> 16 +// REMOVE_START +console.assert(res === 16); +await client.del('counter'); +// REMOVE_END +// STEP_END diff --git a/local_examples/local_string_demo.py b/local_examples/local_string_demo.py new file mode 100644 index 0000000000..349f08474f --- /dev/null +++ b/local_examples/local_string_demo.py @@ -0,0 +1,35 @@ +# EXAMPLE: local_string_demo +# HIDE_START +import redis + +r = redis.Redis(host="localhost", port=6379, db=0, decode_responses=True) +# HIDE_END + +# STEP_START set_get +res = r.set("mykey", "Hello Redis!") +print(res) +# >>> True +res = r.get("mykey") +print(res) +# >>> Hello Redis! +# REMOVE_START +assert res == "Hello Redis!" +r.delete("mykey") +# REMOVE_END +# STEP_END + +# STEP_START incr +res = r.set("counter", "10") +print(res) +# >>> True +res = r.incr("counter") +print(res) +# >>> 11 +res = r.incr("counter", 5) +print(res) +# >>> 16 +# REMOVE_START +assert res == 16 +r.delete("counter") +# REMOVE_END +# STEP_END From 71a7752d4f8fe0fbd30d81dfa5a91b143164b9fa Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 29 Jul 2025 15:05:18 +0100 Subject: [PATCH 5/5] DOC-5503 deleted test files --- .../develop/clients/test-local-examples.md | 92 ------------ local_examples/HashExample.cs | 142 ------------------ local_examples/local_hash_demo.py | 25 --- local_examples/local_list_demo.go | 42 ------ local_examples/local_string_demo.js | 36 ----- local_examples/local_string_demo.py | 35 ----- 6 files changed, 372 deletions(-) delete mode 100644 content/develop/clients/test-local-examples.md delete mode 100644 local_examples/HashExample.cs delete mode 100644 local_examples/local_hash_demo.py delete mode 100644 local_examples/local_list_demo.go delete mode 100644 local_examples/local_string_demo.js delete mode 100644 local_examples/local_string_demo.py diff --git a/content/develop/clients/test-local-examples.md b/content/develop/clients/test-local-examples.md deleted file mode 100644 index 56f2a42a4b..0000000000 --- a/content/develop/clients/test-local-examples.md +++ /dev/null @@ -1,92 +0,0 @@ ---- -title: "Test Local Examples" -description: "Testing the local code examples feature" ---- - -# Test Local Examples - -This page demonstrates the new local code examples feature that works just like remote examples. - -## String Operations - -Here's a local example showing string operations: - -{{< clients-example local_string_demo incr >}} -> SET mykey "Hello Redis!" -OK -> GET mykey -"Hello Redis!" -> SET counter 10 -OK -> INCR counter -(integer) 11 -> INCRBY counter 5 -(integer) 16 -{{< /clients-example >}} - -## With Step Highlighting - -You can highlight specific steps: - -{{< clients-example local_string_demo set_get >}} -> SET mykey "Hello Redis!" -OK -> GET mykey -"Hello Redis!" -{{< /clients-example >}} - -## Hash Operations - -Here's a local example for hash operations: - -{{< clients-example local_hash_demo >}} -> HSET user:1000 name "John Smith" -(integer) 1 -> HSET user:1000 email "john@example.com" age 30 -(integer) 2 -> HGET user:1000 name -"John Smith" -> HGETALL user:1000 -1) "name" -2) "John Smith" -3) "email" -4) "john@example.com" -5) "age" -6) "30" -{{< /clients-example >}} - -## List Operations (Go only) - -This example only has a Go implementation: - -{{< clients-example local_list_demo >}} -> LPUSH mylist "world" -(integer) 1 -> LPUSH mylist "hello" -(integer) 2 -> LRANGE mylist 0 -1 -1) "hello" -2) "world" -{{< /clients-example >}} - -## Language Filtering - -Show only Python examples: - -{{< clients-example local_hash_demo hset_hget Python >}} -> SET counter 10 -OK -> INCR counter -(integer) 11 -{{< /clients-example >}} - -## Custom Tab Name and Footer Link - -Test custom tab name and footer link (no language filtering so footer shows): - -{{< clients-example local_string_demo "" "" "" "REST API" "LangCache API" "/develop/ai/langcache/api-reference" >}} -> SET counter 10 -OK -> INCR counter -(integer) 11 -{{< /clients-example >}} diff --git a/local_examples/HashExample.cs b/local_examples/HashExample.cs deleted file mode 100644 index 80ad6ac749..0000000000 --- a/local_examples/HashExample.cs +++ /dev/null @@ -1,142 +0,0 @@ -// EXAMPLE: hash_tutorial -// HIDE_START - -using NRedisStack.Tests; -using StackExchange.Redis; - -//REMOVE_START -namespace Doc; -[Collection("DocsTests")] -//REMOVE_END -public class HashExample -// REMOVE_START -: AbstractNRedisStackTest, IDisposable -// REMOVE_END -{ - // REMOVE_START - public HashExample(EndpointsFixture fixture) : base(fixture) { } - - [SkippableFact] - // REMOVE_END - public void run() - { - //REMOVE_START - // This is needed because we're constructing ConfigurationOptions in the test before calling GetConnection - SkipIfTargetConnectionDoesNotExist(EndpointsFixture.Env.Standalone); - var _ = GetCleanDatabase(EndpointsFixture.Env.Standalone); - //REMOVE_END - var muxer = ConnectionMultiplexer.Connect("localhost:6379"); - var db = muxer.GetDatabase(); - db.KeyDelete("bike:1"); - //HIDE_END - //STEP_START set_get_all - // Zuggle - db.HashSet("bike:1", new HashEntry[] - { - new HashEntry("model", "Deimos"), - new HashEntry("brand", "Ergonom"), - new HashEntry("type", "Enduro bikes"), - new HashEntry("price", 4972) - }); - - Console.WriteLine("Hash Created"); - // Hash Created - - var model = db.HashGet("bike:1", "model"); - Console.WriteLine($"Model: {model}"); - // Model: Deimos - - var price = db.HashGet("bike:1", "price"); - Console.WriteLine($"Price: {price}"); - // Price: 4972 - - var bike = db.HashGetAll("bike:1"); - Console.WriteLine("bike:1"); - Console.WriteLine(string.Join("\n", bike.Select(b => $"{b.Name}: {b.Value}"))); - // Bike:1: - // model: Deimos - // brand: Ergonom - // type: Enduro bikes - // price: 4972 - //STEP_END - - //REMOVE_START - Assert.Equal(4, bike.Length); - Assert.Equal("Deimos", model); - Assert.Equal(4972, price); - //REMOVE_END - - //STEP_START hmget - var values = db.HashGet("bike:1", new RedisValue[] { "model", "price" }); - Console.WriteLine(string.Join(" ", values)); - // Deimos 4972 - //REMOVE_START - Assert.Equal("Deimos", values[0]); - Assert.Equal(4972, values[1]); - //REMOVE_END - //STEP_END - - //STEP_START hincrby - var newPrice = db.HashIncrement("bike:1", "price", 100); - Console.WriteLine($"New price: {newPrice}"); - //REMOVE_START - Assert.Equal(5072, newPrice); - //REMOVE_END - // New price: 5072 - - newPrice = db.HashIncrement("bike:1", "price", -100); - Console.WriteLine($"New price: {newPrice}"); - //REMOVE_START - Assert.Equal(4972, newPrice); - //REMOVE_END - // New price: 4972 - //STEP_END - - //STEP_START incrby_get_mget - var rides = db.HashIncrement("bike:1", "rides"); - Console.WriteLine($"Rides: {rides}"); - //REMOVE_START - Assert.Equal(1, rides); - //REMOVE_END - // Rides: 1 - - rides = db.HashIncrement("bike:1", "rides"); - Console.WriteLine($"Rides: {rides}"); - //REMOVE_START - Assert.Equal(2, rides); - //REMOVE_END - // Rides: 2 - - rides = db.HashIncrement("bike:1", "rides"); - Console.WriteLine($"Rides: {rides}"); - //REMOVE_START - Assert.Equal(3, rides); - //REMOVE_END - // Rides: 3 - - var crashes = db.HashIncrement("bike:1", "crashes"); - Console.WriteLine($"Crashes: {crashes}"); - //REMOVE_START - Assert.Equal(1, crashes); - //REMOVE_END - // Crashes: 1 - - var owners = db.HashIncrement("bike:1", "owners"); - Console.WriteLine($"Owners: {owners}"); - //REMOVE_START - Assert.Equal(1, owners); - //REMOVE_END - // Owners: 1 - - var stats = db.HashGet("bike:1", new RedisValue[] { "crashes", "owners" }); - Console.WriteLine($"Bike stats: crashes={stats[0]}, owners={stats[1]}"); - //REMOVE_START - Assert.Equal(1, stats[0]); - Assert.Equal(1, stats[1]); - //REMOVE_END - // Bike stats: crashes=1, owners=1 - //STEP_END - //HIDE_START - } -} -//HIDE_END \ No newline at end of file diff --git a/local_examples/local_hash_demo.py b/local_examples/local_hash_demo.py deleted file mode 100644 index 37af26cd7b..0000000000 --- a/local_examples/local_hash_demo.py +++ /dev/null @@ -1,25 +0,0 @@ -# EXAMPLE: local_hash_demo -# HIDE_START -import redis - -r = redis.Redis(host="localhost", port=6379, db=0, decode_responses=True) -# HIDE_END - -# STEP_START hset_hget -res = r.hset("user:1000", "name", "John Smith") -print(res) -# >>> 1 -res = r.hset("user:1000", mapping={"email": "john@example.com", "age": "30"}) -print(res) -# >>> 2 -res = r.hget("user:1000", "name") -print(res) -# >>> John Smith -res = r.hgetall("user:1000") -print(res) -# >>> {'name': 'John Smith', 'email': 'john@example.com', 'age': '30'} -# REMOVE_START -assert res["name"] == "John Smith" -r.delete("user:1000") -# REMOVE_END -# STEP_END diff --git a/local_examples/local_list_demo.go b/local_examples/local_list_demo.go deleted file mode 100644 index 29d154328b..0000000000 --- a/local_examples/local_list_demo.go +++ /dev/null @@ -1,42 +0,0 @@ -// EXAMPLE: local_list_demo -// HIDE_START -package main - -import ( - "context" - "fmt" - "github.com/go-redis/redis/v8" -) - -func main() { - rdb := redis.NewClient(&redis.Options{ - Addr: "localhost:6379", - }) - ctx := context.Background() -// HIDE_END - - // STEP_START lpush_lrange - err := rdb.LPush(ctx, "mylist", "world").Err() - if err != nil { - panic(err) - } - - err = rdb.LPush(ctx, "mylist", "hello").Err() - if err != nil { - panic(err) - } - - vals, err := rdb.LRange(ctx, "mylist", 0, -1).Result() - if err != nil { - panic(err) - } - fmt.Println(vals) - // >>> [hello world] - // REMOVE_START - rdb.Del(ctx, "mylist") - // REMOVE_END - // STEP_END - -// HIDE_START -} -// HIDE_END diff --git a/local_examples/local_string_demo.js b/local_examples/local_string_demo.js deleted file mode 100644 index 2118f655eb..0000000000 --- a/local_examples/local_string_demo.js +++ /dev/null @@ -1,36 +0,0 @@ -// EXAMPLE: local_string_demo -// HIDE_START -const redis = require('redis'); -const client = redis.createClient(); - -await client.connect(); -// HIDE_END - -// STEP_START set_get -let res = await client.set('mykey', 'Hello Redis!'); -console.log(res); -// >>> OK -res = await client.get('mykey'); -console.log(res); -// >>> Hello Redis! -// REMOVE_START -console.assert(res === 'Hello Redis!'); -await client.del('mykey'); -// REMOVE_END -// STEP_END - -// STEP_START incr -res = await client.set('counter', '10'); -console.log(res); -// >>> OK -res = await client.incr('counter'); -console.log(res); -// >>> 11 -res = await client.incrBy('counter', 5); -console.log(res); -// >>> 16 -// REMOVE_START -console.assert(res === 16); -await client.del('counter'); -// REMOVE_END -// STEP_END diff --git a/local_examples/local_string_demo.py b/local_examples/local_string_demo.py deleted file mode 100644 index 349f08474f..0000000000 --- a/local_examples/local_string_demo.py +++ /dev/null @@ -1,35 +0,0 @@ -# EXAMPLE: local_string_demo -# HIDE_START -import redis - -r = redis.Redis(host="localhost", port=6379, db=0, decode_responses=True) -# HIDE_END - -# STEP_START set_get -res = r.set("mykey", "Hello Redis!") -print(res) -# >>> True -res = r.get("mykey") -print(res) -# >>> Hello Redis! -# REMOVE_START -assert res == "Hello Redis!" -r.delete("mykey") -# REMOVE_END -# STEP_END - -# STEP_START incr -res = r.set("counter", "10") -print(res) -# >>> True -res = r.incr("counter") -print(res) -# >>> 11 -res = r.incr("counter", 5) -print(res) -# >>> 16 -# REMOVE_START -assert res == 16 -r.delete("counter") -# REMOVE_END -# STEP_END