重新启动Redis后,为什么我无法在Redis中运行lua脚本? [英] Why i can't run lua script in redis after redis restart?

查看:40
本文介绍了重新启动Redis后,为什么我无法在Redis中运行lua脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行Lua脚本时遇到问题,这是我在做什么:

Im having issues running a Lua script, here is what i am doing:

  1. 我使用LOAD SCRIPT将脚本加载到Redis,并获取脚本的SHA.
  2. 我用SHA测试脚本,没关系.
  3. 我执行了SAVE(BGSAVE),SHUTDOWN,然后再次运行redis服务器,但是我无法使用SHA执行脚本,

这是为什么?

推荐答案

Redis不会保存或存储服务器端Lua脚本.它们与您在RDBMS中可以找到的存储过程不同.

Server-side Lua scripts are not saved or stored by Redis. They are not similar to the stored procedures you can find in RDBMS.

客户端应该至少在首次执行脚本时提供脚本的文本(即,第一次执行时使用EVAL,下一次调用时使用EVALSHA).另外,您也可以使用SCRIPT LOAD和SCRIPT EXISTS,根据情况可能会更方便.

The clients are supposed to provide the text of the script at least for the first execution of the script (i.e. use EVAL for the first execution, and EVALSHA for the next calls). Alternatively, you can also use SCRIPT LOAD and SCRIPT EXISTS, it may be more convenient depending on the situation.

这对于应用程序来说处理起来有点复杂,但是有很多好处:就Lua脚本而言,它使Redis服务器成为无状态的.应用程序的代码(包括Lua脚本)在应用程序端进行管理.加载新版本的应用程序之前,即使在Lua脚本已更改的情况下,也不需要在Redis服务器上应用某些内容.

This is a bit more complex to handle for the application, but there are benefits: it makes the Redis server stateless regarding Lua scripting. The code of the application (including Lua scripts) is managed on application side. You do not need to apply something on the Redis server before loading a new version of the application (even if the Lua scripts have changed).

此属性在分布式基础结构的上下文中非常有用,可支持动态应用程序负载,客户端分片或Redis集群.

This property is very useful in the context of a distributed infrastructure to support on-the-fly application loads, or client-side sharding, or Redis cluster.

这篇关于重新启动Redis后,为什么我无法在Redis中运行lua脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆