MCPcopy
hub / github.com/reflex-dev/reflex / _get_token_owner

Method _get_token_owner

reflex/utils/token_manager.py:407–433  ·  view source on GitHub ↗

Get the instance ID of the owner of a token. Args: token: The client token. refresh: Whether to fetch the latest record from Redis. Returns: The instance ID of the owner, or None if not found.

(self, token: str, refresh: bool = False)

Source from the content-addressed store, hash-verified

405 )
406
407 async def _get_token_owner(self, token: str, refresh: bool = False) -> str | None:
408 """Get the instance ID of the owner of a token.
409
410 Args:
411 token: The client token.
412 refresh: Whether to fetch the latest record from Redis.
413
414 Returns:
415 The instance ID of the owner, or None if not found.
416 """
417 if (
418 not refresh
419 and (socket_record := self.token_to_socket.get(token)) is not None
420 ):
421 return socket_record.instance_id
422
423 redis_key = self._get_redis_key(token)
424 try:
425 record_pkl = await self.redis.get(redis_key)
426 if record_pkl:
427 socket_record = pickle.loads(record_pkl)
428 self.token_to_socket[token] = socket_record
429 self.sid_to_token[socket_record.sid] = token
430 return socket_record.instance_id
431 except Exception as e:
432 console.error(f"Redis error getting token owner: {e}")
433 return None
434
435 async def emit_lost_and_found(
436 self,

Calls 2

_get_redis_keyMethod · 0.95
getMethod · 0.45

Tested by 1