3 ms·
The HSET calls are not just unnecessary, they're a bug. It introduces the possibility of a race condition where a view or like happens between the HGET and HSET
by bastawhiz 2y ago
The HSET calls are not just unnecessary, they're a bug. It introduces the possibility of a race condition where a view or like happens between the HGET and HSET. HSETing the values to zero doesn't actually make anything faster or more correct, it just introduces the possibility of overwriting a value that came in moments ago.
- chilling 2y agoso how would you approach this?
- porridgeraisin 2y agoJust do hincrby alone, if it doesn't exist it will automatically become 1
- chilling 2y agoYou are right. It just should be like so: Get: const likes = (await kv.hget(postTitle, "likes")) || 0 Post: const likes = await kv.hincrby(postTitle, "likes", 1);