All Products
Search
Document Center

ApsaraVideo VOD:Logical functions

Last Updated:Jul 10, 2026

Logical functions evaluate conditions and return Boolean results. Available functions: and, or, not, eq, ne, and null.

and

The following table describes the and function.
Item Description
Syntax and(arg, ...)
Benefit
  • Performs a logical AND operation.
  • Supports short-circuit evaluation. If any argument evaluates to false, subsequent arguments are not evaluated.
Parameter One or more arguments of any type.
Return value Returns true if all values evaluate to true and returns false if a value evaluates to false.
Example
if and($arg_mode, eq($arg_mode, 'set_header')) {
   add_rsp_header('USER-DEFINED-1','path1')
}
  • a. If the request includes the mode parameter and the value of the mode parameter is set_header, set the USER-DEFINED-1 response header.
  • b. If the request does not include the mode parameter, the short-circuit evaluation takes effect and the eq comparison operator is not executed. The response header USER-DEFINED-1 will not be set because the and() function returns a value of false.

or

The following table describes the or function.
Item Description
Syntax or(arg, ...).
Description
  • A logical OR operator.
  • Supports short-circuit evaluation. If an argument evaluates to true, subsequent arguments are not evaluated.
Parameter One or more arguments of any type.
Return value Returns true if any argument is true. Otherwise, returns false.
Example
if and($http_from, or(eq($http_from, 'wap'), eq($http_from, 'comos'))) {
    rewrite(concat('http://example.com.cn/zt_d/we2015/', $http_from), 'enhance_redirect')
}
  • If the from request header exists and its value is either wap or comos, the request is redirected with a 302 status. The script forms the target URL by concatenating http://example.com.cn/zt_d/we2015/ and the value of the from header.
  • If the from request header has the value wap, short-circuit evaluation occurs, skipping the subsequent comparison with comos. The or() function then returns true.

not

The following table describes the not function.
Item Description
Syntax not(arg)
Description Performs a logical NOT operation. undef and false evaluate to false. All other values evaluate to true.
Parameter One argument of any type.
Return value
  • true
  • false
Example
if not($arg_key) {
    exit(403)
}
if not($cookie_user) {
    exit(403, 'not cookie user')
}
if not(0) {
    exit(403)
}
if not(false) {
    exit(403)
}
  • If a request does not include the key parameter, the request is denied and the HTTP 403 status code is returned.
  • If a request does not include cookie_user, the request is denied. The HTTP 403 status code and the response body "not cookie user" are returned.
  • The not(0) function returns a value of false.
  • The not(false) function returns a value of true.

eq

The following table describes the eq function.
Item Description
Syntax eq(arg1, arg2)
Description Checks whether two values are equal.
Parameter
  • arg1: the first value to compare. Data type: any type.
  • arg2: the second value to compare. Data type: same as the arg1 parameter.
Return value Returns true if the two values are equal and returns false if they are not equal.
Example
key1 = 'value1'
key2 = 'value2'
if and($arg_k1, $arg_k2, eq(key1, $arg_k1), ne(key2, $arg_k2)) {
    say('match condition')
}
  • a. If the request includes both the k1 and k2 parameters, the comparison operations are performed.
  • b. If the request does not include the k1 or k2 parameter, the short-circuit evaluation takes effect and the comparison operations are not performed.
  • eq: c. eq: whether the value of the k1 parameter is equal to value1.
  • ne: d. ne: whether the value of the k2 parameter is not equal to value2.
  • e. The response that contains the response body "match condition" is returned only if the following conditions are met: the request includes both the k1 and k2 parameters, the value of the k1 parameter is equal to value1, and the value of the k2 parameter is not equal to value2.

ne

The following table describes the ne function.
Item Description
Syntax ne(arg1, arg2)
Description Checks whether two values are not equal.
Parameter
  • arg1: the first value to compare. Data type: any type.
  • arg2: the second value to compare. Data type: same as the arg1 parameter.
Return value Returns true if the two values are not equal and returns false if they are equal.
Example
key1 = 'value1'
key2 = 'value2'
if and($arg_k1, $arg_k2, eq(key1, $arg_k1), ne(key2, $arg_k2)) {
    say('match condition')
}
  • a. If the request includes both the k1 and k2 parameters, the comparison operations are performed.
  • b. If the request does not include the k1 or k2 parameter, the short-circuit evaluation takes effect and the comparison operations are not performed.
  • eq: c. eq: whether the value of the k1 parameter is equal to value1.
  • ne: d. ne: whether the value of the k2 parameter is not equal to value2.
  • e. The response that contains the response body "match condition" is returned only if the following conditions are met: the request includes both the k1 and k2 parameters, the value of the k1 parameter is equal to value1, and the value of the k2 parameter is not equal to value2.

null

The following table describes the null function.
Item Description
Syntax null(v)
Benefit Checks whether a data type is specified for EdgeScript (ES).
Filed v: the parameter to pass. Data type: array, dictionary, or string. A value of false is returned for other data types.
Return value Data type: Boolean.
  • A value of true is returned if the value of v is an array or a dictionary.
  • A value of true is returned if the value of v is an empty string.
  • A value of false is returned if v is set to other data types.
Examples
d = []
say(null(d))
set(d, 1, 'v1')
say(null(d))
say(tostring(null('x')))
say(tostring(null('')))
Output:
true
false
false
true