Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: adds PTTL command #1036

Merged
merged 2 commits into from
Mar 6, 2024
Merged

Conversation

shohamazon
Copy link
Collaborator

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@shohamazon shohamazon requested a review from a team as a code owner February 25, 2024 17:46
@@ -926,14 +926,15 @@ async def test_unlink(self, redis_client: TRedisClient):

@pytest.mark.parametrize("cluster_mode", [True, False])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
async def test_expire_pexpire_ttl_with_positive_timeout(
async def test_expire_pexpire_ttl_pttl_with_positive_timeout(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please tell me if you prefer:

@pytest.mark.parametrize("cluster_mode", [True, False])
    @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
    async def test_pttl(self, redis_client: TRedisClient):
        key = get_random_string(10)
        assert await redis_client.pttl(key) == -2
        current_time = int(time.time())

        assert await redis_client.set(key, "value") == OK
        assert await redis_client.pttl(key) == -1

        assert await redis_client.expire(key, 10) == True
        assert 0 < await redis_client.pttl(key) <= 10000

        assert await redis_client.expireat(key, current_time + 20) == True
        assert 0 < await redis_client.pttl(key) <= 20000

        assert await redis_client.pexpireat(key, current_time * 1000 + 30000) == True
        assert 0 < await redis_client.pttl(key) <= 30000

        # set command clears the timeout.
        assert await redis_client.set(key, "value") == OK
        assert await redis_client.pttl(key) == -1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, separating the command to a different test will help debugging if needed later on. The last check though seems duplicated (set and then asserting again that its PTTL is -1)

@@ -1005,7 +1005,7 @@ async def expire(

Examples:
>>> await client.expire("my_key", 60)
1 # Indicates that a timeout of 60 seconds has been set for "my_key."
True # Indicates that a timeout of 60 seconds has been set for "my_key."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be move doc fixes to another PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for next time, for now just make sure to have these changes in a separate commit

else:
assert (
await redis_client.expireat(
key, current_time + 50, ExpireOptions.NewExpiryGreaterThanCurrent
)
== 1
== True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do assert await ... without == True

Copy link
Collaborator

@barshaul barshaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please separate the tests

@shohamazon shohamazon merged commit 3ed858f into valkey-io:main Mar 6, 2024
42 of 44 checks passed
@shohamazon shohamazon deleted the python/pttl branch March 6, 2024 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants