Skip to content

Conversation

@sttk
Copy link
Owner

@sttk sttk commented Aug 20, 2025

This PR modifies RedisDataConn#get_connection to retrieve a connection from r2d2::Pool<RedlisClient>, not to get a same connection instance that was created along with the RedisDataConn.

In the previous implementation, while the borrow of the conn: redis::Connection instance obtained from RedisDataConn#get_connection was active, you couldn't call the RedisDataConn#add_force_back method. To perform multiple operations and register force-back functions alternately, you had to enclose the conn acquisition and operations in a block. After the block ended and the conn was dropped, you could then execute add_force_back, and then repeat the process of acquiring the conn and performing operations inside another block.
In the new implementation, it's possible to execute operations on the conn and add_force_back alternately.

Also, in the previous implementation, it was impossible to handle a connection that was severed while being passed around. With the new implementation, however, the pool automatically reconnects, allowing you to get an active connection by calling RedisDataConn::get_connection.
However, if all connections are in use, there will be an overhead of waiting until a connection is released.

@sttk sttk requested a review from Copilot August 20, 2025 16:10

This comment was marked as outdated.

@sttk sttk requested a review from Copilot August 20, 2025 16:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the RedisDataConn struct to use a connection pool instead of holding a single pooled connection, improving concurrent access and connection management.

  • Replaces direct connection storage with r2d2::Pool<redis::Client> reference
  • Modifies get_connection to return a pooled connection on-demand rather than a mutable reference
  • Updates force_back method to acquire fresh connections from the pool for rollback operations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@sttk sttk merged commit 6a38e8b into main Aug 20, 2025
3 checks passed
@sttk sttk deleted the modify_RedisDataConn#get_connection_to_get_conn_from_pool branch August 20, 2025 16:27
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.

2 participants