def _insert(self, meter_reading: MeterReading,
             pipeline: redis.client.Pipeline) -> None:
     """Helper method to insert a meter reading."""
     reading_data = MeterReadingSchema().dump(meter_reading)
     pipeline.xadd(self.key_schema.global_feed_key(),
                   reading_data,
                   maxlen=self.SITE_MAX_FEED_LENGTH)
     pipeline.xadd(self.key_schema.feed_key(reading_data.get('site_id')),
                   reading_data,
                   maxlen=self.GLOBAL_MAX_FEED_LENGTH)
Example #2
0
 def _insert(self, meter_reading: MeterReading,
             pipeline: redis.client.Pipeline) -> None:
     """Helper method to insert a meter reading."""
     # START Challenge #6
     global_key = self.key_schema.global_feed_key()
     site_key = self.key_schema.feed_key(meter_reading.site_id)
     pipeline.xadd(global_key, MeterReadingSchema().dump(meter_reading),
                   maxlen=self.GLOBAL_MAX_FEED_LENGTH)
     pipeline.xadd(site_key, MeterReadingSchema().dump(meter_reading),
                   maxlen=self.SITE_MAX_FEED_LENGTH)
Example #3
0
File: feed.py Project: jkpr/ru102py
 def _insert(self, meter_reading: MeterReading,
             pipeline: redis.client.Pipeline) -> None:
     """Helper method to insert a meter reading."""
     # START Challenge #6
     field_values = MeterReadingSchema().dump(meter_reading)
     pipeline.xadd(self.key_schema.global_feed_key(),
                   field_values,
                   maxlen=FeedDaoRedis.GLOBAL_MAX_FEED_LENGTH)
     pipeline.xadd(self.key_schema.feed_key(meter_reading.site_id),
                   field_values,
                   maxlen=FeedDaoRedis.SITE_MAX_FEED_LENGTH)
Example #4
0
    def _insert(self, meter_reading: MeterReading,
                pipeline: redis.client.Pipeline) -> None:
        """Helper method to insert a meter reading."""
        # START Challenge #6

        # Create variables for ease of use in redis command as well as avoid long statement
        global_key = self.key_schema.global_feed_key()
        site_key = self.key_schema.feed_key(meter_reading.site_id)
        # Avoid repeating doing dump twice
        serialized_meter_reading = MeterReadingSchema().dump(meter_reading)

        pipeline.xadd(global_key, \
        	serialized_meter_reading, \
        	maxlen=self.GLOBAL_MAX_FEED_LENGTH)
        pipeline.xadd(site_key, \
        	serialized_meter_reading, \
        	maxlen=self.SITE_MAX_FEED_LENGTH)
Example #5
0
 def get_recent(self, key: str, limit: int) -> List[MeterReading]:
     return [
         MeterReadingSchema().load(entry[1])
         for entry in self.redis.xrevrange(key, count=limit)
     ]