5 ms·
Redis has the INCR command that does this in redis without the additional round-trips (and race conditions). It also sets the value to 0 if the key doesn't exis
by foepys 5y ago
Redis has the INCR command that does this in redis without the additional round-trips (and race conditions). It also sets the value to 0 if the key doesn't exist.
So, I actually consider this to be exactly the bad behavior that people accuse Copilot of.
- gfosco 5y agoThis was just one of its suggestions, but you're right of course.. it's all based on the training data and idioms used there. If it doesn't weight more modern code higher, if it's not aware of new versions and methods, it isn't going to be super intelligent.. but it can still give you some ideas.
- speedgoose 5y agoYes it's not very shinning there. I would also throw the error instead of printing the error to the console and returning undefined.
- ponyous 5y agoYou are in a callback there. Goodbye your error!
- speedgoose 5y agoOh right. I once made a layer on top of the redis client to use promises because callbacks are a pain to deal with.