本文整理匯總了Java中org.redisson.api.RLocalCachedMap.put方法的典型用法代碼示例。如果您正苦於以下問題:Java RLocalCachedMap.put方法的具體用法?Java RLocalCachedMap.put怎麽用?Java RLocalCachedMap.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.redisson.api.RLocalCachedMap
的用法示例。
在下文中一共展示了RLocalCachedMap.put方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
}
示例2: 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();
}
}
示例3: 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();
}