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

Define prefix strategy for ZMSCORE command #1443

Closed
wants to merge 7 commits into from

Conversation

mohorev
Copy link

@mohorev mohorev commented Mar 19, 2024

Description:

When using Predis, if a client prefix is set and then a ZMSCORE command is executed, the client prefix is ignored. This leads to incorrect results, as the command operates on keys without the applied prefix.

Steps to Reproduce:

  • Set a prefix for the Predis client.
  • Use the ZMSCORE command to retrieve the score from a sorted set.

Expected Behavior:

The ZMSCORE command should consider the client prefix when retrieving the score from the sorted set, ensuring that the correct key is used.

Actual Behavior:

The ZMSCORE command retrieves the score from the sorted set without considering the client prefix. As a result, incorrect keys are accessed, leading to unexpected behavior.

Additional Information:

Predis Version: v2.2.2

Similar issue with prefix problems in ZPOPMIN & ZPOPMAX commands #1432 already reported.

Sample Code:

<?php

require __DIR__ . '/vendor/autoload.php';

// Set up Predis client with a prefix
$redis = new Predis\Client('tcp://localhost:6383', ['prefix' => 'test_']);

// Add values to a sorted set
$redis->zadd('mykey', ['foo' => 10, 'bar' => 20]);

// ZRANGE works correct, return: ['foo' => '10', 'bar' => '20']
var_dump($redis->zrange('mykey', 0, -1, ['WITHSCORES' => true]));

// ZMSCORE ignores the prefix. Outputs incorrect scores: [null, null]
var_dump($redis->zmscore('mykey', 'foo', 'bar'));

@mohorev mohorev requested a review from tillkruss as a code owner March 19, 2024 21:47
@coveralls
Copy link

coveralls commented Mar 19, 2024

Coverage Status

coverage: 80.258% (+0.01%) from 80.247%
when pulling 74ddd24 on mohorev:zmscore-prefix
into 45b18eb on predis:v2.x.

vladvildanov
vladvildanov previously approved these changes Mar 20, 2024
@mohorev
Copy link
Author

mohorev commented Mar 20, 2024

@vladvildanov @tillkruss Hey team, can we release with these changes? This code is my salvation in production. I'd be praying for you in church if you help speed up this release 😺

@mohorev
Copy link
Author

mohorev commented Mar 20, 2024

To kill two birds with one stone, I decided to go further, and within the scope of this pull request, I also fixed the prefix issue with the ZPOPMAX and ZPOPMIN commands, which was mentioned in a neighboring pull request. However, unlike that solution, I added unit tests here that verify the functionality of the prefixes.

Copy link
Member

@tillkruss tillkruss left a comment

Choose a reason for hiding this comment

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

Please undo all the styling changes.

@mohorev
Copy link
Author

mohorev commented Mar 20, 2024

@tillkruss Done. As per your request, I've reverted the commit regarding the styling formatting.

@mohorev mohorev requested a review from tillkruss March 20, 2024 19:14
@vladvildanov
Copy link
Contributor

@mohorev Thanks for your input! I added a PR to fix codestyle issues and bind a version of php-cs-fixer package. After it will be merged please rebase your branch and we will release both of this changes

#1445

@mohorev
Copy link
Author

mohorev commented Apr 10, 2024

Hi, @vladvildanov @tillkruss

Just wanted to check in to see if there are any updates or progress on this enhancement?

@tillkruss
Copy link
Member

I've merged this in #1451 without the test changes.

@mohorev
Copy link
Author

mohorev commented Apr 11, 2024

 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants