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

No expire value raises error #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

No expire value raises error #1

wants to merge 2 commits into from

Conversation

aspedrosa
Copy link

If no value is provided to the expire argument of the RWLock class, the acquire method raises an error.
This happens because the command EXPIRE doesn't accept the None value as argument.

On this PR I also replaced the str.format expressions by f-strings. I you don't agree with this last change I can revert it

>>> import redis
>>> redis_conn = redis.Redis()
>>> from redis_rw_lock import RWLock
>>> read_lock = RWLock(redis_conn, "some_name", RWLock.READ)
>>> read_lock.acquire()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aspedrosa/.trash/test/venv/lib/python3.8/site-packages/redis_rw_lock/__init__.py", line 47, in acquire
    return self.__reader_acquire()
  File "/home/aspedrosa/.trash/test/venv/lib/python3.8/site-packages/redis_rw_lock/__init__.py", line 30, in __reader_acquire
    self.__read_switch.acquire(self.__no_writers)
  File "/home/aspedrosa/.trash/test/venv/lib/python3.8/site-packages/redis_rw_lock/__init__.py", line 81, in acquire
    self.__redis_conn.expire(self.__counter_name, self.__expire)
  File "/home/aspedrosa/.trash/test/venv/lib/python3.8/site-packages/redis/client.py", line 1591, in expire
    return self.execute_command('EXPIRE', name, time)
  File "/home/aspedrosa/.trash/test/venv/lib/python3.8/site-packages/redis/client.py", line 900, in execute_command
    conn.send_command(*args)
  File "/home/aspedrosa/.trash/test/venv/lib/python3.8/site-packages/redis/connection.py", line 725, in send_command
    self.send_packed_command(self.pack_command(*args),
  File "/home/aspedrosa/.trash/test/venv/lib/python3.8/site-packages/redis/connection.py", line 775, in pack_command
    for arg in imap(self.encoder.encode, args):
  File "/home/aspedrosa/.trash/test/venv/lib/python3.8/site-packages/redis/connection.py", line 119, in encode
    raise DataError("Invalid input of type: '%s'. Convert to a "
redis.exceptions.DataError: Invalid input of type: 'NoneType'. Convert to a bytes, string, int or float first.

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.

None yet

1 participant