File tree Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ // EXAMPLE: cmds_set
2+ // HIDE_START
3+ package example_commands_test
4+
5+ import (
6+ "context"
7+ "fmt"
8+
9+ "github.com/redis/go-redis/v9"
10+ )
11+
12+ // HIDE_END
13+
14+ func ExampleClient_sadd_cmd () {
15+ ctx := context .Background ()
16+
17+ rdb := redis .NewClient (& redis.Options {
18+ Addr : "localhost:6379" ,
19+ Password : "" , // no password docs
20+ DB : 0 , // use default DB
21+ })
22+
23+ // REMOVE_START
24+ rdb .Del (ctx , "myset" )
25+ // REMOVE_END
26+
27+ // STEP_START sadd
28+ sAddResult1 , err := rdb .SAdd (ctx , "myset" , "Hello" ).Result ()
29+
30+ if err != nil {
31+ panic (err )
32+ }
33+
34+ fmt .Println (sAddResult1 ) // >>> 1
35+
36+ sAddResult2 , err := rdb .SAdd (ctx , "myset" , "World" ).Result ()
37+
38+ if err != nil {
39+ panic (err )
40+ }
41+
42+ fmt .Println (sAddResult2 ) // >>> 1
43+
44+ sAddResult3 , err := rdb .SAdd (ctx , "myset" , "World" ).Result ()
45+
46+ if err != nil {
47+ panic (err )
48+ }
49+
50+ fmt .Println (sAddResult3 ) // >>> 0
51+
52+ sAddResult4 , err := rdb .SMembers (ctx , "myset" ).Result ()
53+
54+ if err != nil {
55+ panic (err )
56+ }
57+
58+ fmt .Println (sAddResult4 ) // >>> [Hello World]
59+ // STEP_END
60+
61+ // Output:
62+ // 1
63+ // 1
64+ // 0
65+ // [Hello World]
66+ }
You can’t perform that action at this time.
0 commit comments