redis-py icon indicating copy to clipboard operation
redis-py copied to clipboard

Not able to use hiredis with redis-py for server-assisted client-side caching

Open mahudees opened this issue 1 year ago • 4 comments

Version: redis-py - 5.1.0b7, hiredis - 3.0.0

Platform: Python 3.9 in MacBook Apple M3 Pro

Description: Trying server-assisted client-side caching with redis-py version 5.1.0b7, it worked fine without hredis. Tried with hiredis for additional performance, getting the following error once hiredis is installed and ran the script. Does it require any additional change, from this https://redis.io/docs/latest/develop/connect/clients/python/redis-py/ came to know no additional changes is required for most of the cases.

/Users/mahudees/PycharmProjects/redis-client/.venv/bin/python /Users/mahudees/PycharmProjects/rsacsc-py-master/pythoncsc/csc.py Traceback (most recent call last): File "/Users/mahudees/PycharmProjects/rsacsc-py-master/pythoncsc/csc.py", line 129, in r.set("foo", "bar") File "/Users/mahudees/PycharmProjects/redis-client/.venv/lib/python3.9/site-packages/redis/commands/core.py", line 2334, in set return self.execute_command("SET", *pieces, **options) File "/Users/mahudees/PycharmProjects/redis-client/.venv/lib/python3.9/site-packages/redis/client.py", line 566, in execute_command conn = self.connection or pool.get_connection(command_name, **options) File "/Users/mahudees/PycharmProjects/redis-client/.venv/lib/python3.9/site-packages/redis/connection.py", line 1200, in get_connection connection.connect() File "/Users/mahudees/PycharmProjects/redis-client/.venv/lib/python3.9/site-packages/redis/connection.py", line 315, in connect self.on_connect() File "/Users/mahudees/PycharmProjects/redis-client/.venv/lib/python3.9/site-packages/redis/connection.py", line 439, in on_connect self._parser.set_invalidation_push_handler(self._cache_invalidation_process) AttributeError: '_HiredisParser' object has no attribute 'set_invalidation_push_handler'

Process finished with exit code 1

mahudees avatar Aug 20 '24 15:08 mahudees

#3324 hasn't release yet.

kosuke-zhang avatar Aug 20 '24 16:08 kosuke-zhang

Thanks for the reply, when can we expect it to be released.

mahudees avatar Aug 21 '24 02:08 mahudees

No one knows. For the time being, use hiredis<3.0.

akx avatar Aug 27 '24 09:08 akx

Ok sure, Thank you.

mahudees avatar Sep 01 '24 19:09 mahudees

https://github.com/redis/redis-py/pull/3324 was released but its still failing

hiredis                       3.1.0
redis                         5.2.1

93578237 avatar Dec 19 '24 11:12 93578237

Any update on this?

jnrbsn avatar Apr 19 '25 16:04 jnrbsn

Is there a workaround for this? It still doesn't work.

$ pip list | grep redis
hiredis 3.1.0
redis   5.2.1
>>> import redis
>>> from redis.cache import CacheConfig
>>> r = redis.Redis(host='localhost', port=6379, protocol=3, cache_config=CacheConfig())
>>> r.set(b'foo', b'bar')
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    r.set(b'foo', b'bar')
    ~~~~~^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/redis/commands/core.py", line 2335, in set
    return self.execute_command("SET", *pieces, **options)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/redis/client.py", line 559, in execute_command
    return self._execute_command(*args, **options)
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/redis/client.py", line 565, in _execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
                              ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/redis/connection.py", line 1422, in get_connection
    connection.connect()
    ~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/redis/connection.py", line 773, in connect
    self._conn.connect()
    ~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/redis/connection.py", line 385, in connect
    callback(self)
    ~~~~~~~~^^^^^^
  File "/usr/local/lib/python3.13/site-packages/redis/connection.py", line 922, in _enable_tracking_callback
    conn._parser.set_invalidation_push_handler(self._on_invalidation_callback)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: '_HiredisParser' object has no attribute 'set_invalidation_push_handler'

jnrbsn avatar Apr 25 '25 16:04 jnrbsn

keep watching

zengruizhao avatar May 22 '25 08:05 zengruizhao

Hello everyone!

This was fixed, and you can test it by using hiredis>=3.2.0 and redis-py from the master branch.

Let me know if you have any feedback or questions!

uglide avatar May 23 '25 10:05 uglide

Fix is now available as part of https://github.com/redis/redis-py/releases/tag/v.6.2.0 release

uglide avatar May 28 '25 07:05 uglide

@uglide As an aside, why was the release tag format changed from v6.1.0 to v.6.2.0 (extra dot)? I foresee that breaking systems...

akx avatar May 28 '25 10:05 akx

@uglide As an aside, why was the release tag format changed from v6.1.0 to v.6.2.0 (extra dot)? I foresee that breaking systems...

By mistake :( I'll check how this can be fixed...

petyaslavova avatar May 28 '25 12:05 petyaslavova

@akx In which case it makes sense to pull a package from GitHub rather then using a package manager? This is the whole purpose of pip to provide a layer of abstraction from GitHub, so things can be decoupled. So changing naming schema is an issue, but I don't see how this should impact a lot of systems.

vladvildanov avatar May 28 '25 13:05 vladvildanov

@akx In which case it makes sense to pull a package from GitHub rather then using a package manager?

Not necessarily the wheel itself, but, say, change logs for a given version, now that they are only tracked in Github releases.

akx avatar May 28 '25 13:05 akx

@akx For those systems I agree, but not for production usage

vladvildanov avatar May 28 '25 13:05 vladvildanov