Esempio n. 1
0
def get_memory_cache_stats() -> caching_domain.MemoryCacheStats:
    """Returns a memory profile of the redis cache. Visit
    https://redis.io/commands/memory-stats for more details on what exactly is
    returned.

    Returns:
        MemoryCacheStats. MemoryCacheStats object containing the total allocated
        memory in bytes, peak memory usage in bytes, and the total number of
        keys stored as values.
    """
    redis_full_profile = OPPIA_REDIS_CLIENT.memory_stats()
    memory_stats = caching_domain.MemoryCacheStats(
        redis_full_profile['total.allocated'],
        redis_full_profile['peak.allocated'], redis_full_profile['keys.count'])

    return memory_stats
Esempio n. 2
0
def get_memory_cache_stats() -> caching_domain.MemoryCacheStats:
    """Returns a memory profile of the redis cache. Visit
    https://redis.io/commands/memory-stats for more details on what exactly is
    returned.

    Returns:
        MemoryCacheStats. MemoryCacheStats object containing the total allocated
        memory in bytes, peak memory usage in bytes, and the total number of
        keys stored as values.
    """
    # We have ignored [attr-defined] below because there is some error in
    # the redis typeshed. Typestubs don't define the method memory_stats()
    # for the redis.StrictRedis object.
    # TODO(#13617): Update our typeshed after redis stubs are improved in
    # typeshed. Then the ignore[attr-defined] used below can be removed.
    redis_full_profile = OPPIA_REDIS_CLIENT.memory_stats(
    )  # type: ignore[attr-defined]
    memory_stats = caching_domain.MemoryCacheStats(  # type: ignore[no-untyped-call]
        redis_full_profile.get('total.allocated'),
        redis_full_profile.get('peak.allocated'),
        redis_full_profile.get('keys.count'))

    return memory_stats
Esempio n. 3
0
 def test_that_domain_object_is_created_correctly(self) -> None:
     memory_cache = caching_domain.MemoryCacheStats(64, 128, 16)
     self.assertEqual(memory_cache.total_allocated_in_bytes, 64)
     self.assertEqual(memory_cache.peak_memory_usage_in_bytes, 128)
     self.assertEqual(memory_cache.total_number_of_keys_stored, 16)