File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff 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/redis/rueidis"
178+ " github.com/redis/rueidis/rueidiscompat"
179+ )
180+
181+ var incrBy = rueidiscompat.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 := rueidis.NewClient (rueidis.ClientOption {InitAddress: []string {" 127.0.0.1:6379" }})
196+ if err != nil {
197+ panic (err)
198+ }
199+ defer client.Close ()
200+
201+ rdb := rueidiscompat.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.
You can’t perform that action at this time.
0 commit comments