Pipeline#discard() replacement since Jedis version 4 #3505
-
Hi. I am in the process of upgrading Jedis dependency in one of our services from version 3.3.0 to the latest (as of now) Jedis version 4.4.3. On the Jedis 4 Breaking Changes page it is mentioned:
In our code we have a helper method which uses Pipeline object and the logic is wrapped in a try-catch block. Here is the related catch block: } catch (JedisException ex) {
if (pipeline != null) {
pipeline.discard();
}
throw ex;
} As you can see, we used Would appreciate your help. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 5 replies
-
When not in Transaction (MULTI) mode, DISCARD doesn't make any sense. It's not clear what's happening before and after the codeblock. I guess you can |
Beta Was this translation helpful? Give feedback.
-
Hi, @sazzad16. Thank you for your comment. Basically here the whole body of the method in question: protected <TResult> TResult executeInPipeline(Function<Pipeline, TResult> func) {
try (Jedis client = jedisPool.getResource()) {
Pipeline pipeline = client.pipelined();
TResult result;
try {
result = apply(func, pipeline);
pipeline.sync();
return result;
} catch (JedisException ex) {
if (pipeline != null) {
pipeline.discard();
}
throw ex;
}
}
}
private <TParam, TResult> TResult apply(Function<TParam, TResult> func, TParam parameter) {
return func.apply(parameter);
} As we can see, in the core of this method there is a call to another method As we can also see, the Jedis So what do you think of that? Will it be totally OK to just omit the |
Beta Was this translation helpful? Give feedback.
-
@informatik01 Your code uses |
Beta Was this translation helpful? Give feedback.
-
@sazzad16 Fixed my previous message. So what would you say now? |
Beta Was this translation helpful? Give feedback.
-
Remove |
Beta Was this translation helpful? Give feedback.
-
1) Regarding pipelines.So for pipelines the Thank you for confirming that with the new version it's OK to leave the code without 2) Regarding your comment:
You mean in that accidentally posted example with transactions? try {
result = apply(func, transaction);
transaction.exec();
return result;
} catch (JedisException ex) {
if (transaction != null) {
transaction.discard();
}
throw ex;
} Are you sure calling I know that Redis does not support traditional rollbacks which are common for relational databases. But on the official Redis website there's an article - "How transactions work in Redis", and although they do mention that Redis does not support rollbacks, they also suggest using the Here is the quote from that article (emphasis mine):
I didn't write the logic for the examples I presented above, I am just in the process of updating the dependencies and your explanation would be really useful (we could remove that So could you please briefly elaborate why you think calling |
Beta Was this translation helpful? Give feedback.
discard()
is also unnecessary even if your are using transaction but not in transaction mode.exec()
declares the end of a transaction mode irrespective of it's success or failure. So after callingexec()
, even if it fails, there is not an active transaction anymore. That's why I'm saying thatdiscard()
is unnecessary in your code.Usually in same code flow you use either EXEC or DISCARD, not both. You call EXEC to try completing the transaction. Or call DISCARD to abort. You don't need DISCARD after EXEC because if the EXEC is successful the transaction is completed and if the EXEC is failed the transaction is aborted (already).
I guess, if it were (current) me, I would've written your c…