Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Allow to hook load and save functions to use external session storage… #36
Conversation
|
Thanks for this, but Pyrogram is still pretty young and doesn't even persistently cache peers yet, as it should. A redis backend will surely make more sense if there were thousands of peers to store. |
| if callable(self.load_session_hook): | ||
| self.load_session_hook(self) | ||
| else: | ||
| self.load_session(self.session_name) |
delivrance
Mar 19, 2018
•
Member
Not sure if you indented it wrongly, but this piece of code is always needed:
self.session = Session(...)
Here is where Pyrogram creates a new connection to the server.
Not sure if you indented it wrongly, but this piece of code is always needed:
self.session = Session(...)Here is where Pyrogram creates a new connection to the server.
| @@ -17,6 +17,6 @@ | |||
| # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. | |||
|
|
|||
| from .chat_action import ChatAction | |||
| from .client import Client | |||
| from .client import Client, ApiKey, Proxy | |||
delivrance
Mar 19, 2018
Member
I saw your Pyroredis repo, and there is no need to store the proxy settings in a session.
A session should not depend on these information, users should be free to change their proxies regardless of the session used. The same applies for the api key (although I didn't see you using it)
I saw your Pyroredis repo, and there is no need to store the proxy settings in a session.
A session should not depend on these information, users should be free to change their proxies regardless of the session used. The same applies for the api key (although I didn't see you using it)
ezdev128
Mar 19, 2018
Author
The proxy settings is not stored into the redis session. Please re-check the code again.
The proxy settings is not stored into the redis session. Please re-check the code again.
delivrance
Mar 20, 2018
Member
I thought you were only dealing with sessions, and can't understand why you need Proxy (and ApiKey) to be available there. There is a different method that takes care of loading proxy and api key settings (load_config) and has nothing to do with load_session.
Maybe the auth key creation process inside load_session was confusing you a bit, if that's so we should find a nice way to move it from there. Creating a Session (and auth keys) should only be Client's job, and loading a session must happen before that.
I thought you were only dealing with sessions, and can't understand why you need Proxy (and ApiKey) to be available there. There is a different method that takes care of loading proxy and api key settings (load_config) and has nothing to do with load_session.
Maybe the auth key creation process inside load_session was confusing you a bit, if that's so we should find a nice way to move it from there. Creating a Session (and auth keys) should only be Client's job, and loading a session must happen before that.
delivrance
Mar 20, 2018
•
Member
What I'm thinking is returning False from load_session in case a session does not exist and the Client needs to create an auth key, this way we can move self.auth_key = Auth(...) outside.
What I'm thinking is returning False from load_session in case a session does not exist and the Client needs to create an auth key, this way we can move self.auth_key = Auth(...) outside.
ezdev128
Mar 20, 2018
Author
During the modification I had several objectives:
- External shared session storage in case of working > 1 of clients (like bot-mode) with the same account credentials.
- I had a problem with modification session prior to start() because start() overwrites self.session with own self.session = Session(..). So I had to hook it to modify session before self.session.start().
I think will be better if those two actions (session construction and session start) will be in separate methods, like:
def create_session(self):
self.session = Session(
self.dc_id,
self.test_mode,
self.proxy,
self.auth_key,
self.api_key.api_id,
client=self
)
def start(self):
self.load_config()
self.load_session(self.session_name)
if not self.session:
self.create_session()
...
self.session.start()
...
(or even move self.load_session() under create_session()), so it is possible to do something like:
client = Client(session_name='session_name', api_key=(api_id, api_hash))
client.create_session()
client.session.APP_VERSION = "PyRoGrAm"
...
client.start()
During the modification I had several objectives:
- External shared session storage in case of working > 1 of clients (like bot-mode) with the same account credentials.
- I had a problem with modification session prior to start() because start() overwrites self.session with own self.session = Session(..). So I had to hook it to modify session before self.session.start().
I think will be better if those two actions (session construction and session start) will be in separate methods, like:
def create_session(self):
self.session = Session(
self.dc_id,
self.test_mode,
self.proxy,
self.auth_key,
self.api_key.api_id,
client=self
)
def start(self):
self.load_config()
self.load_session(self.session_name)
if not self.session:
self.create_session()
...
self.session.start()
...(or even move self.load_session() under create_session()), so it is possible to do something like:
client = Client(session_name='session_name', api_key=(api_id, api_hash))
client.create_session()
client.session.APP_VERSION = "PyRoGrAm"
...
client.start()|
Closing because this needs a revamp since the introduction of storage engines. |


PR for the projects like https://github.com/ezdev128/pyrogram-session-redis