Giter Site home page Giter Site logo

Comments (21)

KYV365 avatar KYV365 commented on June 12, 2024 2

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.

raja2102598 avatar raja2102598 commented on June 12, 2024

You can use cachedValues() method to get values present in local cache

from redisson.

KYV365 avatar KYV365 commented on June 12, 2024

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.

KYV365 avatar KYV365 commented on June 12, 2024

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.

raja2102598 avatar raja2102598 commented on June 12, 2024

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.

KYV365 avatar KYV365 commented on June 12, 2024

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.

raja2102598 avatar raja2102598 commented on June 12, 2024

@KYV365 can you provide some code for your scenario. I'm not able to understand what you are trying to do

from redisson.

KYV365 avatar KYV365 commented on June 12, 2024

@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.

KYV365 avatar KYV365 commented on June 12, 2024

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.

raja2102598 avatar raja2102598 commented on June 12, 2024

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.

raja2102598 avatar raja2102598 commented on June 12, 2024

here is document link https://github.com/redisson/redisson/wiki/7.-distributed-collections#local-cache

from redisson.

KYV365 avatar KYV365 commented on June 12, 2024

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.

raja2102598 avatar raja2102598 commented on June 12, 2024

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.

KYV365 avatar KYV365 commented on June 12, 2024

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.

raja2102598 avatar raja2102598 commented on June 12, 2024

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.

raja2102598 avatar raja2102598 commented on June 12, 2024

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
image

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.

KYV365 avatar KYV365 commented on June 12, 2024

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.

KYV365 avatar KYV365 commented on June 12, 2024

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
image
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.

raja2102598 avatar raja2102598 commented on June 12, 2024

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.

KYV365 avatar KYV365 commented on June 12, 2024

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.

raja2102598 avatar raja2102598 commented on June 12, 2024

Ideally this should work, can try updating to the latest version.

from redisson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.