ITADN

Safe operation methods (safeGet, safeSet, etc.) that return null instead of throwing

#3180ClosedYoussef-codin 创建于 2026-02-19
Y
Youssef-codincommented
### Motivation As someone who hates using Try and catch, I would very much appreciate this. It could also return a 'success' variable but i prefer it returning just null tbh. I have a code example for both. The reason I raised this issue is because, at least in my application, I don't want my whole app to crash if Redis doesn't work (for whatever reason) and having to use Try and catch just clutters everything and is very annoying. ### Basic Code Example ```JavaScript // option A const data = await redisClient.safeGet('key'); // null // option B const result = await redisClient.safeGet('key'); // { success: true, data: 'value' } // { success: true, data: null } key doesn't exist // { success: false, error: Error } operation failed ``` P.S. Happy to implement this myself if the maintainers are on board.
关闭于 2026-02-20 1 条评论