I've read in a couple places that Redis is idempotent, so a repeated call to SetEntryInHash() will have no effect, right?
Is there any good case for using SetEntryInHashIfNotExists()? Can this give quicker results than just blindly calling SetEntryInHash()?
Idempotent means you can replay the same action multiple times and it will have the same side-effect. Only idempotent operations like SADD are idempotent, i.e. after calling that 1 or more than 1 times you will end up with the same result, i.e. a single item in the set.
Adding to a redis list, e.g. LINSERT is by contrast not idempotent as every new item adds a new item to the redis list.
If you want to know how operations in ServiceStack's Redis Client are implemented, just inspect the source code. SetEntryInHash and SetEntryInHashIfNotExists are here. They both call HSET and HSETNX respectively. Refer to the documentation in redis to learn about the behavior of each operation.
@mythz is right, with the source code at hand, quick to find the real answer, not to mention also including links to the redis documentation. I was curious about the difference myself, and thought I would post the clarification here for others.
HSETNX : Sets field in the hash stored at key to value, only if field does not yet exist. If key does not exist, a new key holding a hash is created. If field already exists, this operation has no effect.
HSET : Sets field in the hash stored at key to value. If key does not exist, a new key holding a hash is created. If field already exists in the hash, it is overwritten.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With