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

Function test_multi_range_advanced

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

Source from the content-addressed store, hash-verified

430@pytest.mark.redismod
431@skip_ifmodversion_lt("1.10.0", "timeseries")
432async def test_multi_range_advanced(decoded_r: redis.Redis):
433 await decoded_r.ts().create(KEY1, labels={"Test": "This", "team": "ny"})
434 await decoded_r.ts().create(
435 KEY2, labels={"Test": "This", "Taste": "That", "team": "sf"}
436 )
437 for i in range(100):
438 await decoded_r.ts().add(KEY1, i, i % 7)
439 await decoded_r.ts().add(KEY2, i, i % 11)
440
441 # test with selected labels
442 res = await decoded_r.ts().mrange(
443 0, 200, filters=["Test=This"], select_labels=["team"]
444 )
445 assert res is not None
446 if expects_resp2_shape(decoded_r):
447 assert {"team": "ny"} == res[0][KEY1][0]
448 assert {"team": "sf"} == res[1][KEY2][0]
449
450 # test with filterby
451 res = await decoded_r.ts().mrange(
452 0,
453 200,
454 filters=["Test=This"],
455 filter_by_ts=[i for i in range(10, 20)],
456 filter_by_min_value=1,
457 filter_by_max_value=2,
458 )
459 assert res is not None
460 assert [(15, 1.0), (16, 2.0)] == res[0][KEY1][1]
461
462 # test groupby
463 res = await decoded_r.ts().mrange(
464 0, 3, filters=["Test=This"], groupby="Test", reduce="sum"
465 )
466 assert res is not None
467 assert [(0, 0.0), (1, 2.0), (2, 4.0), (3, 6.0)] == res[0]["Test=This"][1]
468 res = await decoded_r.ts().mrange(
469 0, 3, filters=["Test=This"], groupby="Test", reduce="max"
470 )
471 assert res is not None
472 assert [(0, 0.0), (1, 1.0), (2, 2.0), (3, 3.0)] == res[0]["Test=This"][1]
473 res = await decoded_r.ts().mrange(
474 0, 3, filters=["Test=This"], groupby="team", reduce="min"
475 )
476 assert res is not None
477 assert 2 == len(res)
478 assert [(0, 0.0), (1, 1.0), (2, 2.0), (3, 3.0)] == res[0]["team=ny"][1]
479 assert [(0, 0.0), (1, 1.0), (2, 2.0), (3, 3.0)] == res[1]["team=sf"][1]
480
481 # test align
482 res = await decoded_r.ts().mrange(
483 0,
484 10,
485 filters=["team=ny"],
486 aggregation_type="count",
487 bucket_size_msec=10,
488 align="-",
489 )

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected