This repository was archived by the owner on Feb 21, 2023. It is now read-only.
File tree 4 files changed +10
-15
lines changed
4 files changed +10
-15
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,11 @@ def connection(self):
50
50
""":class:`aioredis.RedisConnection` instance."""
51
51
return self ._conn
52
52
53
+ @property
54
+ def in_transaction (self ):
55
+ """Set to True when MULTI command was issued."""
56
+ return self ._conn .in_transaction
57
+
53
58
@property
54
59
def closed (self ):
55
60
"""True if connection is closed."""
Original file line number Diff line number Diff line change @@ -136,7 +136,10 @@ def release(self, conn):
136
136
assert conn in self ._used , "Invalid connection, maybe from other pool"
137
137
self ._used .remove (conn )
138
138
if not conn .closed :
139
- if conn .db == self .db :
139
+ if conn .in_transaction :
140
+ # TODO: log warning
141
+ conn .close ()
142
+ elif conn .db == self .db :
140
143
try :
141
144
self ._pool .put_nowait (conn )
142
145
except asyncio .QueueFull :
Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
import unittest
3
- import socket
4
- import random
5
3
import os
6
4
7
5
from functools import wraps
@@ -34,18 +32,6 @@ def tearDown(self):
34
32
self .loop .close ()
35
33
del self .loop
36
34
37
- def _find_port (self ):
38
- s = socket .socket ()
39
- while True :
40
- port = random .randint (1024 , 65535 )
41
- try :
42
- s .bind (('127.0.0.1' , port ))
43
- except OSError :
44
- pass
45
- else :
46
- s .close ()
47
- return port
48
-
49
35
50
36
class RedisTest (BaseTest ):
51
37
Original file line number Diff line number Diff line change @@ -243,6 +243,7 @@ def test_crappy_multiexec(self):
243
243
yield from redis .set ('abc' , 'def' )
244
244
yield from redis .multi ()
245
245
yield from redis .set ('abc' , 'fgh' )
246
+ self .assertTrue (redis .closed )
246
247
with (yield from pool ) as redis :
247
248
value = yield from redis .get ('abc' )
248
249
self .assertEquals (value , 'def' )
You can’t perform that action at this time.
0 commit comments