push method

  1. @override
Future<void> push({
  1. required String collection,
  2. required String recordId,
  3. required Map<String, dynamic> data,
  4. required DateTime timestamp,
})
override

Push data to backend

Implementation

@override
Future<void> push({
  required String collection,
  required String recordId,
  required Map<String, dynamic> data,
  required DateTime timestamp,
}) async {
  final key = _getKey(collection, recordId);
  final indexKey = _getIndexKey(collection);
  final currentVersion = await command.send_object(['HGET', key, 'version']);
  final version =
      currentVersion != null ? int.parse(currentVersion.toString()) + 1 : 1;

  await command.send_object([
    'HSET',
    key,
    'data',
    jsonEncode(data),
    'updated_at',
    timestamp.toIso8601String(),
    'version',
    version.toString(),
  ]);

  await command.send_object([
    'ZADD',
    indexKey,
    timestamp.millisecondsSinceEpoch.toString(),
    recordId,
  ]);
}