This topic describes the syntax, feature description, parameters, and return values of storage functions. This topic also provides examples of these functions.

shm_get

The following table describes the details about this function.
Item Description
Syntax shm_get(k)
Feature Obtains the value corresponding to the key specified by the shared memory system.
Parameter k: the value of the key that you want to obtain. Data type: string.
Return value Returns the value corresponding to the key if the function is executed. Otherwise, a value of false is returned.
Example
say(shm_set('k1', 'v1')
say(concat('k1:', shm_get('k1')))

shm_set('k2', 100, 2)
say(concat('k2:', shm_get('k2')))

shm_set('k3', true)
say(concat('k3:', shm_get('k3')))('today:', today()))
Output
k1: v1
k2: 100
k3: true
The validity period of the k2 value is 2s.

shm_set

The following table describes the details about this function.
Item Description
Syntax shm_set(k, v [, exptime])
Feature Configures a key-value pair into the shared memory system.
Parameters
  • k: the key that you want to set. Data type: string.
  • v: the value that you want to set. You can set a Boolean value, numeric value, or string value.
  • exptime: the validity period. Unit: seconds. This parameter is optional.
Return value Returns a value of true if the function is executed. Otherwise, a value of false is returned.
Example
say(shm_set('k1', 'v1')
say(concat('k1:', shm_get('k1')))

shm_set('k2', 100, 2)
say(concat('k2:', shm_get('k2')))

shm_set('k3', true)
say(concat('k3:', shm_get('k3')))('today:', today()))
Output
k1: v1
k2: 100
k3: true
The validity period of the k2 value is 2s.

shm_add

The following table describes the details about this function.
Item Description
Syntax shm_add(k, v [, exptime])
Feature Use this function in the same way as the shm_set function. However, this function configures a key-value pair into the shared memory system only if the key does not exist.
Parameters
  • k: the key that you want to set. Data type: string.
  • v: the value that you want to set. You can set a Boolean value, numeric value, or string value.
  • exptime: the validity period. Unit: seconds. This parameter is optional.
Return value Returns a value of true if the function is executed. Otherwise, a value of false is returned.
Example
say(concat('k5 add 1st:', shm_add('k5', 10)))
say(concat('k5 get 1st:', shm_get('k5')))
say(concat('k5 add 2nd:', shm_add('k5', 10, 2)))
say(concat('k5 get 2nd:', shm_get('k5')))
Output
k5 add 1st: true
k5 add 1st: 10
k5 add 2nd: false
k5 get 2nd: 10

shm_del

The following table describes the details about this function.
Item Description
Syntax shm_del(k)
Feature Deletes a key-value pair from the shared memory system.
Parameter k: the key that you want to delete.
Return value Always returns a value of true.
Example
shm_del('k3')

shm_incr

The following table describes the details about this function.
Item Description
Syntax shm_incr(k, step [, init])
Feature Atomically and automatically increments the numeric value corresponding to the key in the shared memory system.
Parameters
  • k: the key to be automatically incremented. Data type: string.
  • step: the step to be automatically incremented. Data type: numeric.
  • init: Assume that the key does not exist.
    • If you do not specify the init parameter, a value of false is returned.
    • If you specify the init parameter, a key-value pair is created in the shared memory system. The value is the sum of the values of the init and step parameters.
    • Data type: numeric.
Return value Returns a value of true if the function is executed. Otherwise, a value of false is returned.
Example
say(concat('shm2_k1 incr 1st:', shm_incr('shm2_k1', 10)))                                                                                                                         
say(concat('shm2_k1 incr 2nd:', shm_incr('shm2_k2', 10, 10)))                                                                                                                     
Output
shm2_k1 incr 1st: false
shm2_k1 incr 2nd: 20

redis_get

The following table describes the details about this function.
Item Description
Syntax redis_get(k)
Feature Obtains the value of the key specified in the ApsaraDB for Redis nodes.
Parameter k: the value of the key that you want to obtain.
Return value Returns a value of true if the function is executed. Otherwise, a value of false is returned.
Example
say(concat('get k1: ', redis_get('k1')))                                                                                                                                          
say(concat('set k1: ', redis_set('k1', 'v1', 2)))                                                                                                                                 
say(concat('get k1: ', redis_get('k1')))                                                                                                                                          

say(concat('get k2: ', redis_get('k2')))                                                                                                                                          
say(concat('set k2(ttl 2): ', redis_set('k2', 'v2', 2)))                                                                                                                          
say(concat('get k2: ', redis_get('k2')))                                                                                                                   
Output
get k1: false
set k1: true
get k1: v1
get k2: false
set k2(ttl 2): true
get k2: v2

redis_set

The following table describes the details about this function.
Item Description
Syntax redis_set(k, v [, exptime])
Feature Configures a key-value pair into the ApsaraDB for Redis nodes.
Parameters
  • k: the key that you want to set. Data type: string.
  • v: the value that you want to set. You can set a Boolean value, numeric value, or string value.
  • exptime: the validity period. Unit: seconds. This parameter is optional.
Return value Returns a value of true if the function is executed. Otherwise, a value of false is returned.
Example
say(concat('get k1: ', redis_get('k1')))                                                                                                                                          
say(concat('set k1: ', redis_set('k1', 'v1', 2)))                                                                                                                                 
say(concat('get k1: ', redis_get('k1')))                                                                                                                                          

say(concat('get k2: ', redis_get('k2')))                                                                                                                                          
say(concat('set k2(ttl 2): ', redis_set('k2', 'v2', 2)))                                                                                                                          
say(concat('get k2: ', redis_get('k2')))                                                                                                                   
Output
get k1: false
set k1: true
get k1: v1
get k2: false
set k2(ttl 2): true
get k2: v2