MCPcopy
hub / github.com/redis/redis-py / test_multi_reverse_range

Function test_multi_reverse_range

tests/test_asyncio/test_timeseries.py:581–776  ·  view source on GitHub ↗
(decoded_r: redis.Redis)

Source from the content-addressed store, hash-verified

579@pytest.mark.redismod
580@skip_ifmodversion_lt("1.10.0", "timeseries")
581async def test_multi_reverse_range(decoded_r: redis.Redis):
582 await decoded_r.ts().create(KEY1, labels={"Test": "This", "team": "ny"})
583 await decoded_r.ts().create(
584 KEY2, labels={"Test": "This", "Taste": "That", "team": "sf"}
585 )
586 for i in range(100):
587 await decoded_r.ts().add(KEY1, i, i % 7)
588 await decoded_r.ts().add(KEY2, i, i % 11)
589
590 # ``expected_response_shape`` is ``"unified"`` for
591 # ``legacy_responses=False`` (any protocol) and ``"legacy_resp3"`` for
592 # ``protocol=3`` with ``legacy_responses=True``. The unified shape
593 # always emits ``[labels, [], samples]`` (samples at index 2); legacy
594 # RESP3 preserves the wire layout, appending an extra ``sources``
595 # element under GROUPBY which pushes samples to index 3.
596 groupby_samples_idx = 2 if expected_response_shape(decoded_r) == "unified" else 3
597
598 res = await decoded_r.ts().mrange(0, 200, filters=["Test=This"])
599 assert res is not None
600 assert 2 == len(res)
601 if expects_resp2_shape(decoded_r):
602 assert 100 == len(res[0][KEY1][1])
603
604 res = await decoded_r.ts().mrange(0, 200, filters=["Test=This"], count=10)
605 assert res is not None
606 assert 10 == len(res[0][KEY1][1])
607
608 for i in range(100):
609 await decoded_r.ts().add(KEY1, i + 200, i % 7)
610 res = await decoded_r.ts().mrevrange(
611 0, 500, filters=["Test=This"], aggregation_type="avg", bucket_size_msec=10
612 )
613 assert res is not None
614 assert 2 == len(res)
615 assert 20 == len(res[0][KEY1][1])
616 assert {} == res[0][KEY1][0]
617
618 # test withlabels
619 res = await decoded_r.ts().mrevrange(
620 0, 200, filters=["Test=This"], with_labels=True
621 )
622 assert res is not None
623 assert {"Test": "This", "team": "ny"} == res[0][KEY1][0]
624
625 # test with selected labels
626 res = await decoded_r.ts().mrevrange(
627 0, 200, filters=["Test=This"], select_labels=["team"]
628 )
629 assert res is not None
630 assert {"team": "ny"} == res[0][KEY1][0]
631 assert {"team": "sf"} == res[1][KEY2][0]
632
633 # test filterby
634 res = await decoded_r.ts().mrevrange(
635 0,
636 200,
637 filters=["Test=This"],
638 filter_by_ts=[i for i in range(10, 20)],

Callers

nothing calls this directly

Calls 7

expected_response_shapeFunction · 0.90
expects_resp2_shapeFunction · 0.90
mrangeMethod · 0.80
mrevrangeMethod · 0.80
createMethod · 0.45
tsMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected