Write multiple hash field across different keys atomically

300 views
Skip to first unread message

Boyang Chen

unread,
Jan 8, 2022, 6:02:42 PM1/8/22
to Redis DB
Hey there,

I'm new to Redis, and we have a use case to write multiple hash fields in an atomic manner, is that something Redis could add support for? To be specific, hmset doesn't help because I'm trying to write:
key A, field x
key B, field y

atomically, not key A, field (x, y)

I know there is transaction support in Redis, but since we don't need RMW, so probably worth getting a standalone API. Let me know what you think.

Viktor Söderqvist

unread,
Jan 9, 2022, 1:01:38 PM1/9/22
to redi...@googlegroups.com
MULTI
HSET A x hello
HSET B y world
EXEC

The commands can be sent in a pipeline so there is no extra
round-trip. Multi-exec is very fast. It simply queues up the
queries and executes them together.

I think it's very unlikely that Redis will add special command to
write to multiple keys simultaneously.

Cheers,
Viktor
> --
> You received this message because you are subscribed to the Google
> Groups "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to redis-db+u...@googlegroups.com
> <mailto:redis-db+u...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/redis-db/32d07e8d-c038-4fbf-9e5f-c593e4d6d0edn%40googlegroups.com
> <https://groups.google.com/d/msgid/redis-db/32d07e8d-c038-4fbf-9e5f-c593e4d6d0edn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Boyang Chen

unread,
Jan 9, 2022, 3:30:46 PM1/9/22
to redi...@googlegroups.com
Thanks, however I don’t think pipeline will have any transactional guarantee?

To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redis-db/67961083-b70c-ddf8-fd2c-dd575df5a224%40est.tech.

Viktor Söderqvist

unread,
Jan 9, 2022, 3:36:20 PM1/9/22
to redi...@googlegroups.com
Pipeline has nothing to do with transactions.

Pipeline just means that you send multiple commands without waiting for
the reply for the previous commands.

MULTI-(commands)-EXEC is a transaction. You can send one command and
wait for reply before you send the next command, or you can send all
commands at once in a pipeline.

Only HSET a x hello; HSET b y world in a pipeline (without MULTI) is not
a transaction.
> <mailto:redis-db%2Bunsu...@googlegroups.com>
> > <mailto:redis-db+u...@googlegroups.com
> <mailto:redis-db%2Bunsu...@googlegroups.com>>.
> <https://groups.google.com/d/msgid/redis-db/32d07e8d-c038-4fbf-9e5f-c593e4d6d0edn%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/redis-db/32d07e8d-c038-4fbf-9e5f-c593e4d6d0edn%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to redis-db+u...@googlegroups.com
> <mailto:redis-db%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/redis-db/67961083-b70c-ddf8-fd2c-dd575df5a224%40est.tech
> <https://groups.google.com/d/msgid/redis-db/67961083-b70c-ddf8-fd2c-dd575df5a224%40est.tech>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to redis-db+u...@googlegroups.com
> <mailto:redis-db+u...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/redis-db/CABbPKA%2BVUL0n1j%3DWBRDNEf2LQdomJbHC1%2BAD_oezbHyGLKCm%2BA%40mail.gmail.com
> <https://groups.google.com/d/msgid/redis-db/CABbPKA%2BVUL0n1j%3DWBRDNEf2LQdomJbHC1%2BAD_oezbHyGLKCm%2BA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages