Skip to content

Commit deeb641

Browse files
lvan100lianghuan
authored andcommitted
feat(redis): add example
1 parent 984b9a9 commit deeb641

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Refer to the [example.go](example/example.go) file.
4949

5050
```go
5151
str, err := s.Redis.Get(r.Context(), "key").Result()
52-
_ = s.Redis.Set(r.Context(), "key", "value", 0).Err()
52+
str, err := s.Redis.Set(r.Context(), "key", "value", 0).Result()
5353
```
5454

5555
## Advanced Features

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Service struct {
4949

5050
```go
5151
str, err := s.Redis.Get(r.Context(), "key").Result()
52-
_ = s.Redis.Set(r.Context(), "key", "value", 0).Err()
52+
str, err := s.Redis.Set(r.Context(), "key", "value", 0).Result()
5353
```
5454

5555
## 高级功能

example/example.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ func main() {
5050
})
5151

5252
http.HandleFunc("/set", func(w http.ResponseWriter, r *http.Request) {
53-
_ = s.Redis.Set(r.Context(), "key", "value", 0).Err()
54-
_, _ = w.Write([]byte("ok"))
53+
str, err := s.Redis.Set(r.Context(), "key", "value", 0).Result()
54+
if err != nil {
55+
_, _ = w.Write([]byte(err.Error()))
56+
return
57+
}
58+
_, _ = w.Write([]byte(str))
5559
})
5660

5761
gs.Run()
@@ -61,7 +65,7 @@ func main() {
6165
// ~ curl http://127.0.0.1:9090/get
6266
// redis: nil%
6367
// ~ curl http://127.0.0.1:9090/set
64-
// ok%
68+
// OK%
6569
// ~ curl http://127.0.0.1:9090/get
6670
// value%
6771
}

0 commit comments

Comments
 (0)