Search in sources :

Example 1 with LocalCachedMapEnable

use of org.redisson.cache.LocalCachedMapEnable in project redisson by redisson.

the class RedissonTransaction method enableLocalCache.

private void enableLocalCache(String requestId, Map<HashKey, HashValue> hashes) {
    if (hashes.isEmpty()) {
        return;
    }
    RedissonBatch publishBatch = createBatch();
    for (Entry<HashKey, HashValue> entry : hashes.entrySet()) {
        String name = RedissonObject.suffixName(entry.getKey().getName(), RedissonLocalCachedMap.TOPIC_SUFFIX);
        RTopicAsync topic = publishBatch.getTopic(name, LocalCachedMessageCodec.INSTANCE);
        LocalCachedMapEnable msg = new LocalCachedMapEnable(requestId, entry.getValue().getKeyIds().toArray(new byte[entry.getValue().getKeyIds().size()][]));
        topic.publishAsync(msg);
    }
    try {
        publishBatch.execute();
    } catch (Exception e) {
    // skip it. Disabled local cache entries are enabled once reach timeout.
    }
}
Also used : RedissonBatch(org.redisson.RedissonBatch) LocalCachedMapEnable(org.redisson.cache.LocalCachedMapEnable)

Example 2 with LocalCachedMapEnable

use of org.redisson.cache.LocalCachedMapEnable in project redisson by redisson.

the class RedissonTransaction method enableLocalCacheAsync.

private RFuture<BatchResult<?>> enableLocalCacheAsync(String requestId, Map<HashKey, HashValue> hashes) {
    if (hashes.isEmpty()) {
        return RedissonPromise.newSucceededFuture(null);
    }
    RedissonBatch publishBatch = createBatch();
    for (Entry<HashKey, HashValue> entry : hashes.entrySet()) {
        String name = RedissonObject.suffixName(entry.getKey().getName(), RedissonLocalCachedMap.TOPIC_SUFFIX);
        RTopicAsync topic = publishBatch.getTopic(name, LocalCachedMessageCodec.INSTANCE);
        LocalCachedMapEnable msg = new LocalCachedMapEnable(requestId, entry.getValue().getKeyIds().toArray(new byte[entry.getValue().getKeyIds().size()][]));
        topic.publishAsync(msg);
    }
    return publishBatch.executeAsync();
}
Also used : RedissonBatch(org.redisson.RedissonBatch) LocalCachedMapEnable(org.redisson.cache.LocalCachedMapEnable)

Aggregations

RedissonBatch (org.redisson.RedissonBatch)2 LocalCachedMapEnable (org.redisson.cache.LocalCachedMapEnable)2