-
Notifications
You must be signed in to change notification settings - Fork 2.5k
DOC-4494 SADD and SMEMBERS command examples #3242
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
ndyakov
merged 16 commits into
redis:master
from
andy-stark-redis:DOC-4494-set-cmd-examples
Mar 19, 2025
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
538eba8
DOC-4494 added sadd example
andy-stark-redis 9fd5e1d
DOC-4494 sadd and smembers examples
andy-stark-redis 56237bb
Merge branch 'master' into DOC-4494-set-cmd-examples
andy-stark-redis 690f492
Merge branch 'master' into DOC-4494-set-cmd-examples
andy-stark-redis 81a84e2
Merge branch 'master' into DOC-4494-set-cmd-examples
andy-stark-redis d58fe47
Merge branch 'master' into DOC-4494-set-cmd-examples
ndyakov e667d5d
Merge branch 'master' into DOC-4494-set-cmd-examples
andy-stark-redis c2d224e
Merge branch 'master' into DOC-4494-set-cmd-examples
ndyakov 171b83a
Merge branch 'master' into DOC-4494-set-cmd-examples
andy-stark-redis 2bf2195
Merge branch 'master' into DOC-4494-set-cmd-examples
andy-stark-redis a5d202b
DOC-4494 better naming convention for result variables
andy-stark-redis beef535
Merge branch 'master' into DOC-4494-set-cmd-examples
andy-stark-redis 55b65d3
Merge branch 'master' into DOC-4494-set-cmd-examples
ndyakov 9b90e09
Merge branch 'master' into DOC-4494-set-cmd-examples
ndyakov 974664e
Merge branch 'master' into DOC-4494-set-cmd-examples
ndyakov 252ab1d
Merge branch 'master' into DOC-4494-set-cmd-examples
ndyakov 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,102 @@ | ||
// EXAMPLE: cmds_set | ||
// HIDE_START | ||
package example_commands_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/redis/go-redis/v9" | ||
) | ||
|
||
// HIDE_END | ||
|
||
func ExampleClient_sadd_cmd() { | ||
ctx := context.Background() | ||
|
||
rdb := redis.NewClient(&redis.Options{ | ||
Addr: "localhost:6379", | ||
Password: "", // no password docs | ||
DB: 0, // use default DB | ||
}) | ||
|
||
// REMOVE_START | ||
rdb.Del(ctx, "myset") | ||
// REMOVE_END | ||
|
||
// STEP_START sadd | ||
sAddResult1, err := rdb.SAdd(ctx, "myset", "Hello").Result() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(sAddResult1) // >>> 1 | ||
|
||
sAddResult2, err := rdb.SAdd(ctx, "myset", "World").Result() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(sAddResult2) // >>> 1 | ||
|
||
sAddResult3, err := rdb.SAdd(ctx, "myset", "World").Result() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(sAddResult3) // >>> 0 | ||
|
||
sAddResult4, err := rdb.SMembers(ctx, "myset").Result() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(sAddResult4) // >>> [Hello World] | ||
// STEP_END | ||
|
||
// Output: | ||
// 1 | ||
// 1 | ||
// 0 | ||
// [Hello World] | ||
} | ||
|
||
func ExampleClient_smembers_cmd() { | ||
ctx := context.Background() | ||
|
||
rdb := redis.NewClient(&redis.Options{ | ||
Addr: "localhost:6379", | ||
Password: "", // no password docs | ||
DB: 0, // use default DB | ||
}) | ||
|
||
// REMOVE_START | ||
rdb.Del(ctx, "myset") | ||
// REMOVE_END | ||
|
||
// STEP_START smembers | ||
sMembersResult1, err := rdb.SAdd(ctx, "myset", "Hello", "World").Result() | ||
ndyakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(sMembersResult1) // >>> 2 | ||
|
||
sMembersResult2, err := rdb.SMembers(ctx, "myset").Result() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(sMembersResult2) // >>> [Hello World] | ||
// STEP_END | ||
|
||
// Output: | ||
// 2 | ||
// [Hello World] | ||
} |
Oops, something went wrong.
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.