简体   繁体   English

如何声明一个持久化子程序的变量

[英]How to declare a variable that persists subroutines

During the recv subroutine I am currently changing my backend to another backend to handle the request, I need to declare a variable that will hold the value for the first/original backend that it was set to, so that when the request is restarted, I can then assign the backend back to this.在 recv 子例程中,我目前正在将我的后端更改为另一个后端来处理请求,我需要声明一个变量,该变量将保存它设置的第一个/原始后端的值,以便在请求重新启动时,我然后可以将后端分配回此。

I can't just use the name for the backend and simply assign it back as I need it to be dynamic, storing it in a variable seems like the simplest solution but I can't seem to find any information on how this can be achieved through subroutines/ restarts.我不能只使用后端的名称并简单地将其分配回来,因为我需要它是动态的,将它存储在变量中似乎是最简单的解决方案,但我似乎无法找到有关如何实现的任何信息通过子程序/重新启动。

If not possible are there any other solutions I could try to achieve this?如果不可能,是否还有其他解决方案可以尝试实现这一目标? Probably not possible from what I understand but even the ability to access an array of the backends defined and picking the first one would suffice, I just cant rely on naming the backend to assign it back.根据我的理解,可能不可能,但即使能够访问定义的后端数组并选择第一个就足够了,我只是不能依靠命名后端来将其分配回来。

Unfortunately it isn't possible to declare a variable as a BACKEND type (which is what req.backend returns).不幸的是,不可能将变量声明为BACKEND类型(这是req.backend返回的内容)。

See this 'Fastly Fiddle' example that demonstrates you'll get a compiler error of:请参阅此“Fastly Fiddle”示例,该示例演示您将收到以下编译器错误:

Expected variable type, one of: BOOL, INTEGER, FLOAT, TIME, RTIME, IP or STRING预期的变量类型,以下之一:BOOL、INTEGER、FLOAT、TIME、RTIME、IP 或 STRING

There also isn't any way to get a list of available backends via VCL either.也没有任何方法可以通过 VCL 获取可用后端列表。

Additionally you would need to hardcode the backend value (ie you need to explicitly know what backends are defined from the VCL perspective) as trying to store a backend into a header or variable will convert it to a STRING type representation (such as 6kLtu7NicmMs0DtKsuite9--F_origin_0 ).此外,您需要对后端值进行硬编码(即您需要明确知道从 VCL 角度定义了哪些后端),因为尝试将后端存储到标头或变量中会将其转换为 STRING 类型表示(例如6kLtu7NicmMs0DtKsuite9--F_origin_0 )。

This means even if you were able to parse the actual F_origin_0 backend from the string you wouldn't be able to assign it as a value to req.backend as that expects the value to be of type BACKEND (and VCL doesn't provide a way, AFAIK, to convert a string into that type).这意味着即使您能够从字符串中解析实际的F_origin_0后端,您也无法将其作为值分配给req.backend因为它期望该值的类型为BACKEND (并且 VCL 不提供方式,AFAIK,将字符串转换为该类型)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM