Skip to content

Commit

Permalink
Added redis dependency check
Browse files Browse the repository at this point in the history
  • Loading branch information
coder2020official committed Jul 12, 2024
1 parent 676597c commit 5bd4271
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion telebot/storage/redis_storage.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import json
import redis
from telebot.storage.base_storage import StateStorageBase, StateContext
from typing import Optional, Union

redis_installed = True
try:
import redis
except ImportError:
redis_installed = False

class StateRedisStorage(StateStorageBase):
def __init__(self, host='localhost', port=6379, db=0, password=None,
prefix='telebot',
redis_url=None,
connection_pool: redis.ConnectionPool=None,
separator: Optional[str]=":",
) -> None:

if not redis_installed:
raise ImportError("Redis is not installed. Please install it via pip install redis")

self.separator = separator
self.prefix = prefix
if not self.prefix:
Expand Down

0 comments on commit 5bd4271

Please sign in to comment.