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

Function ExampleScript

example_test.go:592–613  ·  example_test.go::ExampleScript
()

Source from the content-addressed store, hash-verified

590}
591
592func ExampleScript() {
593 IncrByXX := redis.NewScript(`
594 if redis.call("GET", KEYS[1]) ~= false then
595 return redis.call("INCRBY", KEYS[1], ARGV[1])
596 end
597 return false
598 `)
599
600 n, err := IncrByXX.Run(ctx, rdb, []string{"xx_counter"}, 2).Result()
601 fmt.Println(n, err)
602
603 err = rdb.Set(ctx, "xx_counter", "40", 0).Err()
604 if err != nil {
605 panic(err)
606 }
607
608 n, err = IncrByXX.Run(ctx, rdb, []string{"xx_counter"}, 2).Result()
609 fmt.Println(n, err)
610
611 // Output: <nil> redis: nil
612 // 42 <nil>
613}
614
615func Example_customCommand() {
616 Get := func(ctx context.Context, rdb *redis.Client, key string) *redis.StringCmd {

Callers

nothing calls this directly

Calls 4

RunMethod · 0.95
ResultMethod · 0.65
ErrMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected