redis_lock.go 406 字节
package redis

import (
	"context"
	"fmt"

	"github.com/go-redis/redis/v8"
)

var demoScript = redis.NewScript(`
	if redis.call("GET", KEYS[1]) == ARGV[1] then
		return 1
	else
		return 0
	end`)

func RunDemoScript() string {
	result := demoScript.Run(context.TODO(), rdb, []string{"demokey"}, "4564")
	err := result.Err()
	if err != nil {
		return err.Error()
	}
	return fmt.Sprintf("%v", result.Val())
}