arjunmehta / node-georedis

Super fast geo queries.
MIT License
192 stars 33 forks source link

Upsert functionality #2

Closed jesseditson closed 8 years ago

jesseditson commented 8 years ago

Hey, thanks for this awesome library.

I was wondering about the difference between addLocation and updateLocation - in my application, I am looking to do an "upsert" - just to add or update depending on if the location already exists. Does one or both of these methods already expose this functionality? And if not, is there a way to avoid doing a get and then an update or add depending on the existence of the value returned by get?

arjunmehta commented 8 years ago

Hey there @jesseditson,

The difference for addLocation and updateLocation is purely semantic. They perform the same thing in reality, that is an "upsert" (as you call it).

That is, if the location doesn't exist it will be added, and if it does it will be updated, no matter which method you use. So take your pick :)

You can see more in the source here. You can see they're both actually the same method :)

The reason for this behavior is because Redis automatically does that by default for the commands we're using (ZADD for emulation mode and GEOADD for native mode).

jesseditson commented 8 years ago

Ah, fantastic! Thanks so much for the clarification, and thanks again for the lib!

arjunmehta commented 8 years ago

Thank you! Let me know if you encounter any strange behaviour. It was a recent rewrite (to 3.0.0) so I'm on edge :)

jesseditson commented 8 years ago

Absolutely! I'm working it in to a project now, I'll be sure to file anything I run across here!