Skip to content

Commit 896e225

Browse files
committed
docs: add more examples to rueidiscompat
Signed-off-by: Rueian <[email protected]>
1 parent af513ad commit 896e225

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

valkeycompat/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,45 @@ func main() {
166166
}
167167
```
168168

169+
### Lua script example
170+
171+
```golang
172+
package main
173+
174+
import (
175+
"context"
176+
"fmt"
177+
"github.com/valkey-io/valkey-go"
178+
"github.com/valkey-io/valkey-go/valkeycompat"
179+
)
180+
181+
var incrBy = valkeycompat.NewScript(`
182+
local key = KEYS[1]
183+
local change = ARGV[1]
184+
local value = redis.call("GET", key)
185+
if not value then
186+
value = 0
187+
end
188+
value = value + change
189+
redis.call("SET", key, value)
190+
return value
191+
`)
192+
193+
func main() {
194+
ctx := context.Background()
195+
client, err := valkey.NewClient(valkey.ClientOption{InitAddress: []string{"127.0.0.1:6379"}})
196+
if err != nil {
197+
panic(err)
198+
}
199+
defer client.Close()
200+
201+
rdb := valkeycompat.NewAdapter(client)
202+
keys := []string{"my_counter"}
203+
values := []interface{}{+1}
204+
fmt.Println(incrBy.Run(ctx, rdb, keys, values...).Int())
205+
}
206+
```
207+
169208
### Methods not yet implemented in the adapter
170209

171210
* `HExpire`, `HPExpire`, `HTTL`, and `HPTTL` related methods.

0 commit comments

Comments
 (0)