mlasevich / PyRSMQ

Python Implementation of Redis Simple Message Queue Algorithm
Apache License 2.0
43 stars 10 forks source link

incomplete delete when using message_id: bytes #17

Open ChuckHend opened 2 years ago

ChuckHend commented 2 years ago

Passing the message_id in as bytes to .deleteMessage will delete the message from the ZSET but not the HASH when using python3.x.

https://github.com/mlasevich/PyRSMQ/blob/8e8221e762c3ca290975d33a3933c41fb955c01a/src/rsmq/cmd/delete_message.py#L38-L40

tx.zrem seems to function just fine passing in bytes. Problem seems to come from the string formatting on the tx.hdel. The key to delete gets formatted to include the b prefix, "b'g6r6o3gmvlyHWbPC457M4Cvru9J4nd9C':fr", for example. Key w/ the "b" does not exist so it's not. tx.del returns 1, instead of the expected 3.

I'd like to see either an exception raised and/or an error logged in this scenario. I'd be happy to open a PR with a proposal if you're open to it @mlasevich.

to reproduce...

from rsmq import RedisSMQ

queue = RedisSMQ(host="redis", qname="myqueue", options={"decode_responses": False})
queue.createQueue(delay=0).vt(20).execute()
message_id = queue.sendMessage().message("Hello World").execute()
msg = queue.receiveMessage().exceptions(False).execute()

msg_id_bytes: bytes = msg['id'] # bytes because "decode_responses": False
resp = queue.deleteMessage(id=msg_id_bytes).execute()
assert resp is True

client = queue.client

# successfull delete from the zset
zset = client.hgetall("rsmq:myqueue")
assert zset == {}

# keys still in hash
client.hgetall("rsmq:myqueue:Q")
mlasevich commented 12 months ago

I am always open to PRs (though I clearly missed this message) :-)