当前位置: 首页>>代码示例>>Java>>正文


Java RedissonClient.getLocalCachedMap方法代码示例

本文整理汇总了Java中org.redisson.api.RedissonClient.getLocalCachedMap方法的典型用法代码示例。如果您正苦于以下问题:Java RedissonClient.getLocalCachedMap方法的具体用法?Java RedissonClient.getLocalCachedMap怎么用?Java RedissonClient.getLocalCachedMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.redisson.api.RedissonClient的用法示例。


在下文中一共展示了RedissonClient.getLocalCachedMap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mapsLocalCache2

import org.redisson.api.RedissonClient; //导入方法依赖的package包/类
void mapsLocalCache2(Waiter waiter) {
    Config config = new Config();
    config.useSingleServer().setAddress("http://127.0.0.1:6379");
    RedissonClient client = Redisson.create(config);

    LocalCachedMapOptions options = LocalCachedMapOptions.defaults().maxIdle(10 * 1000).timeToLive(10 * 1000);
    RLocalCachedMap<String, Integer> map = client.getLocalCachedMap("myMap", options);

    System.out.println("KEY BEFORE: " + map.get("key"));

    try {
        Thread.sleep(2000);
    }
    catch(InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println("KEY AFTER: " + map.get("key"));
    waiter.assertEquals(map.get("key"), 25);
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:20,代码来源:RedisTest.java

示例2: mapsItemChange2

import org.redisson.api.RedissonClient; //导入方法依赖的package包/类
void mapsItemChange2(Waiter waiter){
    Config config = new Config();
    config.useSingleServer().setAddress("http://127.0.0.1:6379");
    RedissonClient client = Redisson.create(config);

    LocalCachedMapOptions options = LocalCachedMapOptions.defaults().maxIdle(10 * 1000).timeToLive(10 * 1000);
    RLocalCachedMap<String, FinalValue<Integer>> map = client.getLocalCachedMap("myMap", options);
    FinalValue<Integer> value = map.get("test");
    System.out.println("Value Before: " + value.get());

    try {
        Thread.sleep(2000);
    }
    catch(InterruptedException e) {
        e.printStackTrace();
    }

    value = map.get("test");
    System.out.println("Value After: " + value.get());
    waiter.assertEquals(value.get(), 18);
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:22,代码来源:RedisTest.java

示例3: mapsLocalCache

import org.redisson.api.RedissonClient; //导入方法依赖的package包/类
@Test
void mapsLocalCache() {
    Config config = new Config();
    config.useSingleServer().setAddress("http://127.0.0.1:6379");
    RedissonClient client = Redisson.create(config);

    LocalCachedMapOptions options = LocalCachedMapOptions.defaults().maxIdle(5 * 1000).timeToLive(5 * 1000);
    RLocalCachedMap<String, Integer> map = client.getLocalCachedMap("myMap", options);

    Waiter waiter = new Waiter();
    map.put("key", 20);
    new Thread(() -> {
        mapsLocalCache2(waiter);
        waiter.resume();
    }).start();


    try {
        Thread.sleep(1000);
    }
    catch(InterruptedException e) {
        e.printStackTrace();
    }

    System.out.println("SET");
    map.put("key", 25);
    try {
        waiter.await();
    }
    catch(Throwable throwable) {
        throwable.printStackTrace();
    }
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:34,代码来源:RedisTest.java

示例4: mapsItemChange

import org.redisson.api.RedissonClient; //导入方法依赖的package包/类
@Test
void mapsItemChange() {
    Config config = new Config();
    config.useSingleServer().setAddress("http://127.0.0.1:6379");
    RedissonClient client = Redisson.create(config);

    LocalCachedMapOptions options = LocalCachedMapOptions.defaults().maxIdle(5 * 1000).timeToLive(5 * 1000);
    RLocalCachedMap<String, FinalValue<Integer>> map = client.getLocalCachedMap("myMap", options);

    FinalValue value = new FinalValue(15);
    map.put("test", value);

    Waiter waiter = new Waiter();

    System.out.println("Value: " + value.get());
    new Thread(() -> {
        mapsItemChange2(waiter);
        waiter.resume();
    }).start();

    try {
        Thread.sleep(1000);
    }
    catch(InterruptedException e) {
        e.printStackTrace();
    }
    value.set(18);
    map.put("test", value);
    System.out.println("VALUE SET.");

    try {
        waiter.await();
    }
    catch(Throwable throwable) {
        throwable.printStackTrace();
    }
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:38,代码来源:RedisTest.java

示例5: main

import org.redisson.api.RedissonClient; //导入方法依赖的package包/类
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    LocalCachedMapOptions options = LocalCachedMapOptions.defaults()
            .cacheSize(10000)
            .evictionPolicy(EvictionPolicy.LRU)
            .maxIdle(10, TimeUnit.SECONDS)
            .timeToLive(60, TimeUnit.SECONDS)
            .invalidateEntryOnChange(true);
            
    RLocalCachedMap<String, Integer> cachedMap = redisson.getLocalCachedMap("myMap", options);
    cachedMap.put("a", 1);
    cachedMap.put("b", 2);
    cachedMap.put("c", 3);
    
    boolean contains = cachedMap.containsKey("a");
    
    Integer value = cachedMap.get("c");
    Integer updatedValue = cachedMap.addAndGet("a", 32);
    
    Integer valueSize = cachedMap.valueSize("c");
    
    Set<String> keys = new HashSet<String>();
    keys.add("a");
    keys.add("b");
    keys.add("c");
    Map<String, Integer> mapSlice = cachedMap.getAll(keys);
    
    // use read* methods to fetch all objects
    Set<String> allKeys = cachedMap.readAllKeySet();
    Collection<Integer> allValues = cachedMap.readAllValues();
    Set<Entry<String, Integer>> allEntries = cachedMap.readAllEntrySet();
    
    // use fast* methods when previous value is not required
    boolean isNewKey = cachedMap.fastPut("a", 100);
    boolean isNewKeyPut = cachedMap.fastPutIfAbsent("d", 33);
    long removedAmount = cachedMap.fastRemove("b");
    
    redisson.shutdown();
}
 
开发者ID:redisson,项目名称:redisson-examples,代码行数:42,代码来源:LocalCachedMapExamples.java


注:本文中的org.redisson.api.RedissonClient.getLocalCachedMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。