redis_lock.go
396 字节
package redis
import (
"context"
"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()
}
val, _ := result.Text()
return val
}