Skip to content

Commit

Permalink
docs: add more examples to rueidiscompat
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <[email protected]>
  • Loading branch information
rueian committed Aug 11, 2024
1 parent af513ad commit 896e225
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions valkeycompat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,45 @@ func main() {
}
```

### Lua script example

```golang
package main

import (
"context"
"fmt"
"github.com/valkey-io/valkey-go"
"github.com/valkey-io/valkey-go/valkeycompat"
)

var incrBy = valkeycompat.NewScript(`
local key = KEYS[1]
local change = ARGV[1]
local value = redis.call("GET", key)
if not value then
value = 0
end
value = value + change
redis.call("SET", key, value)
return value
`)

func main() {
ctx := context.Background()
client, err := valkey.NewClient(valkey.ClientOption{InitAddress: []string{"127.0.0.1:6379"}})
if err != nil {
panic(err)
}
defer client.Close()

rdb := valkeycompat.NewAdapter(client)
keys := []string{"my_counter"}
values := []interface{}{+1}
fmt.Println(incrBy.Run(ctx, rdb, keys, values...).Int())
}
```

### Methods not yet implemented in the adapter

* `HExpire`, `HPExpire`, `HTTL`, and `HPTTL` related methods.
Expand Down

0 comments on commit 896e225

Please sign in to comment.