Java Code Examples for org.redisson.api.RMapCache#fastPut()

The following examples show how to use org.redisson.api.RMapCache#fastPut() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriterFastPutTTL() {
    Map<String, String> store = new HashMap<>();
    RMapCache<String, String> map = (RMapCache<String, String>) getWriterTestMap("test", store);

    map.fastPut("1", "11", 10, TimeUnit.SECONDS);
    map.fastPut("2", "22", 10, TimeUnit.SECONDS);
    map.fastPut("3", "33", 10, TimeUnit.SECONDS);
    
    Map<String, String> expected = new HashMap<>();
    expected.put("1", "11");
    expected.put("2", "22");
    expected.put("3", "33");
    assertThat(store).isEqualTo(expected);
    map.destroy();
}
 
Example 2
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFastPutTTL() throws InterruptedException {
    RMapCache<SimpleKey, SimpleValue> map = redisson.getMapCache("getAll");
    map.trySetMaxSize(1);
    map.fastPut(new SimpleKey("1"), new SimpleValue("3"), 5, TimeUnit.SECONDS, 0, TimeUnit.SECONDS);
    Thread.sleep(5000);
    assertThat(map.get(new SimpleKey("1"))).isNull();

    map.fastPut(new SimpleKey("1"), new SimpleValue("4"), 5, TimeUnit.SECONDS, 0, TimeUnit.SECONDS);
    Thread.sleep(10000);
    assertThat(map.get(new SimpleKey("1"))).isNull();
}
 
Example 3
Source File: FileUtils.java    From kkFileViewOfficeEdit with Apache License 2.0 4 votes vote down vote up
public void addConvertedFile(String fileName, String value){
    RMapCache<String, String> convertedList = redissonClient.getMapCache(REDIS_FILE_PREVIEW_PDF_KEY);
    convertedList.fastPut(fileName, value);
}
 
Example 4
Source File: CacheServiceRedisImpl.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
@Override
public void putPDFCache(String key, String value) {
    RMapCache<String, String> convertedList = redissonClient.getMapCache(FILE_PREVIEW_PDF_KEY);
    convertedList.fastPut(key, value);
}
 
Example 5
Source File: CacheServiceRedisImpl.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
@Override
public void putImgCache(String key, List<String> value) {
    RMapCache<String, List<String>> convertedList = redissonClient.getMapCache(FILE_PREVIEW_IMGS_KEY);
    convertedList.fastPut(key, value);
}
 
Example 6
Source File: CacheServiceRedisImpl.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
@Override
public void putPdfImageCache(String pdfFilePath, int num) {
    RMapCache<String, Integer> convertedList = redissonClient.getMapCache(FILE_PREVIEW_PDF_IMGS_KEY);
    convertedList.fastPut(pdfFilePath, num);
}
 
Example 7
Source File: MapCacheExamples.java    From redisson-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    RMapCache<String, Integer> mapCache = redisson.getMapCache("test");
    
    // with ttl = 10 seconds
    Integer prevValue = mapCache.put("1", 10, 10, TimeUnit.SECONDS);
    // with ttl = 15 seconds and maxIdleTime = 5 seconds
    Integer prevValue2 = mapCache.put("2", 20, 15, TimeUnit.SECONDS, 5, TimeUnit.SECONDS);
    // store value permanently 
    Integer prevValue3 = mapCache.put("3", 30);
    
    // with ttl = 30 seconds
    Integer currValue = mapCache.putIfAbsent("4", 40, 30, TimeUnit.SECONDS);
    // with ttl = 40 seconds and maxIdleTime = 10 seconds
    Integer currValue2 = mapCache.putIfAbsent("5", 50, 40, TimeUnit.SECONDS, 10, TimeUnit.SECONDS);
    // try to add new key-value permanently 
    Integer currValue3 = mapCache.putIfAbsent("6", 60);
    
    // use fast* methods when previous value is not required

    // with ttl = 20 seconds
    boolean isNewKey1 = mapCache.fastPut("7", 70, 20, TimeUnit.SECONDS);
    // with ttl = 40 seconds and maxIdleTime = 20 seconds
    boolean isNewKey2 = mapCache.fastPut("8", 80, 40, TimeUnit.SECONDS, 20, TimeUnit.SECONDS);
    // store value permanently 
    boolean isNewKey3 = mapCache.fastPut("9", 90);
    
    // try to add new key-value permanently
    boolean isNewKeyPut = mapCache.fastPutIfAbsent("10", 100);

    boolean contains = mapCache.containsKey("a");
    
    Integer value = mapCache.get("c");
    Integer updatedValue = mapCache.addAndGet("a", 32);
    
    Integer valueSize = mapCache.valueSize("c");
    
    Set<String> keys = new HashSet<String>();
    keys.add("a");
    keys.add("b");
    keys.add("c");
    Map<String, Integer> mapSlice = mapCache.getAll(keys);
    
    // use read* methods to fetch all objects
    Set<String> allKeys = mapCache.readAllKeySet();
    Collection<Integer> allValues = mapCache.readAllValues();
    Set<Entry<String, Integer>> allEntries = mapCache.readAllEntrySet();
    
    redisson.shutdown();
}
 
Example 8
Source File: FileUtils.java    From kkFileViewOfficeEdit with Apache License 2.0 2 votes vote down vote up
/**
 * 设置redis中压缩包内图片文件
 * @param fileKey
 * @param imgs
 */
public void setRedisImgUrls(String fileKey,List imgs){
    RMapCache<String, List> convertedList = redissonClient.getMapCache(REDIS_FILE_PREVIEW_IMGS_KEY);
     convertedList.fastPut(fileKey,imgs);
}