Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_57962205
redisson
提交
cd595c13
R
redisson
项目概览
weixin_57962205
/
redisson
与 Fork 源项目一致
从无法访问的项目Fork
通知
10
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redisson
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cd595c13
编写于
5月 16, 2019
作者:
N
Nikita Koksharov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Feature - Async, Reactive, RxJava2 interfaces added to JCache. #2059
上级
0cca617c
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
1946 addition
and
583 deletion
+1946
-583
redisson/src/main/java/org/redisson/api/CacheAsync.java
redisson/src/main/java/org/redisson/api/CacheAsync.java
+266
-0
redisson/src/main/java/org/redisson/api/CacheReactive.java
redisson/src/main/java/org/redisson/api/CacheReactive.java
+268
-0
redisson/src/main/java/org/redisson/api/CacheRx.java
redisson/src/main/java/org/redisson/api/CacheRx.java
+269
-0
redisson/src/main/java/org/redisson/jcache/JCache.java
redisson/src/main/java/org/redisson/jcache/JCache.java
+1095
-583
redisson/src/test/java/org/redisson/jcache/JCacheTest.java
redisson/src/test/java/org/redisson/jcache/JCacheTest.java
+48
-0
未找到文件。
redisson/src/main/java/org/redisson/api/CacheAsync.java
0 → 100644
浏览文件 @
cd595c13
/**
* Copyright (c) 2013-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.redisson.api
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.cache.CacheException
;
import
javax.cache.event.CacheEntryRemovedListener
;
import
javax.cache.integration.CacheLoader
;
import
javax.cache.integration.CacheWriter
;
/**
*
* @author Nikita Koksharov
*
* @param <K> key type
* @param <V> value type
*/
public
interface
CacheAsync
<
K
,
V
>
{
/**
* This method retrieves an entry from the cache.
*
* If the cache uses the read-through pattern, and the method would return null
* because the entry is not present in the cache, then the cache's {@link CacheLoader}
* will try to load the entry.
*
* @param key the key whose value should be returned
* @return the element, or null if the entry does not exist.
* @throws IllegalStateException if the cache is in a closed state
* @throws NullPointerException if the key is null
* @throws CacheException if there is a problem retrieving the entry from the cache
*/
RFuture
<
V
>
getAsync
(
K
key
);
/**
* This method accepts a set of requested keys and retrieves a collection of entries from the
* {@link CacheAsync}, returning them as a {@link Map} of the associated values.
*
* If the cache uses the read-through pattern, and the method would return null for a key
* because an entry is not present in the cache, the Cache's {@link CacheLoader} will try to
* load the entry. If a key's entry cannot be loaded, the key will not appear in the Map.
*
* @param keys The keys whose values should be returned.
* @return A Map of entries associated with the given keys. If a key is not found
* in the cache, it will not be in the Map.
* @throws NullPointerException if keys is null or contains a null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem retrieving the entries from the cache
*/
RFuture
<
Map
<
K
,
V
>>
getAllAsync
(
Set
<?
extends
K
>
keys
);
/**
* This method returns a Boolean true/false value, depending on whether the
* {@link CacheAsync} has a mapping for a key k such that key.equals(k).
*
*
* @param key the key with a possible mapping in the cache.
* @return true if such a mapping exists
* @throws NullPointerException if key is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
Boolean
>
containsKeyAsync
(
K
key
);
/**
* This method places the given value V in the cache and associates it with the given key K.
*
* If the {@link CacheAsync} already has a mapping for the key, the previous
* value is replaced by the given value V.
* This occurs if and only if {@link #containsKeyAsync(Object) c.containsKey(k)}
* would return true.)
*
* @param key the key to place in the cache
* @param value the value to associate with the given key
* @return void
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
Void
>
putAsync
(
K
key
,
V
value
);
/**
* This method places the given key and value in the cache.
* Any value already in the cache is returned and replaced by the new given value.
* This occurs if and only if {@link #containsKeyAsync(Object) c.containsKey(k)}
* would return true.)
* If there was no value already in the cache, the method returns null.
*
* @param key the key to place in the cache
* @param value the value to associate with the given key
* @return the previous value in the cache, or null if none already existed
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
V
>
getAndPutAsync
(
K
key
,
V
value
);
/**
* This method copies all of the entries from the given Map to the {@link CacheAsync}.
*
* This method is equivalent to calling
* {@link #putAsync(Object, Object)} on this cache one time for each mapping
* from key k to value v in the given Map.
*
* Individual puts may occur in any order.
*
* If entries in the cache corresponding to entries in the Map, or the Map itself, is
* changed or removed during this operation, then the behavior of this method is
* not defined.
*
* If default consistency mode is enabled, then each put is atomic but not
* the entire putAll operation. Listeners can observe individual updates.
*
* @param map the Map that contains the entries to be copied to the cache
* @return void
* @throws NullPointerException if the map is null or contains null keys or values.
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache.
*/
RFuture
<
Void
>
putAllAsync
(
java
.
util
.
Map
<?
extends
K
,
?
extends
V
>
map
);
/**
* This method places the given key and value in the cache atomically, if the key is
* not already associated with a value in the cache.
*
* @param key the key to place in the cache
* @param value the value to associate with the given key
* @return true if the value was successfully placed in the cache
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
Boolean
>
putIfAbsentAsync
(
K
key
,
V
value
);
/**
* This method deletes the mapping for a given key from the cache, if it is present.
*
* This occurs if and only if there is a mapping from key k to
* value v such that
* (key==null ? k==null : key.equals(k)).
*
*
This method returns true if the removal was successful,
* or false if there was no such mapping.
*
*
* @param key the key whose mapping will be deleted
* @return returns true if successful, or false if there was no mapping
* @throws NullPointerException if the key is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
Boolean
>
removeAsync
(
K
key
);
/**
* This method atomically removes a key's mapping only if it is currently mapped to the
* provided value.
*
* @param key the key whose mapping will be deleted
* @param oldValue the value that should be mapped to the given key
* @return returns true if successful, or false if there was no such mapping
* @throws NullPointerException if the key is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
Boolean
>
removeAsync
(
K
key
,
V
oldValue
);
/**
* This method atomically removes the entry for a key only if it is currently mapped to some
* value.
*
* @param key the given key
* @return the value if it existed, or null if it did not
* @throws NullPointerException if the key is null.
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
V
>
getAndRemoveAsync
(
K
key
);
/**
* This method atomically replaces an entry only if the key is currently mapped to a
* given value.
*
* @param key the key associated with the given oldValue
* @param oldValue the value that should be associated with the key
* @param newValue the value that will be associated with the key
* @return true if the value was replaced, or false if not
* @throws NullPointerException if the key or values are null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
Boolean
>
replaceAsync
(
K
key
,
V
oldValue
,
V
newValue
);
/**
* This method atomically replaces an entry only if the key is currently mapped to some
* value.
*
* @param key the key mapped to the given value
* @param value the value mapped to the given key
* @return true if the value was replaced, or false if not
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
Boolean
>
replaceAsync
(
K
key
,
V
value
);
/**
* This method atomically replaces a given key's value if and only if the key is currently
* mapped to a value.
*
* @param key the key associated with the given value
* @param value the value associated with the given key
* @return the previous value mapped to the given key, or
* null if there was no such mapping.
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
V
>
getAndReplaceAsync
(
K
key
,
V
value
);
/**
* This method deletes the entries for the given keys.
*
* The order in which the individual entries are removed is undefined.
*
* For every entry in the key set, the following are called:
*
• any registered {@link CacheEntryRemovedListener}s
• if the cache is a write-through cache, the {@link CacheWriter}
* If the key set is empty, the {@link CacheWriter} is not called.
*
* @param keys the keys to remove
* @return void
* @throws NullPointerException if keys is null or if it contains a null key
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
Void
>
removeAllAsync
(
Set
<?
extends
K
>
keys
);
/**
* This method empties the cache's contents, without notifying listeners or
* {@link CacheWriter}s.
*
* @return void
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
RFuture
<
Void
>
clearAsync
();
}
redisson/src/main/java/org/redisson/api/CacheReactive.java
0 → 100644
浏览文件 @
cd595c13
/**
* Copyright (c) 2013-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.redisson.api
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.cache.CacheException
;
import
javax.cache.event.CacheEntryRemovedListener
;
import
javax.cache.integration.CacheLoader
;
import
javax.cache.integration.CacheWriter
;
import
reactor.core.publisher.Mono
;
/**
*
* @author Nikita Koksharov
*
* @param <K> key type
* @param <V> value type
*/
public
interface
CacheReactive
<
K
,
V
>
{
/**
* This method retrieves an entry from the cache.
*
* If the cache uses the read-through pattern, and the method would return null
* because the entry is not present in the cache, then the cache's {@link CacheLoader}
* will try to load the entry.
*
* @param key the key whose value should be returned
* @return the element, or null if the entry does not exist.
* @throws IllegalStateException if the cache is in a closed state
* @throws NullPointerException if the key is null
* @throws CacheException if there is a problem retrieving the entry from the cache
*/
Mono
<
V
>
get
(
K
key
);
/**
* This method accepts a set of requested keys and retrieves a collection of entries from the
* {@link CacheReactive}, returning them as a {@link Map} of the associated values.
*
* If the cache uses the read-through pattern, and the method would return null for a key
* because an entry is not present in the cache, the Cache's {@link CacheLoader} will try to
* load the entry. If a key's entry cannot be loaded, the key will not appear in the Map.
*
* @param keys The keys whose values should be returned.
* @return A Map of entries associated with the given keys. If a key is not found
* in the cache, it will not be in the Map.
* @throws NullPointerException if keys is null or contains a null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem retrieving the entries from the cache
*/
Mono
<
Map
<
K
,
V
>>
getAll
(
Set
<?
extends
K
>
keys
);
/**
* This method returns a Boolean true/false value, depending on whether the
* {@link CacheReactive} has a mapping for a key k such that key.equals(k).
*
*
* @param key the key with a possible mapping in the cache.
* @return true if such a mapping exists
* @throws NullPointerException if key is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
Boolean
>
containsKey
(
K
key
);
/**
* This method places the given value V in the cache and associates it with the given key K.
*
* If the {@link CacheReactive} already has a mapping for the key, the previous
* value is replaced by the given value V.
* This occurs if and only if {@link #containsKey(Object) c.containsKey(k)}
* would return true.)
*
* @param key the key to place in the cache
* @param value the value to associate with the given key
* @return void
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
Void
>
put
(
K
key
,
V
value
);
/**
* This method places the given key and value in the cache.
* Any value already in the cache is returned and replaced by the new given value.
* This occurs if and only if {@link #containsKey(Object) c.containsKey(k)}
* would return true.)
* If there was no value already in the cache, the method returns null.
*
* @param key the key to place in the cache
* @param value the value to associate with the given key
* @return the previous value in the cache, or null if none already existed
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
V
>
getAndPut
(
K
key
,
V
value
);
/**
* This method copies all of the entries from the given Map to the {@link CacheReactive}.
*
* This method is equivalent to calling
* {@link #put(Object, Object) put(k, v)} on this cache one time for each mapping
* from key k to value v in the given Map.
*
* Individual puts may occur in any order.
*
* If entries in the cache corresponding to entries in the Map, or the Map itself, is
* changed or removed during this operation, then the behavior of this method is
* not defined.
*
* If default consistency mode is enabled, then each put is atomic but not
* the entire putAll operation. Listeners can observe individual updates.
*
* @param map the Map that contains the entries to be copied to the cache
* @return void
* @throws NullPointerException if the map is null or contains null keys or values.
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache.
*/
Mono
<
Void
>
putAll
(
java
.
util
.
Map
<?
extends
K
,
?
extends
V
>
map
);
/**
* This method places the given key and value in the cache atomically, if the key is
* not already associated with a value in the cache.
*
* @param key the key to place in the cache
* @param value the value to associate with the given key
* @return true if the value was successfully placed in the cache
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
Boolean
>
putIfAbsent
(
K
key
,
V
value
);
/**
* This method deletes the mapping for a given key from the cache, if it is present.
*
* This occurs if and only if there is a mapping from key k to
* value v such that
* (key==null ? k==null : key.equals(k)).
*
*
This method returns true if the removal was successful,
* or false if there was no such mapping.
*
*
* @param key the key whose mapping will be deleted
* @return returns true if successful, or false if there was no mapping
* @throws NullPointerException if the key is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
Boolean
>
remove
(
K
key
);
/**
* This method atomically removes a key's mapping only if it is currently mapped to the
* provided value.
*
* @param key the key whose mapping will be deleted
* @param oldValue the value that should be mapped to the given key
* @return returns true if successful, or false if there was no such mapping
* @throws NullPointerException if the key is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
Boolean
>
remove
(
K
key
,
V
oldValue
);
/**
* This method atomically removes the entry for a key only if it is currently mapped to some
* value.
*
* @param key the given key
* @return the value if it existed, or null if it did not
* @throws NullPointerException if the key is null.
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
V
>
getAndRemove
(
K
key
);
/**
* This method atomically replaces an entry only if the key is currently mapped to a
* given value.
*
* @param key the key associated with the given oldValue
* @param oldValue the value that should be associated with the key
* @param newValue the value that will be associated with the key
* @return true if the value was replaced, or false if not
* @throws NullPointerException if the key or values are null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
Boolean
>
replace
(
K
key
,
V
oldValue
,
V
newValue
);
/**
* This method atomically replaces an entry only if the key is currently mapped to some
* value.
*
* @param key the key mapped to the given value
* @param value the value mapped to the given key
* @return true if the value was replaced, or false if not
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
Boolean
>
replace
(
K
key
,
V
value
);
/**
* This method atomically replaces a given key's value if and only if the key is currently
* mapped to a value.
*
* @param key the key associated with the given value
* @param value the value associated with the given key
* @return the previous value mapped to the given key, or
* null if there was no such mapping.
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
V
>
getAndReplace
(
K
key
,
V
value
);
/**
* This method deletes the entries for the given keys.
*
* The order in which the individual entries are removed is undefined.
*
* For every entry in the key set, the following are called:
*
• any registered {@link CacheEntryRemovedListener}s
• if the cache is a write-through cache, the {@link CacheWriter}
* If the key set is empty, the {@link CacheWriter} is not called.
*
* @param keys the keys to remove
* @return void
* @throws NullPointerException if keys is null or if it contains a null key
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
Void
>
removeAll
(
Set
<?
extends
K
>
keys
);
/**
* This method empties the cache's contents, without notifying listeners or
* {@link CacheWriter}s.
*
* @return void
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Mono
<
Void
>
clear
();
}
redisson/src/main/java/org/redisson/api/CacheRx.java
0 → 100644
浏览文件 @
cd595c13
/**
* Copyright (c) 2013-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.redisson.api
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.cache.CacheException
;
import
javax.cache.event.CacheEntryRemovedListener
;
import
javax.cache.integration.CacheLoader
;
import
javax.cache.integration.CacheWriter
;
import
io.reactivex.Completable
;
import
io.reactivex.Maybe
;
import
io.reactivex.Single
;
/**
*
* @author Nikita Koksharov
*
* @param <K> key type
* @param <V> value type
*/
public
interface
CacheRx
<
K
,
V
>
{
/**
* This method retrieves an entry from the cache.
*
* If the cache uses the read-through pattern, and the method would return null
* because the entry is not present in the cache, then the cache's {@link CacheLoader}
* will try to load the entry.
*
* @param key the key whose value should be returned
* @return the element, or null if the entry does not exist.
* @throws IllegalStateException if the cache is in a closed state
* @throws NullPointerException if the key is null
* @throws CacheException if there is a problem retrieving the entry from the cache
*/
Maybe
<
V
>
get
(
K
key
);
/**
* This method accepts a set of requested keys and retrieves a collection of entries from the
* {@link CacheRx}, returning them as a {@link Map} of the associated values.
*
* If the cache uses the read-through pattern, and the method would return null for a key
* because an entry is not present in the cache, the Cache's {@link CacheLoader} will try to
* load the entry. If a key's entry cannot be loaded, the key will not appear in the Map.
*
* @param keys The keys whose values should be returned.
* @return A Map of entries associated with the given keys. If a key is not found
* in the cache, it will not be in the Map.
* @throws NullPointerException if keys is null or contains a null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem retrieving the entries from the cache
*/
Single
<
Map
<
K
,
V
>>
getAll
(
Set
<?
extends
K
>
keys
);
/**
* This method returns a Boolean true/false value, depending on whether the
* {@link CacheRx} has a mapping for a key k such that key.equals(k).
*
*
* @param key the key with a possible mapping in the cache.
* @return true if such a mapping exists
* @throws NullPointerException if key is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Single
<
Boolean
>
containsKey
(
K
key
);
/**
* This method places the given value V in the cache and associates it with the given key K.
*
* If the {@link CacheRx} already has a mapping for the key, the previous
* value is replaced by the given value V.
* This occurs if and only if {@link #containsKey(Object) c.containsKey(k)}
* would return true.)
*
* @param key the key to place in the cache
* @param value the value to associate with the given key
* @return void
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Completable
put
(
K
key
,
V
value
);
/**
* This method places the given key and value in the cache.
* Any value already in the cache is returned and replaced by the new given value.
* This occurs if and only if {@link #containsKey(Object) c.containsKey(k)}
* would return true.)
* If there was no value already in the cache, the method returns null.
*
* @param key the key to place in the cache
* @param value the value to associate with the given key
* @return the previous value in the cache, or null if none already existed
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Maybe
<
V
>
getAndPut
(
K
key
,
V
value
);
/**
* This method copies all of the entries from the given Map to the {@link CacheRx}.
*
* This method is equivalent to calling
* {@link #put(Object, Object) put(k, v)} on this cache one time for each mapping
* from key k to value v in the given Map.
*
* Individual puts may occur in any order.
*
* If entries in the cache corresponding to entries in the Map, or the Map itself, is
* changed or removed during this operation, then the behavior of this method is
* not defined.
*
* If default consistency mode is enabled, then each put is atomic but not
* the entire putAll operation. Listeners can observe individual updates.
*
* @param map the Map that contains the entries to be copied to the cache
* @return void
* @throws NullPointerException if the map is null or contains null keys or values.
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache.
*/
Completable
putAll
(
java
.
util
.
Map
<?
extends
K
,
?
extends
V
>
map
);
/**
* This method places the given key and value in the cache atomically, if the key is
* not already associated with a value in the cache.
*
* @param key the key to place in the cache
* @param value the value to associate with the given key
* @return true if the value was successfully placed in the cache
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Single
<
Boolean
>
putIfAbsent
(
K
key
,
V
value
);
/**
* This method deletes the mapping for a given key from the cache, if it is present.
*
* This occurs if and only if there is a mapping from key k to
* value v such that
* (key==null ? k==null : key.equals(k)).
*
*
This method returns true if the removal was successful,
* or false if there was no such mapping.
*
*
* @param key the key whose mapping will be deleted
* @return returns true if successful, or false if there was no mapping
* @throws NullPointerException if the key is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Single
<
Boolean
>
remove
(
K
key
);
/**
* This method atomically removes a key's mapping only if it is currently mapped to the
* provided value.
*
* @param key the key whose mapping will be deleted
* @param oldValue the value that should be mapped to the given key
* @return returns true if successful, or false if there was no such mapping
* @throws NullPointerException if the key is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Single
<
Boolean
>
remove
(
K
key
,
V
oldValue
);
/**
* This method atomically removes the entry for a key only if it is currently mapped to some
* value.
*
* @param key the given key
* @return the value if it existed, or null if it did not
* @throws NullPointerException if the key is null.
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Maybe
<
V
>
getAndRemove
(
K
key
);
/**
* This method atomically replaces an entry only if the key is currently mapped to a
* given value.
*
* @param key the key associated with the given oldValue
* @param oldValue the value that should be associated with the key
* @param newValue the value that will be associated with the key
* @return true if the value was replaced, or false if not
* @throws NullPointerException if the key or values are null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Single
<
Boolean
>
replace
(
K
key
,
V
oldValue
,
V
newValue
);
/**
* This method atomically replaces an entry only if the key is currently mapped to some
* value.
*
* @param key the key mapped to the given value
* @param value the value mapped to the given key
* @return true if the value was replaced, or false if not
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Single
<
Boolean
>
replace
(
K
key
,
V
value
);
/**
* This method atomically replaces a given key's value if and only if the key is currently
* mapped to a value.
*
* @param key the key associated with the given value
* @param value the value associated with the given key
* @return the previous value mapped to the given key, or
* null if there was no such mapping.
* @throws NullPointerException if the key or value is null
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Maybe
<
V
>
getAndReplace
(
K
key
,
V
value
);
/**
* This method deletes the entries for the given keys.
*
* The order in which the individual entries are removed is undefined.
*
* For every entry in the key set, the following are called:
*
• any registered {@link CacheEntryRemovedListener}s
• if the cache is a write-through cache, the {@link CacheWriter}
* If the key set is empty, the {@link CacheWriter} is not called.
*
* @param keys the keys to remove
* @return void
* @throws NullPointerException if keys is null or if it contains a null key
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Completable
removeAll
(
Set
<?
extends
K
>
keys
);
/**
* This method empties the cache's contents, without notifying listeners or
* {@link CacheWriter}s.
*
* @return void
* @throws IllegalStateException if the cache is in a closed state
* @throws CacheException if there is a problem with the cache
*/
Completable
clear
();
}
redisson/src/main/java/org/redisson/jcache/JCache.java
浏览文件 @
cd595c13
此差异已折叠。
点击以展开。
redisson/src/test/java/org/redisson/jcache/JCacheTest.java
浏览文件 @
cd595c13
...
...
@@ -34,6 +34,8 @@ import org.redisson.BaseTest;
import
org.redisson.RedisRunner
;
import
org.redisson.RedisRunner.FailedToStartRedisException
;
import
org.redisson.RedisRunner.RedisProcess
;
import
org.redisson.api.CacheReactive
;
import
org.redisson.api.CacheRx
;
import
org.redisson.codec.TypedJsonJacksonCodec
;
import
org.redisson.config.Config
;
import
org.redisson.jcache.configuration.RedissonConfiguration
;
...
...
@@ -43,6 +45,52 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
public
class
JCacheTest
extends
BaseTest
{
@Test
public
void
testReactive
()
throws
Exception
{
RedisProcess
runner
=
new
RedisRunner
()
.
nosave
()
.
randomDir
()
.
port
(
6311
)
.
run
();
URL
configUrl
=
getClass
().
getResource
(
"redisson-jcache.json"
);
Config
cfg
=
Config
.
fromJSON
(
configUrl
);
Configuration
<
String
,
String
>
config
=
RedissonConfiguration
.
fromConfig
(
cfg
);
Cache
<
String
,
String
>
cache
=
Caching
.
getCachingProvider
().
getCacheManager
()
.
createCache
(
"test"
,
config
);
CacheReactive
<
String
,
String
>
reactive
=
cache
.
unwrap
(
CacheReactive
.
class
);
reactive
.
put
(
"1"
,
"2"
).
block
();
assertThat
(
reactive
.
get
(
"1"
).
block
()).
isEqualTo
(
"2"
);
cache
.
close
();
runner
.
stop
();
}
@Test
public
void
testRx
()
throws
Exception
{
RedisProcess
runner
=
new
RedisRunner
()
.
nosave
()
.
randomDir
()
.
port
(
6311
)
.
run
();
URL
configUrl
=
getClass
().
getResource
(
"redisson-jcache.json"
);
Config
cfg
=
Config
.
fromJSON
(
configUrl
);
Configuration
<
String
,
String
>
config
=
RedissonConfiguration
.
fromConfig
(
cfg
);
Cache
<
String
,
String
>
cache
=
Caching
.
getCachingProvider
().
getCacheManager
()
.
createCache
(
"test"
,
config
);
CacheRx
<
String
,
String
>
reactive
=
cache
.
unwrap
(
CacheRx
.
class
);
reactive
.
put
(
"1"
,
"2"
).
blockingAwait
();
assertThat
(
reactive
.
get
(
"1"
).
blockingGet
()).
isEqualTo
(
"2"
);
cache
.
close
();
runner
.
stop
();
}
@Test
public
void
testPutAll
()
throws
Exception
{
RedisProcess
runner
=
new
RedisRunner
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录