1010import java .util .concurrent .ConcurrentHashMap ;
1111import java .util .concurrent .TimeUnit ;
1212import java .util .concurrent .locks .ReentrantReadWriteLock ;
13+ import java .util .Iterator ;
1314
1415// Picoded imports
1516import picoded .core .conv .ConvertJSON ;
@@ -124,7 +125,7 @@ public void systemSetup() {
124125 * Teardown and delete the backend storage table, etc. If needed
125126 **/
126127 public void systemDestroy () {
127- redisMap . delete ();
128+ backendMap (). clear ();
128129 }
129130
130131 /**
@@ -168,13 +169,16 @@ public Set<String> keySet(String value) { //TODO
168169 HashSet <String > ret = new HashSet <String >();
169170 //Fetch everything in current db
170171 List <String > retList = null ;
171- // if (value != null) {
172- //backendMap().get(value);
173- //backendMap().keyset();
174- retList = new ArrayList <String >(backendmap ().readAllKeySet ());
175- // Return the full keyset
176- retList .forEach (k -> ret .add (k ));
177- // }
172+ if (value != null ) {
173+ //backendMap().get(value);
174+ //retList = new ArrayList<String>(backendMap().readAllKeySet());
175+ retList = new ArrayList <String >(backendMap ().readAllKeySet ());
176+ // Return the full keyset
177+ retList .forEach (k -> ret .add (k ));
178+ }
179+ retList = new ArrayList <String >(backendMap ().readAllKeySet ());
180+ // Return the full keyset
181+ retList .forEach (k -> ret .add (k ));
178182 return ret ;
179183 }
180184
@@ -227,9 +231,8 @@ public String setValueRaw(String key, String value, long expire) {
227231 }
228232
229233 // Setup key, value - with expirary?
230- //TODO Use fastput ?
231234 if (expire > 0 ) {
232- backendMap ().put (key , value , Math .max (expire - System .currentTimeMillis (), 1 ),
235+ backendMap ().fastPut (key , value , Math .max (expire - System .currentTimeMillis (), 1 ),
233236 TimeUnit .MILLISECONDS );
234237 } else {
235238 backendMap ().put (key , value );
@@ -251,27 +254,31 @@ public String setValueRaw(String key, String value, long expire) {
251254 **/
252255 public MutablePair <String , Long > getValueExpiryRaw (String key , long now ) {
253256
254- // Get the entry view
255- Map .Entry <String , String > entry = backendMap ().get (key );
256- if (entry == null ) {
257- return null ;
258- }
259-
260- // Get the value and expire object : milliseconds?
261- String value = entry .getValue ();
262- Long expireObj = entry .getExpirationTime ();
263- if (expireObj == null ) {
264- expireObj = 0L ;
265- }
257+ Set <String > keys = new HashSet <String >();
258+ Map <String , String > mapSlice = new HashMap <String , String >();
259+ Map .Entry <String ,String > entry = null ;
260+ String value = null ;
261+
262+ keys .add (key );
263+ mapSlice = backendMap ().getAll (keys );
264+
265+ Iterator <Map .Entry <String ,String >> it = mapSlice .entrySet ().iterator ();
266+ if (it .hasNext ()){
267+ entry = it .next ();
268+ if (entry == null ) {
269+ return null ;
270+ }
271+ value = entry .getValue ();
272+
273+ //Cheating there because I don't think redisson has Map Entry Eviction according to this:
274+ //https://www.javadoc.io/doc/org.redisson/redisson/3.2.0/org/redisson/api/RMapCache.html
275+ Long expireObj = 0L ;
266276
267- // Note: 0 = no timestamp, hence valid value
268- long expiry = expireObj .longValue ();
269- if (expiry != 0 && expiry < now ) {
270- return null ;
277+ // Note: 0 = no timestamp, hence valid value
278+ long expiry = expireObj .longValue ();
279+ return new MutablePair <String , Long >(value , expiry );
271280 }
272-
273- // Return the expirary pair
274- return new MutablePair <String , Long >(value , expiry );
281+ return null ;
275282 }
276283
277284}
0 commit comments