接口 SessionKey

所有已知实现类:
SimpleSessionKey

public interface SessionKey
Marker interface for session identifiers.

Users can define custom session identifier structures for complex scenarios like multi-tenant applications. The default implementation SimpleSessionKey uses a simple string.

Custom Session implementations can interpret SessionKey structures to determine storage strategies (e.g., multi-tenant database sharding).

Example custom implementation:


 // Multi-tenant scenario
 public record TenantSessionKey(
     String tenantId,
     String userId,
     String sessionId
 ) implements SessionKey {}

 // Usage
 session.save(new TenantSessionKey("tenant_001", "user_123", "session_456"), "agent_meta", state);
 
另请参阅:
  • 方法概要

    修饰符和类型
    方法
    说明
    default String
    Returns a string identifier for this session key.
  • 方法详细资料

    • toIdentifier

      default String toIdentifier()
      Returns a string identifier for this session key.

      This method is used by Session implementations to convert the session key to a string suitable for storage (e.g., as a directory name, database key, or Redis key prefix).

      The default implementation uses JSON serialization. Implementations like SimpleSessionKey override this to return the session ID directly for better readability.

      返回:
      a string identifier for this session key