Comments (11)
Sorry, but I don't understand why this issue was closed. Has this been resolved? I think the vertx timer is simply a workaround. Its strange that a storage library like Redis would not natively support a timeout option...
from vertx-redis-client.
Just use a vertx timer for that, that would be the easiest.
from vertx-redis-client.
So does the redis handler get call after that?, can I use redis-client for other command in timer handler context?
from vertx-redis-client.
here some code:
Handler<AsyncResult<String>> handler = res -> {
// here your success handler as usual...
};
final long timerId = vertx.setTimer(30000l, t -> handler.handle(Future.failedFuture("timeout")));
redis.get(key, res -> {
if (vertx.cancelTimer(timerId)) {
handler.handle(res);
}
});
So you declare the handler outside the redis command, and wrap it with a timer, in this case i set call failure if no reply arrives in 30 seconds. If a reply arrives before it cancels the timer and delegates to your handler, if a timer has already been triggered and a reply comes later the cancel timer returns false since the timer does not exist anymore and your handler is not called twice.
Probably you could wrap this in some helper method and make the code cleaner.
from vertx-redis-client.
hello, I'm back, I still need to clear the state of RedisClient after the timeout fire.
for example, I have follow sequence:
browser request - > RedisClient -> send request -> redis_server busy for a moment -> client fire timedout handler ->
next browser request -> RedisClient -> send request -> redis_server response for the first request
Actually, we have a RPC service that use redis protocol as redis server side, sometime it take time for this server to response, I just want to ignore any slow response and continue other.
So, is there any risk that the second request will get the reply correspond to the first request?
from vertx-redis-client.
for each request you specify a handler (callback if you prefer) this handler is specific to the command so ignoring it means that the handler if triggered but you then have some logic to ignore any further processing. This means that no handler will receive replies from other requests it is 1 to 1 mapping.
from vertx-redis-client.
Yes, I see, but when the timeout fired, how RedisClient handle the late incoming reply (discard it? ), does RedisClient clear the receive buffer before send a command? should I close the RedisClient instance and create a new one for safe?
Thanks for your explain.
from vertx-redis-client.
hi, there is no receive buffer, what happens is like this:
your code sends a command and passes a handler, the redis client has a FIFO where the handlers are added, once a reply arrives from the redis server the top of the FIFO is removed and called with the incoming message. Now the timer has to do the following:
if handler has not been called, then mark it to do nothing once it is called by the client, else do nothing.
Please see the code on the comment: #26 (comment)
for each command you send you create a timer, then the handler is:
cancel the timer, if you can cancel it means it has been called yet (no timeout yet) therefore call the real handler.
If a reply comes after the cancel was triggered the if statement will be false so the lower handler will not be triggered.
from vertx-redis-client.
ok, I was forget that the first reply was ignore by this block
if (vertx.cancelTimer(timerId)) {
handler.handle(res);
}
Thank you.
from vertx-redis-client.
@ltamrazov Redis does not support timeout see their docs: https://redis.io/commands
You can add it to your code as stated in these comments but that would not be in any way related to redis and it can introduce strange behaviour. For example if a DEL command takes too long you would trigger a timeout and assume it failed but since redis does not have the concept of timeout with enough time and if the server does not crash the key will be deleted.
So that was the reason this was closed as won't fix.
from vertx-redis-client.
Yes, agreed. Thanks for the clarification.
from vertx-redis-client.
Related Issues (20)
- Pick the protocol from the url if provided HOT 1
- Create too many connections to server HOT 4
- Cluster mode (MOVED Exception) HOT 3
- The vertx redis reconnection demo introduced at docs cannot work in the case when redis instances shutdown and get back to ready. HOT 4
- Align Redis deprecations with RedisAPI methods
- hight cpu usage after pressure test HOT 6
- redis client shared in multiple verticles in high concurrency load will make redis call get response belonged to another request with some specific keys HOT 7
- Seeing unhandled exception when client reacts to sentinel failover HOT 2
- Unexpected behavior of UNSUBSCRIBE with cluster mode HOT 5
- Getting io.vertx.core.impl.NoStackTraceThrowable: Cannot connect to any of the provided endpoints Error while trying to connect to redis in replication mode HOT 4
- which situation will make RedisStandaloneConnection message handler a null value HOT 1
- RedisClusterClient gives much higher load to first healthy node HOT 18
- always have the "Redis waiting Queue is full" error
- Missing connection with endpoint fallback in cluster connection HOT 2
- Getting different result when executing `FT.SEARCH` when using `redis/redis-stack:7.0.6-RC8` vs `redis/redis-stack-server:7.2.0-v5`. (Multi is a Map) HOT 6
- How to catch io.vertx.core.impl.NoStackTraceThrowable HOT 4
- [RedisConnectionManager] io.netty.channel.StacklessClosedChannelException throwed HOT 1
- Command.XREADGROUP error MOVED HOT 7
- Expose more properties through CommandReporter
- Support for FalkorDB
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 vertx-redis-client.