Start a Redis server with a limited number of clients:
$> /usr/local/opt/redis/bin/redis-server --port 6380 --maxclients 5
Then, run the script:
$> ruby redis_connection_pool.rb
The script should fail with the following error during the second iteration:
ERR max number of clients reached (Redis::CommandError)
Run the script again with SHUTDOWN=true
:
$> SHUTDOWN=true ruby redis_connection_pool.rb
This will allow the second iteration to complete successfully, since the connections from the first iteration will have been properly closed.