本文整理匯總了Java中org.redisson.api.RLocalCachedMap類的典型用法代碼示例。如果您正苦於以下問題:Java RLocalCachedMap類的具體用法?Java RLocalCachedMap怎麽用?Java RLocalCachedMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RLocalCachedMap類屬於org.redisson.api包,在下文中一共展示了RLocalCachedMap類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mapsLocalCache2
import org.redisson.api.RLocalCachedMap; //導入依賴的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);
}
示例2: mapsItemChange2
import org.redisson.api.RLocalCachedMap; //導入依賴的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);
}
示例3: init
import org.redisson.api.RLocalCachedMap; //導入依賴的package包/類
/**
* Simply initializes this class but with automatically getting the needed informations
*/
public void init(RLocalCachedMap<String, Object> configMap) {
if(configMap == null) return;
this.init(
(List<String>) configMap.get(NetworkConfigType.PUNISHMENT_CATEGORIES.getKey()),
(List<String>) configMap.get(NetworkConfigType.PUNISHMENT_SUBTYPES.getKey())
);
}
示例4: mapsLocalCache
import org.redisson.api.RLocalCachedMap; //導入依賴的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();
}
}
示例5: mapsItemChange
import org.redisson.api.RLocalCachedMap; //導入依賴的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();
}
}
示例6: main
import org.redisson.api.RLocalCachedMap; //導入依賴的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();
}