图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.1 KiB

  1. from ..helpers import nativestr
  2. from .utils import list_to_dict
  3. class TSInfo:
  4. """
  5. Hold information and statistics on the time-series.
  6. Can be created using ``tsinfo`` command
  7. https://redis.io/docs/latest/commands/ts.info/
  8. """
  9. rules = []
  10. labels = []
  11. sourceKey = None
  12. chunk_count = None
  13. memory_usage = None
  14. total_samples = None
  15. retention_msecs = None
  16. last_time_stamp = None
  17. first_time_stamp = None
  18. max_samples_per_chunk = None
  19. chunk_size = None
  20. duplicate_policy = None
  21. def __init__(self, args):
  22. """
  23. Hold information and statistics on the time-series.
  24. The supported params that can be passed as args:
  25. rules:
  26. A list of compaction rules of the time series.
  27. sourceKey:
  28. Key name for source time series in case the current series
  29. is a target of a rule.
  30. chunkCount:
  31. Number of Memory Chunks used for the time series.
  32. memoryUsage:
  33. Total number of bytes allocated for the time series.
  34. totalSamples:
  35. Total number of samples in the time series.
  36. labels:
  37. A list of label-value pairs that represent the metadata
  38. labels of the time series.
  39. retentionTime:
  40. Retention time, in milliseconds, for the time series.
  41. lastTimestamp:
  42. Last timestamp present in the time series.
  43. firstTimestamp:
  44. First timestamp present in the time series.
  45. maxSamplesPerChunk:
  46. Deprecated.
  47. chunkSize:
  48. Amount of memory, in bytes, allocated for data.
  49. duplicatePolicy:
  50. Policy that will define handling of duplicate samples.
  51. Can read more about on
  52. https://redis.io/docs/latest/develop/data-types/timeseries/configuration/#duplicate_policy
  53. """
  54. response = dict(zip(map(nativestr, args[::2]), args[1::2]))
  55. self.rules = response.get("rules")
  56. self.source_key = response.get("sourceKey")
  57. self.chunk_count = response.get("chunkCount")
  58. self.memory_usage = response.get("memoryUsage")
  59. self.total_samples = response.get("totalSamples")
  60. self.labels = list_to_dict(response.get("labels"))
  61. self.retention_msecs = response.get("retentionTime")
  62. self.last_timestamp = response.get("lastTimestamp")
  63. self.first_timestamp = response.get("firstTimestamp")
  64. if "maxSamplesPerChunk" in response:
  65. self.max_samples_per_chunk = response["maxSamplesPerChunk"]
  66. self.chunk_size = (
  67. self.max_samples_per_chunk * 16
  68. ) # backward compatible changes
  69. if "chunkSize" in response:
  70. self.chunk_size = response["chunkSize"]
  71. if "duplicatePolicy" in response:
  72. self.duplicate_policy = response["duplicatePolicy"]
  73. if type(self.duplicate_policy) == bytes:
  74. self.duplicate_policy = self.duplicate_policy.decode()
  75. def get(self, item):
  76. try:
  77. return self.__getitem__(item)
  78. except AttributeError:
  79. return None
  80. def __getitem__(self, item):
  81. return getattr(self, item)