# Fix "DeprecationWarning: Redis.hmset() is deprecated. Use Redis.hset() instead" in a Python Service

Yes. An agent finds each hmset call, reproduces the redis-py warning, rewrites it as hset with a mapping, updates the tests that assert on it and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/fix-redis-hmset-is-deprecated-warning/redis-py/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads where the Redis client is used. In a Python server like SpamExperts/pyzor, the collaborative spam-digest service at 1.1.2, `requirements.txt` pins `redis==4.0.2` under a comment that it is needed only for the redis engine, and `docs/server.rst` tells operators to set `Engine = redis` in the configuration. The engine lives in `pyzor/engines/redis_.py`: `_get_new_connection` builds a `redis.StrictRedis` from the host, port, database and password, `__getitem__` reads a digest's record with `hgetall`, and `__setitem__` at line 137 writes it with `self.db.hmset(real_key, self._encode_record(value))` before setting an `expire` when `max_age` is configured; the report and whitelist paths a few lines below already use `hsetnx` and `hset`. `tests/unit/test_engines/test_redis.py` patches `redis.StrictRedis` with a mock and, in `test_set` and `test_set_max_age` at lines 184 and 195, asserts `hmset.assert_called_with(...)`, so the suite pins the deprecated call.

Then it reproduces the warning against the real client rather than the mock, because a mocked `StrictRedis` never raises it. With the pinned 4.0.2 on Python 3.11 and `-W default`, calling `hmset` on a client pointed at a closed port prints `DeprecationWarning: Redis.hmset() is deprecated. Use Redis.hset() instead.` before the `ConnectionError`; 4.5.4 prints the same text, and the current 8.1.0 prints `Call to deprecated hmset. (Use 'hset' instead.) -- Deprecated since version 4.0.0.` Under `-W error::DeprecationWarning` the call raises before any network traffic. The run also shows that 4.0.2 does not import on Python 3.12 at all, since its `connection.py` starts with `from distutils.version import LooseVersion`, which the agent records as a finding about the pin rather than fixing here. On the current release the 161 unit tests pass.

The fix is the call redis-py has recommended since 3.5: `self.db.hset(real_key, mapping=self._encode_record(value))`, one line, and the two assertions in `test_redis.py` become `hset.assert_called_with(key, mapping=record)`. With those three lines changed, the 161 unit tests pass under `-W error::DeprecationWarning` on the current client, and the real-client check now raises only the `ConnectionError` with no warning ahead of it.

It writes down what it did not change: `hsetnx` and the single-field `hset` calls in the same file are already the current API; the `redis==4.0.2` pin and its Python 3.12 import failure are a separate upgrade with its own test run; and the MySQL and gdbm engines in the same package do not use Redis. Each goes in the pull request as a finding with its line.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "The service prints `DeprecationWarning: Redis.hmset() is deprecated. Use Redis.hset() instead`. List every hmset call in the repository with its file and line, and every test that asserts on hmset. Reproduce the warning against the real redis client under python -W default, pointed at a closed port so no server is needed, and quote it. Rewrite each call as hset with the mapping keyword, keeping the key and the record unchanged, and update the test assertions to match. Run the unit tests under -W error::DeprecationWarning before and after and quote the counts. Report any other problem with the pinned redis version you notice, such as an import failure on a newer Python, without fixing it. Open a pull request that quotes the reproduction and both test runs.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request touching `pyzor/engines/redis_.py` and `tests/unit/test_engines/test_redis.py`: the `hmset` call rewritten as `hset(real_key, mapping=...)` and the two mock assertions updated to expect it. The description lists the one call site and two assertions, quotes the deprecation text from the pinned client and from the current one, and shows the unit tests passing under `-W error::DeprecationWarning` with the same count before and after.

A reviewer checks that the key and the encoded record passed to `hset` are the same objects `hmset` received, that `expire` still follows the write when `max_age` is set, and that the findings list keeps the `redis==4.0.2` pin and its Python 3.12 import failure as a separate change. The run's record holds the reproduction and both test runs, so the warning and its disappearance can be opened rather than taken on trust.

## Run it on every Linear issue labelled tech-debt

Add an automation to the repository's Project with a `linear` trigger on issues labelled `tech-debt` and this prompt. When someone files the issue for this warning and labels it, the run starts with the issue placed after the prompt, rewrites every `hmset` it finds and opens a pull request that links the issue; an issue about a different deprecation ends with a report and no change.

The same body works from your own server with `POST /o/{org}/sessions` and an API key, with a `request_id` that is a UUID v5 of the issue id so a retried call returns the run it already started; the key's `webhook_url` then receives `run.completed` with the pull request.

## Why run it on Rush?

A client deprecation that the tests mock away never shows up in CI, and the first place it appears is a production log. The agent reproduces it against the real client in its own sandbox, with no Redis server needed, and keeps the output in the run's record, so the pull request shows the warning text from the pinned release rather than quoting documentation.

The rewrite is one line, but the tests that assert on the old call are the part a quick patch forgets, and they fail only after the change. Because the agent runs the suite under `-W error::DeprecationWarning` on both sides, the pull request carries the updated assertions and the same passing count.

## Frequently asked questions

### Why was hmset deprecated?

Redis 4.0 made `HSET` accept several field-value pairs, which left `HMSET` with nothing it could do that `HSET` could not. redis-py followed in 3.5 by adding the `mapping` keyword to `hset` and marking `hmset` deprecated; the server command still works, so the warning is the only effect today.

### Does hset with mapping behave the same?

Yes for a write: both send the key with every field and value in one command. `hset` returns the number of fields that were newly added, where `hmset` returned a boolean, so the agent checks whether any caller reads the return value; in this engine `__setitem__` discards it.

### Why not just upgrade redis-py?

The warning is present on every release from 3.5 to the current 8, and the current one prints it in a different wording, so an upgrade alone changes the text, not the call. The pinned 4.0.2 also fails to import on Python 3.12, which the agent reports so the upgrade can be its own reviewed change.

### How does it reproduce the warning without a Redis server?

redis-py emits the deprecation when the method is called, before it connects. Pointing a client at a closed port and calling `hmset` prints the warning and then a `ConnectionError`, which is enough to quote the exact text the pinned release prints.

## More jobs like this: Turn a Linear label into a PR

- [Fix "Return type should either be compatible with ArrayAccess::offsetGet" Deprecations on PHP 8.1](https://getrush.ai/run/fix-return-type-will-change-deprecation/php/)
- [Fix "Argument is deprecated: Use the aws_s3_bucket_versioning resource instead" in Terraform](https://getrush.ai/run/fix-s3-bucket-argument-is-deprecated/terraform/)
- [Fix "OSError: 'seaborn' is not a valid package style" in Matplotlib](https://getrush.ai/run/fix-seaborn-is-not-a-valid-package-style/matplotlib/)
- [Fix "ImportError: cannot import name 'joblib' from 'sklearn.externals'"](https://getrush.ai/run/fix-sklearn-externals-joblib-import-error/joblib/)
- [Fix You Must Pass the Application as an Import String to Enable Reload in Uvicorn](https://getrush.ai/run/fix-you-must-pass-the-application-as-an-import-string/uvicorn/)
- [Turn Labeled GitHub Issues Into Pull Requests for an Ansible Role](https://getrush.ai/run/github-issue-to-pr/ansible/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
