2

I have a list and I'm adding elements using RPUSH which returns the updated length of the list. My question is that, is it reliable to use the returned length - 1 as the index of the newly inserted item?

By reliable I mean, If I have multiple connections to Redis doing the same operation is it guaranteed there won't be any overlapping like the returned length actually returning after two RPUSH that occurred simultaneously or is that Redis' list operation atomic by default or do I need transactions?

4

1 回答 1

2

考虑到 redis 命令的原子性,您可以 100% 确定每个 RPUSH 之后都会有相应的整数回复,因此可以安全地假设您的元素的索引是 (integer_reply - 1)。我在这里回答了一个与此相关的问题

于 2012-06-12T06:02:37.113 回答