Skip to content

How to batch lots of HGET from different keys with caching? #179

Answered by rueian
0x079 asked this question in Q&A
Discussion options

You must be logged in to vote

You are right. Your first example will result in a lot of round trips.

And your second example is the best you can do. It will incur only one round trip and send only those cache missed commands.

c.DoMulti is simply a batched version of c.Do that sends multiple commands in one round trip. So does c.DoMultiCache with consulting local cache first.

c.B().Multi() is just the redis MULTI command, since c.B() is a command builder. To use redis transaction, you can freely construct related commands to suite your needs, for example:

client.Dedicated(func(c rueidis.DedicatedClient) error {
    // watch keys first
    c.Do(ctx, c.B().Watch().Key("k1", "k2").Build())
    // perform read here
    c.Do(

Replies: 1 comment 2 replies

Comment options

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

@rueian
Comment options

Answer selected by 0x079
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