...
1
2
3 package example_commands_test
4
5 import (
6 "context"
7 "fmt"
8 "time"
9
10 "github.com/redis/go-redis/v9"
11 )
12
13 func ExampleClient_LPush_and_lrange() {
14 ctx := context.Background()
15
16 rdb := redis.NewClient(&redis.Options{
17 Addr: "localhost:6379",
18 Password: "",
19 DB: 0,
20 })
21
22
23
24
25 errFlush := rdb.FlushDB(ctx).Err()
26 if errFlush != nil {
27 panic(errFlush)
28 }
29
30
31 listSize, err := rdb.LPush(ctx, "my_bikes", "bike:1", "bike:2").Result()
32 if err != nil {
33 panic(err)
34 }
35
36 fmt.Println(listSize)
37 time.Sleep(10 * time.Millisecond)
38
39 value, err := rdb.LRange(ctx, "my_bikes", 0, -1).Result()
40 if err != nil {
41 panic(err)
42 }
43 fmt.Println(value)
44
45
46
47
48 }
49
50
51
View as plain text