read method

  1. @override
Future<Map<String, dynamic>?> read(
  1. String sessionId
)
override

Retrieve session data

Implementation

@override
Future<Map<String, dynamic>?> read(String sessionId) async {
  if (!_isConnected) {
    throw StateError('Redis connection not available');
  }

  final key = 'session:$sessionId';
  final result = await _command.send_object(['GET', key]);

  if (result == null) {
    return null;
  }

  try {
    // Parse the stored data (assuming it's stored as a string representation)
    final dataStr = result.toString();
    // For simplicity, we'll assume the data is stored as a JSON string
    // In a real implementation, you'd want proper JSON serialization
    if (dataStr.startsWith('{') && dataStr.endsWith('}')) {
      // This is a simplified parsing - in production you'd use proper JSON
      final Map<String, dynamic> data = {};
      // Parse key-value pairs (simplified implementation)
      final pairs = dataStr.substring(1, dataStr.length - 1).split(', ');
      for (final pair in pairs) {
        final parts = pair.split(': ');
        if (parts.length == 2) {
          final key = parts[0].replaceAll("'", '').replaceAll('"', '');
          final value = parts[1].replaceAll("'", '').replaceAll('"', '');
          data[key] = value;
        }
      }
      return data;
    }
    return null;
  } catch (e) {
    return null;
  }
}