Pārlūkot izejas kodu

Rename function

`db.set_conn_id` is more meaningful.
Cesar Rodas 2 gadi atpakaļ
vecāks
revīzija
57032e6e4f
3 mainītis faili ar 7 papildinājumiem un 9 dzēšanām
  1. 1 1
      src/connection/connections.rs
  2. 1 1
      src/connection/mod.rs
  3. 5 7
      src/db/mod.rs

+ 1 - 1
src/connection/connections.rs

@@ -66,7 +66,7 @@ impl Connections {
             id: *id,
             addr: addr.to_string(),
             all_connections: self.clone(),
-            info: RwLock::new(ConnectionInfo::new(db.new_db_instance(*id))),
+            info: RwLock::new(ConnectionInfo::new(db.set_conn_id(*id))),
             pubsub_client: PubsubClient::new(pubsub_sender),
         });
 

+ 1 - 1
src/connection/mod.rs

@@ -371,7 +371,7 @@ impl Connection {
             .all_connections
             .get_databases()
             .get(db)?
-            .new_db_instance(self.id);
+            .set_conn_id(self.id);
         info.current_db = db;
         Ok(Value::Ok)
     }

+ 5 - 7
src/db/mod.rs

@@ -185,12 +185,10 @@ impl Db {
         }
     }
 
-    /// Creates a new Database instance bound to a connection.
+    /// Attaches a conn_id to a database instance.
     ///
-    /// This is particular useful when locking keys exclusively.
-    ///
-    /// All the internal data are shjared through an Arc.
-    pub fn new_db_instance(self: Arc<Db>, conn_id: u128) -> Arc<Db> {
+    /// This conn_id is used to lock entries for a given conn_id.
+    pub fn set_conn_id(self: Arc<Db>, conn_id: u128) -> Arc<Db> {
         Arc::new(Self {
             slots: self.slots.clone(),
             tx_key_locks: self.tx_key_locks.clone(),
@@ -1387,8 +1385,8 @@ mod test {
     #[tokio::test]
     async fn lock_keys() {
         let db1 = Arc::new(Db::new(100));
-        let db2 = db1.clone().new_db_instance(2);
-        let db3 = db1.clone().new_db_instance(3);
+        let db2 = db1.clone().set_conn_id(2);
+        let db3 = db1.clone().set_conn_id(3);
         let shared = Arc::new(RwLock::new(1));
         let shared1 = shared.clone();
         let shared2 = shared.clone();