(one_session)
Iterate over one or all existing django sessions

    Assumes that redis is the default cache in which all sessions are stored.
Iterate over one or all existing django sessions
Iterate over one or all existing django sessions
def iter_sessions(one_session):
    """Iterate over one or all existing django sessions

    Assumes that redis is the default cache in which all sessions are stored.
    """
    assert settings.SESSION_ENGINE == "django.contrib.sessions.backends.cache", \
        f"unsupported session engine: {settings.SESSION_ENGINE}"
    engine = import_module(settings.SESSION_ENGINE)

    if one_session:
        session_key = getpass(prompt="Session key: ")
        yield engine.SessionStore(session_key)
        return

    cache = caches[settings.SESSION_CACHE_ALIAS]
    prefix_length = len(engine.SessionStore.cache_key_prefix)
    for key in cache.iter_keys(engine.SessionStore.cache_key_prefix + "*"):
        session_key = key[prefix_length:]
        yield engine.SessionStore(session_key)
def iter_sessions ( one_session ) : assert settings . SESSION_ENGINE == "django.contrib.sessions.backends.cache" , f"unsupported session engine: {settings.SESSION_ENGINE}" engine = import_module ( settings . SESSION_ENGINE ) if one_session : session_key = getpass ( prompt = "Session key: " ) yield engine . SessionStore ( session_key ) return cache = caches [ settings . SESSION_CACHE_ALIAS ] prefix_length = len ( engine . SessionStore . cache_key_prefix ) for key in cache . iter_keys ( engine . SessionStore . cache_key_prefix + "*" ) : session_key = key [ prefix_length : ] yield engine . SessionStore ( session_key )