-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Adds testable examples to be automatically pulled in redis.io docs #2601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
8acf06c
Adding examples
elena-kolevska 66667ea
Update readme
elena-kolevska 73513c8
Update Readme
elena-kolevska d9d0694
Remove unneeded lines. Added an examples.json file
elena-kolevska fe568e9
Update readme for examples
elena-kolevska 4cdcb77
More fixes
elena-kolevska a51b785
Add example tags
elena-kolevska 1f1ac7e
Update examples.json
elena-kolevska 5b4aa9d
Rename
elena-kolevska 96884a4
Add another hide block
elena-kolevska 51fb633
Temporary test
elena-kolevska 8b0d7e5
Add example id for lpush and lrange
elena-kolevska 3aca299
Update readme
elena-kolevska 0b042c1
Update output text
elena-kolevska 0ea1be9
Merge branch 'redis:master' into examples
elena-kolevska 3c23b02
Improve examples
elena-kolevska e78ebdb
Merge branch 'examples' of github.com:elena-kolevska/go-redis into ex…
elena-kolevska b40181f
Merge branch 'master' into examples
elena-kolevska 6450c2f
Move examples test dir to doctests
elena-kolevska 7bd87c3
Add redis v7's ExpireAtNX, ExpireAtXX, ExpireAtGT, ExpireAtLT, PExpir…
carner af12cb6
add tests for new commands
carner 90420e8
Adds github workflow to add docexamples tests. Flushes db before ever…
elena-kolevska 69480ed
Merge branch 'master' into examples
elena-kolevska c503772
Fixes broken workflow file
elena-kolevska 22ff268
Adds Igor’s suggestion of keeping the instructions for docexamples in…
elena-kolevska 261a30e
Removes unneeded “Missing” section, because it was solved as a workflow
elena-kolevska 84f7f0f
Revert "add tests for new commands"
elena-kolevska e08ae3c
Fixes review comments
elena-kolevska 5fc0663
Specifies versions as strings instead of floats
elena-kolevska f34e395
Merge branch 'master' into examples
elena-kolevska d387bb1
Merge branch 'master' into examples
elena-kolevska 2bbd541
Merge branch 'master' into examples
elena-kolevska File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Documentation Tests | ||
|
||
on: | ||
push: | ||
branches: [master, examples] | ||
pull_request: | ||
branches: [master, examples] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
doctests: | ||
name: doctests | ||
runs-on: ubuntu-latest | ||
|
||
services: | ||
redis-stack: | ||
image: redis/redis-stack-server:latest | ||
options: >- | ||
--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 | ||
ports: | ||
- 6379:6379 | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
go-version: [ "1.18", "1.19", "1.20" ] | ||
|
||
steps: | ||
- name: Set up ${{ matrix.go-version }} | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Test doc examples | ||
working-directory: ./doctests | ||
run: go test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.rdb | ||
testdata/* | ||
.idea/ | ||
.DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Command examples for redis.io | ||
|
||
These examples appear on the [Redis documentation](https://redis.io) site as part of the tabbed examples interface. | ||
|
||
## How to add examples | ||
|
||
- Create a Go test file with a meaningful name in the current folder. | ||
- Create a single method prefixed with `Example` and write your test in it. | ||
- Determine the id for the example you're creating and add it as the first line of the file: `// EXAMPLE: set_and_get`. | ||
- We're using the [Testable Examples](https://go.dev/blog/examples) feature of Go to test the desired output has been written to stdout. | ||
|
||
### Special markup | ||
|
||
See https://github.com/redis-stack/redis-stack-website#readme for more details. | ||
|
||
## How to test the examples | ||
|
||
- Start a Redis server locally on port 6379 | ||
- CD into the `doctests` directory | ||
- Run `go test` to test all examples in the directory. | ||
- Run `go test filename.go` to test a single file | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// EXAMPLE: lpush_and_lrange | ||
// HIDE_START | ||
package example_commands_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/redis/go-redis/v9" | ||
) | ||
|
||
func ExampleLPushLRange() { | ||
ctx := context.Background() | ||
|
||
rdb := redis.NewClient(&redis.Options{ | ||
Addr: "localhost:6379", | ||
Password: "", // no password docs | ||
DB: 0, // use default DB | ||
}) | ||
|
||
// HIDE_END | ||
|
||
// REMOVE_START | ||
errFlush := rdb.FlushDB(ctx).Err() // Clear the database before each test | ||
if errFlush != nil { | ||
panic(errFlush) | ||
} | ||
// REMOVE_END | ||
|
||
listSize, err := rdb.LPush(ctx, "my_bikes", "bike:1", "bike:2").Result() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(listSize) | ||
|
||
value, err := rdb.LRange(ctx, "my_bikes", 0, -1).Result() | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(value) | ||
// HIDE_START | ||
|
||
// Output: 2 | ||
// [bike:2 bike:1] | ||
} | ||
|
||
// HIDE_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// EXAMPLE: set_and_get | ||
// HIDE_START | ||
package example_commands_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/redis/go-redis/v9" | ||
) | ||
|
||
func ExampleSetGet() { | ||
ctx := context.Background() | ||
|
||
rdb := redis.NewClient(&redis.Options{ | ||
Addr: "localhost:6379", | ||
Password: "", // no password docs | ||
DB: 0, // use default DB | ||
}) | ||
|
||
// HIDE_END | ||
|
||
// REMOVE_START | ||
errFlush := rdb.FlushDB(ctx).Err() // Clear the database before each test | ||
if errFlush != nil { | ||
panic(errFlush) | ||
} | ||
// REMOVE_END | ||
|
||
err := rdb.Set(ctx, "bike:1", "Process 134", 0).Err() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println("OK") | ||
|
||
value, err := rdb.Get(ctx, "bike:1").Result() | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("The name of the bike is %s", value) | ||
// HIDE_START | ||
|
||
// Output: OK | ||
// The name of the bike is Process 134 | ||
} | ||
|
||
// HIDE_END |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.