Skip to content

请教一个问题,为什么 JetCache 用 Lettuce 返回的 RedisCommand 做 callback #908

Answered by areyouok
Roiocam asked this question in Q&A
Discussion options

You must be logged in to vote

我没完全看懂你的描述,但你提示了很重要的问题。我理解是这样的:

Cache类提供的是异步接口,对于使用jedis的场景来说它本身没有支持异步,所以是同步转异步的“伪异步”,对于lettuce来说就是真正的异步。

CompletableFuture虽然是用来做异步开发的,但它的回调很容易堵塞本来不该堵塞的IO线程,这很容易搞错。JetCache本身虽然没有在这类回调里面执行IO操作,但编解码操作也是比较耗时的(此外lettuce api的回调里面也不该执行解码)。这些操作包括

  • do_GET里面的解码操作。
  • CacheMonitor回调,其中就包括发送缓存失效通知时,对CacheMessage的编码操作。
  • BroadcastManager接收到CacheMessage,在回调中执行解码操作

可以把这些操作丢到另一个线程池里面去执行。

Replies: 5 comments 10 replies

Comment options

You must be logged in to vote
4 replies
@Roiocam
Comment options

@Roiocam
Comment options

@Roiocam
Comment options

@Roiocam
Comment options

Answer selected by Roiocam
Comment options

You must be logged in to vote
1 reply
@Roiocam
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Roiocam
Comment options

@areyouok
Comment options

@Roiocam
Comment options

Comment options

You must be logged in to vote
2 replies
@Roiocam
Comment options

@areyouok
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants