Crates.io | redis_dumbpool |
lib.rs | redis_dumbpool |
version | 0.2.0 |
source | src |
created_at | 2021-02-18 14:04:12.58281 |
updated_at | 2021-02-19 15:28:10.668732 |
description | Really dumb implementation of a Redis Connection Pool |
homepage | |
repository | https://github.com/nappa85/redis_dumbpool |
max_upload_size | |
id | 357073 |
size | 9,158 |
Really dumb implementation of a Redis Connection Pool
My tests with other polling crates ended up with a new TIME_WAIT socket for every Redis query, like if the socket is discared and recreated every time. Trying to demonstrate the problem, I endend up with this implementation, that is kind-of usable.
There is a main object (Pool), storing a Vec of Redis connections. The Pool can be inited with a number of active connections. Every time a connection is requested from the pool, it's popped from the Vec and tested before being returned. If a connection isn't available and the maximum number of connections has been already reached, an async sleep is performed before retrying. On return, the connection is wrapped in a struct that only purpose is to return the connection to the pool on drop.