Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature - Rx and Reactive interfaces for RLocalCachedMap object. #3181
- Loading branch information
Nikita Koksharov
committed
Nov 7, 2022
1 parent
f3ed239
commit 013e660
Showing
8 changed files
with
222 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
redisson/src/main/java/org/redisson/api/RLocalCachedMapReactive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.redisson.api; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* Map object with local entry cache support. | ||
* <p> | ||
* Each instance maintains local cache to achieve fast read operations. | ||
* Suitable for maps which used mostly for read operations and network roundtrip delays are undesirable. | ||
* | ||
* @author Nikita Koksharov | ||
* | ||
* @param <K> map key | ||
* @param <V> map value | ||
*/ | ||
public interface RLocalCachedMapReactive<K, V> extends RMapReactive<K, V> { | ||
|
||
/** | ||
* Clears local cache across all instances | ||
* | ||
* @return void | ||
*/ | ||
Mono<Void> clearLocalCache(); | ||
|
||
/** | ||
* Returns all keys stored in local cache | ||
* | ||
* @return keys | ||
*/ | ||
Set<K> cachedKeySet(); | ||
|
||
/** | ||
* Returns all values stored in local cache | ||
* | ||
* @return values | ||
*/ | ||
Collection<V> cachedValues(); | ||
|
||
/** | ||
* Returns all map entries stored in local cache | ||
* | ||
* @return entries | ||
*/ | ||
Set<Map.Entry<K, V>> cachedEntrySet(); | ||
|
||
/** | ||
* Returns state of local cache | ||
* | ||
* @return map | ||
*/ | ||
Map<K, V> getCachedMap(); | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
redisson/src/main/java/org/redisson/api/RLocalCachedMapRx.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.redisson.api; | ||
|
||
import io.reactivex.rxjava3.core.Completable; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* Map object with local entry cache support. | ||
* <p> | ||
* Each instance maintains local cache to achieve fast read operations. | ||
* Suitable for maps which used mostly for read operations and network roundtrip delays are undesirable. | ||
* | ||
* @author Nikita Koksharov | ||
* | ||
* @param <K> map key | ||
* @param <V> map value | ||
*/ | ||
public interface RLocalCachedMapRx<K, V> extends RMapRx<K, V> { | ||
|
||
/** | ||
* Clears local cache across all instances | ||
* | ||
* @return void | ||
*/ | ||
Completable clearLocalCache(); | ||
|
||
/** | ||
* Returns all keys stored in local cache | ||
* | ||
* @return keys | ||
*/ | ||
Set<K> cachedKeySet(); | ||
|
||
/** | ||
* Returns all values stored in local cache | ||
* | ||
* @return values | ||
*/ | ||
Collection<V> cachedValues(); | ||
|
||
/** | ||
* Returns all map entries stored in local cache | ||
* | ||
* @return entries | ||
*/ | ||
Set<Map.Entry<K, V>> cachedEntrySet(); | ||
|
||
/** | ||
* Returns state of local cache | ||
* | ||
* @return map | ||
*/ | ||
Map<K, V> getCachedMap(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
redisson/src/test/java/org/redisson/RedissonLocalCachedMapReactiveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.redisson; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.redisson.api.LocalCachedMapOptions; | ||
import org.redisson.api.RLocalCachedMapReactive; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class RedissonLocalCachedMapReactiveTest extends BaseReactiveTest { | ||
|
||
@Test | ||
public void test1() { | ||
RLocalCachedMapReactive<String, String> m1 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); | ||
RLocalCachedMapReactive<String, String> m2 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); | ||
|
||
m1.put("1", "4").block(); | ||
m1.put("2", "5").block(); | ||
m1.put("3", "6").block(); | ||
|
||
assertThat(m1.getCachedMap()).containsKeys("1", "2", "3"); | ||
|
||
assertThat(m1.get("1").block()).isEqualTo(m2.get("1").block()).isEqualTo("4"); | ||
} | ||
|
||
} |