Comments (21)
LocalCachedMapOptions
i know the reason。
if you set LocalCachedMapOptions timeToLive and maxIdle,
the cachedValues convert to List or iterator(),
the method removeExpiredEntries() will be call in AbstractCacheMap,
and then check cache expired even though evictionPolicy(LocalCachedMapOptions.EvictionPolicy.NONE),
the element will be eviction when over the time.
Thanks for your kindness reply.
from redisson.
You can use cachedValues() method to get values present in local cache
from redisson.
You can use cachedValues() method to get values present in local cache
new ArrayList<>(localCachedMap.cachedValues()) can not get any data.
but redissonObject and ConcurrentMap<CacheKey, CacheValue> cache in LocalCacheView is not empty
from redisson.
You can use cachedValues() method to get values present in local cache
expect when start, load data to RedissonLocalCachedMap from DB,and then get all data from local in RedissonLocalCachedMap,RedissonLocalCachedMap just listen keys change and reload local data,any setting or method can give me advice,thanks.
from redisson.
If the redis server has values for the hashmap, then when you create a localcachemap for the hashmap, use preloadcache() function to load redis data to your local cache.
After this if you use cachedvalues() you will get the data.
from redisson.
If the redis server has values for the hashmap, then when you create a localcachemap for the hashmap, use preloadcache() function to load redis data to your local cache.
After this if you use cachedvalues() you will get the data.
cachedvalues() can get the data only once?the twice is still null
from redisson.
@KYV365 can you provide some code for your scenario. I'm not able to understand what you are trying to do
from redisson.
@KYV365 can you provide some code for your scenario. I'm not able to understand what you are trying to do
private RedissonLocalCachedMap<Long, User> cachedMap = null;
private void init(){
cachedMap = (RedissonLocalCachedMap<Long, User>) redissonClient.getLocalCachedMap("user", options);
// select * from user
cachedMap.put(1L, user1);
cachedMap.put(2L, user2);
cachedMap.preloadCache();
}
private List getAll(){
Collection userList= cachedMap .cachedValues();
ArrayList list = new ArrayList<>(userList);
return list;
}
first,call init to create the RedissonLocalCachedMap and load db data to map.
second call getAll,userList has the local data,list is null.
third call getAll, userList and list all is null.
no doc show how to use it. it is so confused for user.
from redisson.
just expect
when i put the db data to RedissonLocalCachedMap, i can get the data from local.
when the keys change, RedissonLocalCachedMap can refresh the local, and i can get the new one from local.
any method can do this or show some sample?
from redisson.
Try this
private static RLocalCachedMap<Long, User> cachedMap = null;
public static void main(String[] args) {
RedissonClient redissonClient = createRedissonClient();
cachedMap = redissonClient.getLocalCachedMap(
LocalCachedMapOptions.name("user"));
cachedMap.put(1L, user1);
cachedMap.put(2L, user2);
System.out.println(getAll());
}
private static Collection<User> getAll(){
return cachedMap.cachedValues();
}
This is latest version code, but if you are using old version it should be similar to this.
from redisson.
here is document link https://github.com/redisson/redisson/wiki/7.-distributed-collections#local-cache
from redisson.
Try this
private static RLocalCachedMap<Long, User> cachedMap = null; public static void main(String[] args) { RedissonClient redissonClient = createRedissonClient(); cachedMap = redissonClient.getLocalCachedMap( LocalCachedMapOptions.name("user")); cachedMap.put(1L, user1); cachedMap.put(2L, user2); System.out.println(getAll()); } private static Collection<User> getAll(){ return cachedMap.cachedValues(); }
This is latest version code, but if you are using old version it should be similar to this.
static is nouse,when the second time getAll(),you can get nothing.
and the second question, the Collection can not convert to List, or you will get nothing.
from redisson.
Then in the getall method, get the localcachemap from the redissonclient again same as init, this should solve your issue.
One more change, instead of cachedvalues use values() or readallvalues()
from redisson.
Then in the getall method, get the localcachemap from the redissonclient again same as init, this should solve your issue.
One more change, instead of cachedvalues use values() or readallvalues()
i know values() is ok, but when convert to List, it will call redis server by commod HLEN for the method size()
i do not want to call redis server frequently or local cache is meaningless.
from redisson.
I got your point. You said the second time it's giving null right, after init when the second call happens, is it immediately or later, and did you debug the second time
from redisson.
redisson version:3.18.0
redisson config:
Config config = new Config();
config.useSingleServer()
.setTimeout(3000)
.setConnectTimeout(10000)
.setRetryAttempts(3)
.setRetryInterval(1500)
.setPingConnectionInterval(10000)
.setConnectionPoolSize(100)
.setConnectionMinimumIdleSize(10)
.setIdleConnectionTimeout(10000)
.setAddress(REDIS_PROTOCOL_PREFIX + redisProperties.getHost() + ":" + redisProperties.getPort())
.setDatabase(redisProperties.getDatabase())
.setPassword(redisProperties.getPassword());StringCodec stringCodec = new StringCodec(); JsonJacksonCodec codec = new JsonJacksonCodec(); config.setCodec(codec); config.setTransportMode(TransportMode.NIO); config.setThreads(Runtime.getRuntime().availableProcessors() * 2); config.setNettyThreads(Runtime.getRuntime().availableProcessors() * 2); return Redisson.create(config);
LocalCachedMapOptions config:
LocalCachedMapOptions.defaults()
.evictionPolicy(LocalCachedMapOptions.EvictionPolicy.NONE)
.cacheSize(0)
.reconnectionStrategy(LocalCachedMapOptions.ReconnectionStrategy.NONE)
.syncStrategy(LocalCachedMapOptions.SyncStrategy.INVALIDATE)
.timeToLive(10000)
.maxIdle(10000);redis data:
key:id
value: Object
i want to obtain all values,
Collection<> values = redissonClient.getLocalCachedMap.values()。
Collection<> values = redissonClient.getLocalCachedMap.readAllValues()。
the two method can obtain all values,but the first get from local,the second get from redis。the next,get by the first,and convert Collection to List,it call redis command HLEN,i expect all the data from local。
what method can do this?
Try changing the cache size in options
from redisson.
I got your point. You said the second time it's giving null right, after init when the second call happens, is it immediately or later, and did you debug the second time
the second is later, yes, debug show me null
from redisson.
redisson version:3.18.0
redisson config:
Config config = new Config();
config.useSingleServer()
.setTimeout(3000)
.setConnectTimeout(10000)
.setRetryAttempts(3)
.setRetryInterval(1500)
.setPingConnectionInterval(10000)
.setConnectionPoolSize(100)
.setConnectionMinimumIdleSize(10)
.setIdleConnectionTimeout(10000)
.setAddress(REDIS_PROTOCOL_PREFIX + redisProperties.getHost() + ":" + redisProperties.getPort())
.setDatabase(redisProperties.getDatabase())
.setPassword(redisProperties.getPassword());StringCodec stringCodec = new StringCodec(); JsonJacksonCodec codec = new JsonJacksonCodec(); config.setCodec(codec); config.setTransportMode(TransportMode.NIO); config.setThreads(Runtime.getRuntime().availableProcessors() * 2); config.setNettyThreads(Runtime.getRuntime().availableProcessors() * 2); return Redisson.create(config);
LocalCachedMapOptions config:
LocalCachedMapOptions.defaults()
.evictionPolicy(LocalCachedMapOptions.EvictionPolicy.NONE)
.cacheSize(0)
.reconnectionStrategy(LocalCachedMapOptions.ReconnectionStrategy.NONE)
.syncStrategy(LocalCachedMapOptions.SyncStrategy.INVALIDATE)
.timeToLive(10000)
.maxIdle(10000);
redis data:
key:id
value: Object
i want to obtain all values,
Collection<> values = redissonClient.getLocalCachedMap.values()。
Collection<> values = redissonClient.getLocalCachedMap.readAllValues()。
the two method can obtain all values,but the first get from local,the second get from redis。
the next,get by the first,and convert Collection to List,it call redis command HLEN,i expect all the data from local。
what method can do this?Try changing the cache size in options
change cache size is also no use. 0 means no limit is doc.
from redisson.
I got your point. You said the second time it's giving null right, after init when the second call happens, is it immediately or later, and did you debug the second time
the second is later, yes, debug show me null
This is not more than the ttl you gave right?
from redisson.
I got your point. You said the second time it's giving null right, after init when the second call happens, is it immediately or later, and did you debug the second time
the second is later, yes, debug show me null
This is not more than the ttl you gave right?
ttl is -1
from redisson.
Ideally this should work, can try updating to the latest version.
from redisson.
Related Issues (20)
- RTransaction.getLocalCachedMap giving wrong cache if the cache map is empty HOT 3
- Redisson stream gets stucked after acquiring connection HOT 11
- SentinelConnectionManager stops scheduling change check / dns check after error HOT 1
- redisson.getMap(org.redisson.api.options.MapOptions<K, V> options), if options set codec, but invalid HOT 1
- Inconsistency in Redisson's RLiveObjectService.find() Method: Retrieving Outdated Data Despite Updates HOT 6
- Supporting delete() method RedissonTransactionalLocalCachedMap
- Issue with Kryo5Codec in combination with org.springframework.cache.support.NullValue HOT 5
- Why RedissonMap#containsKey() return true,but get() method return an null value? HOT 4
- org.redisson.client.RedisConnectionException: SlaveConnectionPool no available Redis entries. Disconnected hosts:{IPS} HOT 4
- Make TransactionOptions possible to test for equality
- Issue #4963 Back: Unable to find session error arise if Tomcat session was deleted or expired HOT 2
- is bloom filter not have a responsive usage? HOT 2
- IndexOutOfBoundsException in LZ4Codec HOT 2
- Being able to do setCredentialsResolver at Config level
- 为啥maven依赖引入不了,有没有什么好的解决办法? HOT 1
- Add sslKeystoreType setting HOT 1
- RLiveObjects can't set fields to null. HOT 2
- How to add event listener for RLock HOT 1
- Which version is the current stable version? HOT 3
- CRaC support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redisson.