Skip to content

Make hset support multiple field/value pairs.#1271

Merged
andymccurdy merged 6 commits intoredis:masterfrom
laixintao:bugfix/hset-multi-pairs
Feb 7, 2020
Merged

Make hset support multiple field/value pairs.#1271
andymccurdy merged 6 commits intoredis:masterfrom
laixintao:bugfix/hset-multi-pairs

Conversation

@laixintao
Copy link
Copy Markdown
Contributor

@laixintao laixintao commented Jan 29, 2020

Pull Request check-list

Please make sure to review and check all of these items:

  • Does $ tox pass with this change (including linting)?
  • Does travis tests pass with this change (enable it first in your forked repo and wait for the travis build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

Description of change

  1. hset accept multiple field/value s now.
  2. hmset marked as deprecated.

close #1269

@laixintao laixintao requested a review from andymccurdy January 29, 2020 11:52
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jan 29, 2020

Codecov Report

Merging #1271 into master will decrease coverage by 1.26%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1271      +/-   ##
==========================================
- Coverage   92.39%   91.13%   -1.27%     
==========================================
  Files          19       19              
  Lines        6394     6249     -145     
==========================================
- Hits         5908     5695     -213     
- Misses        486      554      +68
Impacted Files Coverage Δ
tests/test_commands.py 99.94% <100%> (-0.01%) ⬇️
redis/client.py 85.73% <100%> (-0.01%) ⬇️
redis/_compat.py 32.25% <0%> (-53.35%) ⬇️
redis/utils.py 66.66% <0%> (-2.09%) ⬇️
tests/test_multiprocessing.py 77.89% <0%> (-0.9%) ⬇️
tests/test_encoding.py 95.83% <0%> (-0.17%) ⬇️
redis/connection.py 80.55% <0%> (-0.16%) ⬇️
tests/test_connection_pool.py 97.77% <0%> (-0.07%) ⬇️
tests/test_pubsub.py 99.14% <0%> (-0.02%) ⬇️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b7f562...fb38caf. Read the comment docs.

@andymccurdy
Copy link
Copy Markdown
Contributor

Thanks for making this PR. I'd prefer to not use keyword args here -- this was a big mistake with ZADD from the 2.x days and 3.x ended up breaking a bunch of user code. Instead, lets make it look like:

def hset(self, name, key=None, value=None, mapping=None)

Also we should adjust the comment so that it mentions that the return value is the number of fields added to the hash (as the redis docs suggest).

@laixintao laixintao force-pushed the bugfix/hset-multi-pairs branch from 8a76f68 to 77408cb Compare January 31, 2020 09:10
@laixintao
Copy link
Copy Markdown
Contributor Author

@andymccurdy Hi thanks for review, updated. PTAL again :)

@laixintao
Copy link
Copy Markdown
Contributor Author

ping @andymccurdy

@laixintao laixintao force-pushed the bugfix/hset-multi-pairs branch from cda787a to ddbc77a Compare February 5, 2020 00:53
laixintao and others added 2 commits February 7, 2020 11:20
Co-Authored-By: Alan Mai <0110amai@gmail.com>
@andymccurdy
Copy link
Copy Markdown
Contributor

Thanks, looks great!

@elcolumbio
Copy link
Copy Markdown

I like this commit and it is such an important interface.
I have a learning question.
When would we consider to break backwards compatibility in favor of this:
hset(self, name, mapping)

@andymccurdy
Copy link
Copy Markdown
Contributor

We could consider a backwards incompatible change when we increment a major version number. For example, 3.x -> 4.x.

Set ``key`` to ``value`` within hash ``name``
Returns 1 if HSET created a new field, otherwise 0
Set ``key`` to ``value`` within hash ``name``,
Use ``mappings`` keyword args to set multiple key/value pairs
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Small typo here: s/mappings/mapping

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +17 to +18
* HSET command now can accept multiple pairs. HMSET has been marked as
deprecated now. Thanks to @laixintao #1271
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@laixintao this unfortunately doesn't mention that it requires at least Redis 4.0.0. We got bitten by this when updating redis-py (from 3.4.1 to 3.5.2) in a system that runs Redis 3.2.4.

@andymccurdy I couldn't find any information about which version(s) of Redis is supported by redis-py. Did I miss something?

Copy link
Copy Markdown
Contributor

@andymccurdy andymccurdy May 20, 2020

Choose a reason for hiding this comment

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

@ala-ableton This is completely backwards compatible with older versions of Redis server. You can still use the key and value that were present in all previous versions of redis-py. We could add a comment to the function that mapping requires Redis server 4.0 or greater.

redis-py works with all known versions of Redis server. Obviously you need a version of Redis server that supports the commands and command options you're working with.

Copy link
Copy Markdown

@ala-ableton ala-ableton May 22, 2020

Choose a reason for hiding this comment

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

@andymccurdy sorry, I misread the diff. It seems that our issue didn't come from redis-py, but from https://github.com/rq/rq (more specifically, rq/rq@5859339). Thanks for the quick reply!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hmset() uses deprecated command HMSET

7 participants