In vertx prior to 3.7, there was a redis client method mgetmany:
RedisClient mgetMany(List<String> keys,
Handler<AsyncResult<JsonArray>> handler)
Get the values of all the given keys
In the native redis methods what is the counterpart of this?
How could we replace this method using the new RestAPI?
Its equivalent redis command is MGET.
refer redis doc here
You can use any redis client lib to call redis. (For example Jedis, Redision, Lettuce), which will provide you easy to use APIs
Related
is there a way to configure mTLS in Helidon MP without saving the following to disk?
server.sockets.0.tls.trust.keystore-path
server.sockets.0.tls.private-key.keystore-path
client.tls.client.keystore-path
If we have these certificates as a Java object is there a way to pass those to the Helidon server?
I am using Helidon MP 2.3.1
I have tried configuring it with certificates on disk but I would like to avoid that.
From David Kral, there is no "easy" way to do this. Basically there are two possible options for you.
It is possible to create a new config with runtime created ConfigSource and instead of setting resource.resource-path one could use resource.content . The value here is Base64 encoded resource value. That means, you can store obtained certificate there.
Alternatively, you could create your own CDI extension. Inject ServerCdiExtension there and create initialization method (Similar to how ServerCdiExtension#startServer method looks like in terms of parameters). In this method you can obtain WebServer.Builder from injected ServerCdiExtension instance and it is possible to set Tls configuration the way you want it to be set. It is important to note, this extension has to have higher priority over theServerCdiExtension .
Using Java the spring-rabbitmq has a isRunning method in the RabbitTemplate class. Is this method equivalent to rabbitmq’s server-check through http-api: /api/aliveness-test/vhost? Can both be used for the purpose of just checking if the rabbitmq server is running ?
No. They are different things.
RabbitTemplate's class is checking if any of RabbitMQ listeners in your application are still running.
synchronized (this.directReplyToContainers) {
return this.directReplyToContainers.values()
.stream()
.anyMatch(AbstractMessageListenerContainer::isRunning);
}
API check through HTTP checks vhost's (server's) aliveness.
Can Redis be used as a self populating cache (or pull-through cache) ?
In other words, is it able to create an entry on the fly if this entry is not cached yet ?
Redis is just a store: you add things to it and retrieve them back again. It has no awareness of what you are using it for (caching) or knowledge of the backend it would perform lookups from, that will depend on the application handling the request and using Redis to cache.
Can Redis be used as a self-populating cache (or pull-through cache)?
Yes! But Redis doesn't have an implementation for self-population.
So you just have to implement it yourself and it's easy too.
Define a wrapper class that extends(is-a relation) a redis client(of your choice).
Define Factory interfaces to create objects.
Override necessary methods that require pull-through implementation
3.1 If the key already exists, return it.
3.2 Otherwise use factory interfaces to create the value, cache it and return it.
Hope this answer is generic enough for any redis client.
I want to remove all objects that are stored in Redis via the ServiceStack Redis client.
I tried to use the Remove method with "*" as a key but it is not ok.
Thanks.
If you want to clear all data on the Redis instance you can use:
redis.FlushAll();
Or if you just want to clear the DB you're on:
redis.FlushDb();
I want to use Redis as a cache storage for multiple applications on the same physical machine.
I know at least two ways of doing it:
by running several Redis instances on different ports;
by using different Redis databases for different applications.
But I don't know which one is better for me.
What are advantages and disadvantages of these methods?
Is there any better way of doing it?
Generally, you should prefer the 1st approach, i.e. dedicated Redis servers. Shared databases are managed by the same Redis process and can therefore block each other. Additionally, shared databases share the same configuration (although in your case this may not be an issue since all databases are intended for caching). Lastly, shared databases are not supported by Redis Cluster.
For more information refer to this blog post: https://redislabs.com/blog/benchmark-shared-vs-dedicated-redis-instances
We solved this problem by namespacing the keys. Intially we tried using databases where each database ID would be used a specific applications. However, that idea was not scalable since there is a limited number of databases, plus in Premium offerings (like Azure Cache for Redis Premium instances with Sharding enabled), the concept of database is not used.
The solution we used is attaching a unique prefix for all keys. Each application would be annotated with a unique moniker which would be prefixed infront of each key.
To reduce churn, we have built a framework (URP). If you are using StackExchange.Redis then yuo will be able to use the URP SDK directly. If it helps, I have added some of the references.
Source Code and Documentation - https://github.com/microsoft/UnifiedRedisPlatform.Core/wiki/Management-Console
Blog Post (idea) - https://www.devcompost.com/post/__urp
You can use different cache manager for each application will also work same way I am using.
like :
#Bean(name = "myCacheManager")
public CacheManager cacheManager(RedisTemplate<String, Object> redisTemplate) {
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
return cacheManager;
}
#Bean(name ="customKeyGenerator")
public KeyGenerator keyGenerator() {
return new KeyGenerator() {
#Override
public Object generate(Object o, Method method, Object... objects) {
// This will generate a unique key of the class name, the method name,
// and all method parameters appended.
StringBuilder sb = new StringBuilder();
sb.append(o.getClass().getName());
sb.append(method.getName());
for (Object obj : objects) {
sb.append(obj.toString());
}
return sb.toString();
}
};
}