tronic / redio Goto Github PK
View Code? Open in Web Editor NEWRedis client for Python Trio
Redis client for Python Trio
Hi Tronic,
First of all thank you for this piece of software in trio land.
Unfortunetaly It will be difficult for me to promote it at my job if the project is lacking of tests :(
and I think I wouldn't be the only one with this problem.
Best regards
Hi there:)
I am interested in using redis with trio and had a look at the code in this repo and really liked what I saw. However as I might use this as work at some point I'd hesitate using code that is not under a permissive license (e.g. BSD, MIT etc.). Any thoughts?
In the pubsub subscriber example with database !=0: with pipelining we send the SELECT after the SUBSCRIBE leading to
redis = redio.Redis("redis://localhost/9")
async for message in redis.pubsub("channel"):
print (message)
redio.exc.ProtocolError: Pipelining error: bytes left unread: bytearray(b'-ERR only (P)SUBSCRIBE / (P)UNSUBSCRIB
E / PING / QUIT allowed in this context\r\n')
Wireshark shows:
*2
$9
SUBSCRIBE
$7
channel
*2
$6
SELECT
$1
9
There are multiple issues with the connection pool:
DB
instance was not deleted, its connection will never be returned to the pool. And there is no guarantee that __del__
method is to be called soon. Since Redis._borrow_connection
does not check for the number of borrowed connections, it is possible for the code to create a lot of connections, that causes an error OSError: all attempts to connect to <redis host> failed
__del__
method during garbage collection, adding the same connection to the pool.For me, it seems that the pool management should be revisited, also I would add an ability to explicitly borrow and return the connection.
I have 2 tasks started by nursery that process communication from different channels, one of them is PubSub reader. The code fetches messages one by one in tight loop:
while True:
# await trio.sleep(0)
if ws.closed:
registry.remove(client_id=client)
break
user = registry.get(client_id=client)
if user:
message = await user.collect_message()
payload = message.message
payload['topic'] = message.topic
try:
await ws.send_message(json.dumps(payload))
except ConnectionClosed:
registry.remove(client_id=client)
break
Fetch code:
async def collect_message(self) -> Message:
topic, message = await self._pubsub
return Message(topic, message)
Once reader task starts executing it blocks the whole execution until 1st message arrives. I was able to overcome this by adding await trio.sleep(0)
at the beginning of loop but I am not sure if it's a bug or I'm doing something stupid here. Tried to implement collect_message
as async generator but the result was the same.
Any hints?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.