[PR #23845] refactor: improve Redis wrapper type hints and fix None value handling #30418

Closed
opened 2026-02-21 20:47:27 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/23845

State: closed
Merged: Yes


Fixes #23844

Summary

This PR improves the Redis wrapper's type hints and fixes a bug where potential None values from Redis operations weren't being handled properly.

Changes:

  1. Improved Redis wrapper type hints: Added TYPE_CHECKING block with proper type annotations for commonly used Redis methods, enabling IDE autocomplete and better static analysis
  2. Enhanced type support: Added support for timedelta in setex and expire methods, and numeric keys in zadd mapping
  3. Bug fix: Fixed queue_monitor_task.py to properly handle cases where Redis returns None or configuration is missing
  4. Backward compatibility: All changes maintain full backward compatibility - type hints are only used during static analysis, not at runtime

Screenshots

Before After
image image

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/23845 **State:** closed **Merged:** Yes --- Fixes #23844 ## Summary This PR improves the Redis wrapper's type hints and fixes a bug where potential `None` values from Redis operations weren't being handled properly. ### Changes: 1. **Improved Redis wrapper type hints**: Added `TYPE_CHECKING` block with proper type annotations for commonly used Redis methods, enabling IDE autocomplete and better static analysis 2. **Enhanced type support**: Added support for `timedelta` in `setex` and `expire` methods, and numeric keys in `zadd` mapping 3. **Bug fix**: Fixed `queue_monitor_task.py` to properly handle cases where Redis returns `None` or configuration is missing 4. **Backward compatibility**: All changes maintain full backward compatibility - type hints are only used during static analysis, not at runtime ## Screenshots | Before | After | |--------|-------| | <img width="377" height="77" alt="image" src="https://github.com/user-attachments/assets/8901049a-433e-41c6-819e-f8e4487d45b6" /> | <img width="461" height="282" alt="image" src="https://github.com/user-attachments/assets/ea9a8c35-1afd-4118-8ed7-614ae99db997" /> | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:47:27 -05:00
yindo closed this issue 2026-02-21 20:47:27 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30418