Search in sources :

Example 1 with SetArgs

use of com.lambdaworks.redis.SetArgs in project moleculer-java by moleculer-java.

the class RedisCacher method set.

@Override
public Promise set(String key, Tree value, int ttl) {
    if (status.get() == STATUS_CONNECTED) {
        try {
            SetArgs args;
            if (ttl > 0) {
                // Entry-level TTL (in seconds)
                args = SetArgs.Builder.ex(ttl);
            } else {
                // Use the default TTL
                args = expiration;
            }
            Tree root = new CheckedTree(Collections.singletonMap(CONTENT, value.asObject()));
            return client.set(key, serializer.write(root), args);
        } catch (Exception cause) {
            logger.warn("Unable to put data into Redis!", cause);
        }
    }
    return Promise.resolve();
}
Also used : CheckedTree(services.moleculer.util.CheckedTree) CheckedTree(services.moleculer.util.CheckedTree) Tree(io.datatree.Tree) SetArgs(com.lambdaworks.redis.SetArgs)

Aggregations

SetArgs (com.lambdaworks.redis.SetArgs)1 Tree (io.datatree.Tree)1 CheckedTree (services.moleculer.util.CheckedTree)1