How to forward data to the specified state.var of the specified client based on the client_token?

How to forward data to the specified state.var of the specified client based on the client_token?
Is set_state okay? I didn’t understand how to use it.
Like an asynchronous notification sent by a third party to a specified user (which can be identified by a string), there needs to be a public API to receive the notification and forward it to the state.var of the specified client
I have used Redis’ PUB/SUB before, but I think it would be more efficient if it could be based on the client token.

1 Like

You would need to use a context that look like
with modify_state(StateName, token) as state:

However, if you are using Redis to have multiple workers, remember that there is no guarantee that the external hit on the public API will arrive on the same worker that currently has the WS for said client.
So in the end you would still need to use PUB/SUB to notify the update to the worker that has the websocket.

We want to eventually make this easier to do with maybe built-in pub/sub so users don’t have to implement it for each small changes, but we haven’t had the time to do it yet.

1 Like