Skip to content

Commit

Permalink
docs: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dnjooiopa committed Jun 27, 2023
1 parent fb3a961 commit f70447f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ func main() {
pwd := ""
db := 3

rc, ctx := rdctx.NewWithContext(context.Background(), host, pwd, db)
defer rc.Close()
// init
client, ctx := rdctx.NewWithContext(context.Background(), host, pwd, db)
defer client.Close()

if err := rc.ConnOK(); err != nil {
// Check if connection is ok
if err := client.ConnOK(); err != nil {
log.Println("cannot connect to redis:", err)
}
log.Println("redis connected")
Expand All @@ -33,10 +35,13 @@ func main() {
}

func performTask(ctx context.Context) {
if _, err := rdctx.Set(ctx, "foo", "bar"); err != nil {
// Set key-value
_, err := rdctx.Set(ctx, "foo", "bar")
if err != nil {
log.Println("cannot set key to redis:", err)
}

// Get value from key
v, err := rdctx.Get(ctx, "foo")
if err != nil {
log.Println("cannot get key from redis:", err)
Expand All @@ -48,7 +53,7 @@ func performTask(ctx context.Context) {
#### Inject to echo middleware

```go
e.Use(echo.WrapMiddleware(rdctx.Middleware(rc))) // rc is a *rdctx.Client
e.Use(echo.WrapMiddleware(rdctx.Middleware(client)))
```

#### Set multiple key-value pairs with a single command
Expand Down

0 comments on commit f70447f

Please sign in to comment.