MCPcopy
hub / github.com/redis/go-redis / main

Function main

example/lua-scripting/main.go:10–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8)
9
10func main() {
11 ctx := context.Background()
12
13 rdb := redis.NewClient(&redis.Options{
14 Addr: ":6379",
15 })
16 _ = rdb.FlushDB(ctx).Err()
17
18 fmt.Printf("# INCR BY\n")
19 for _, change := range []int{+1, +5, 0} {
20 num, err := incrBy.Run(ctx, rdb, []string{"my_counter"}, change).Int()
21 if err != nil {
22 panic(err)
23 }
24 fmt.Printf("incr by %d: %d\n", change, num)
25 }
26
27 fmt.Printf("\n# SUM\n")
28 sum, err := sum.Run(ctx, rdb, []string{"my_sum"}, 1, 2, 3).Int()
29 if err != nil {
30 panic(err)
31 }
32 fmt.Printf("sum is: %d\n", sum)
33}
34
35var incrBy = redis.NewScript(`
36local key = KEYS[1]

Callers

nothing calls this directly

Calls 5

ErrMethod · 0.65
FlushDBMethod · 0.65
PrintfMethod · 0.65
IntMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected