Updated on 2023-10-10 GMT+08:00

RedisClient

Path

com.roma.apic.livedata.client.v1.RedisClient

Description

This class is used to connect to the Redis or read the Redis cache. If JedisConfig is not specified, connect to the default Redis provided by the function API of the custom backend.

Example

importClass(com.roma.apic.livedata.client.v1.RedisClient);
function execute(data) {
    var redisClient = new RedisClient;
    var count = redisClient.get("visit_count")
    if (!count)
    {
        redisClient.put("visit_count", 1);
    }else {
        redisClient.put("visit_count", parseInt(count) + 1);
    }
    return redisClient.get("visit_count");
}

Constructor Details

public RedisClient()

Constructs a RedisClient and connects it to the default Redis provided by the function API (livedata) of the custom backend.

public RedisClient(JedisConfig jedisConfig)

Constructs a RedisClient using jedisConfig.

Parameter jedisConfig indicates the RedisClient information.

Method List

Returned Type

Method and Description

String

get(String key)

Obtain the value corresponding to the key in the Redis cache.

String

put(String key, int expireTime, String value)

Update the Redis cache content and expiration time, and return the execution result.

String

put(String key, String value)

Update the Redis cache content and return the execution result.

Long

remove(String key)

Delete cached messages of a specified key value.

Method Details

  • public String get(String key)

    Obtain the value corresponding to the key in the Redis cache.

    Input Parameter

    key indicates the key value.

    Returns

    Obtain the value of the key in the Redis cache.

  • public String put(String key, int expireTime, String value)

    Update the Redis cache and expiration time.

    Input Parameter

    • key indicates the key value of the cache to be updated.
    • expireTime indicates the expiration time of the cache content to be updated, in seconds.
    • value indicates the value of the cache to be updated.

    Returns

    Execution result.

  • public String put(String key, String value)

    Update the Redis cache.

    Input Parameter

    • key indicates the key value of the cache to be updated.
    • value indicates the value of the cache to be updated.

    Returns

    Execution result.

  • public Long remove(String key)

    Delete cached messages of a specified key value.

    Input Parameter

    key indicates the key value of the cache to be deleted.

    Returns

    Execution result.