Files
export-telegram-group-members/session_store.py
T
tiennm99 f03099a18e feat: store session and exports in redis for cross-device portability
Replace the device-bound Telethon .session file and local CSV folders with
Redis-backed storage so the tool runs on any device from just .env.

- StringSession persisted at <prefix>:session:<phone> (no re-login per device)
- each group export saved as one self-contained JSON key per run:
  <prefix>:run:<phone>:<yyyymmddhhmmss>:<group_id>
- REDIS_PREFIX namespaces all keys; applied via a single key() helper
- no cross-key references: deleting any key cannot corrupt another's state
- list_exports() lists history, tolerant of deleted/corrupt keys
2026-06-08 16:49:34 +07:00

20 lines
602 B
Python

"""Load/save the Telethon StringSession from Redis.
The session string grants full account access; it lives only in Redis (behind
TLS/auth), never on local disk. Deleting the key simply forces a clean re-login.
"""
from config import key, phone, redis_client
_SESSION_KEY = key('session', phone)
def load_session():
"""Return the stored StringSession string, or None if not yet authenticated."""
return redis_client.get(_SESSION_KEY)
def save_session(session_string):
"""Persist the StringSession string for reuse on any device."""
redis_client.set(_SESSION_KEY, session_string)