database-wrapper-redis 0.2.36__tar.gz → 0.2.38__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: database_wrapper_redis
3
- Version: 0.2.36
3
+ Version: 0.2.38
4
4
  Summary: database_wrapper for Redis database
5
5
  Author-email: Gints Murans <gm@gm.lv>
6
6
  License: GNU General Public License v3.0 (GPL-3.0)
@@ -32,7 +32,7 @@ Classifier: Topic :: Software Development
32
32
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
33
33
  Requires-Python: >=3.8
34
34
  Description-Content-Type: text/markdown
35
- Requires-Dist: database_wrapper==0.2.36
35
+ Requires-Dist: database_wrapper==0.2.38
36
36
  Requires-Dist: redis>=8.0
37
37
 
38
38
  # database_wrapper_redis
@@ -147,36 +147,42 @@ class KVDbBase:
147
147
  def __enter__(self) -> RedisClient:
148
148
  self.logger.debug("Creating redis connection")
149
149
 
150
+ # Connections are kept in a per-context stack so that nested
151
+ # context managers each get and close their own connection
150
152
  connection = self.new_connection()
151
- self.context_connection.set(connection)
153
+ stack = self.context_connection.get() or ()
154
+ self.context_connection.set(stack + (connection,))
152
155
  return connection
153
156
 
154
157
  def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
155
158
  self.logger.debug("Releasing redis connection")
156
159
 
157
- redis_conn = self.context_connection.get()
158
- if redis_conn:
159
- redis_conn.close()
160
-
161
- # Reset context
162
- self.context_connection.set(None)
160
+ stack = self.context_connection.get() or ()
161
+ if stack:
162
+ redis_conn = stack[-1]
163
+ self.context_connection.set(stack[:-1])
164
+ if redis_conn:
165
+ redis_conn.close()
163
166
 
164
167
  async def __aenter__(self) -> RedisClientAsync:
165
168
  self.logger.debug("Creating redis connection")
166
169
 
170
+ # Connections are kept in a per-context stack so that nested
171
+ # context managers each get and close their own connection
167
172
  connection = await self.new_connection()
168
- self.context_connection.set(connection)
173
+ stack = self.context_connection.get() or ()
174
+ self.context_connection.set(stack + (connection,))
169
175
  return connection
170
176
 
171
177
  async def __aexit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
172
178
  self.logger.debug("Releasing redis connection")
173
179
 
174
- redis_conn = self.context_connection.get()
175
- if redis_conn:
176
- await redis_conn.aclose()
177
-
178
- # Reset context
179
- self.context_connection.set(None)
180
+ stack = self.context_connection.get() or ()
181
+ if stack:
182
+ redis_conn = stack[-1]
183
+ self.context_connection.set(stack[:-1])
184
+ if redis_conn:
185
+ await redis_conn.aclose()
180
186
 
181
187
  ###############
182
188
  ### Helpers ###
@@ -217,7 +223,7 @@ class KVDbBase:
217
223
 
218
224
 
219
225
  class RedisDb(KVDbBase):
220
- context_connection: ContextVar[RedisClient | None]
226
+ context_connection: ContextVar[tuple[RedisClient, ...] | None]
221
227
 
222
228
  _connection: RedisClient
223
229
 
@@ -288,7 +294,7 @@ class RedisDb(KVDbBase):
288
294
 
289
295
 
290
296
  class RedisDbAsync(KVDbBase):
291
- context_connection: ContextVar[RedisClientAsync | None]
297
+ context_connection: ContextVar[tuple[RedisClientAsync, ...] | None]
292
298
 
293
299
  _connection: RedisClientAsync | None
294
300
 
@@ -375,7 +381,7 @@ class RedisDbAsync(KVDbBase):
375
381
 
376
382
  class RedisDbWithPool(KVDbBase):
377
383
  pool: RedisConnectionPool
378
- context_connection: ContextVar[RedisClient | None]
384
+ context_connection: ContextVar[tuple[RedisClient, ...] | None]
379
385
 
380
386
  _connection: RedisClient | None
381
387
 
@@ -446,7 +452,7 @@ class RedisDbWithPool(KVDbBase):
446
452
 
447
453
  class RedisDbWithPoolAsync(KVDbBase):
448
454
  pool: RedisConnectionPoolAsync
449
- context_connection: ContextVar[RedisClientAsync | None]
455
+ context_connection: ContextVar[tuple[RedisClientAsync, ...] | None]
450
456
 
451
457
  _connection: RedisClientAsync | None
452
458
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: database_wrapper_redis
3
- Version: 0.2.36
3
+ Version: 0.2.38
4
4
  Summary: database_wrapper for Redis database
5
5
  Author-email: Gints Murans <gm@gm.lv>
6
6
  License: GNU General Public License v3.0 (GPL-3.0)
@@ -32,7 +32,7 @@ Classifier: Topic :: Software Development
32
32
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
33
33
  Requires-Python: >=3.8
34
34
  Description-Content-Type: text/markdown
35
- Requires-Dist: database_wrapper==0.2.36
35
+ Requires-Dist: database_wrapper==0.2.38
36
36
  Requires-Dist: redis>=8.0
37
37
 
38
38
  # database_wrapper_redis
@@ -0,0 +1,2 @@
1
+ database_wrapper==0.2.38
2
+ redis>=8.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "database_wrapper_redis"
7
- version = "0.2.36"
7
+ version = "0.2.38"
8
8
  description = "database_wrapper for Redis database"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -32,7 +32,7 @@ classifiers = [
32
32
  "Topic :: Software Development :: Libraries :: Python Modules",
33
33
  ]
34
34
  keywords = ["database", "wrapper", "python", "redis"]
35
- dependencies = ["database_wrapper == 0.2.36", "redis >= 8.0"]
35
+ dependencies = ["database_wrapper == 0.2.38", "redis >= 8.0"]
36
36
 
37
37
  [project.urls]
38
38
  Homepage = "https://github.com/gintsmurans/py_database_wrapper"
@@ -1,2 +0,0 @@
1
- database_wrapper==0.2.36
2
- redis>=8.0