redis-allocator 0.3.1__py3-none-any.whl → 0.3.3__py3-none-any.whl
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.
- redis_allocator/_version.py +1 -1
- redis_allocator/allocator.py +10 -4
- {redis_allocator-0.3.1.dist-info → redis_allocator-0.3.3.dist-info}/METADATA +1 -1
- {redis_allocator-0.3.1.dist-info → redis_allocator-0.3.3.dist-info}/RECORD +8 -8
- tests/conftest.py +2 -11
- {redis_allocator-0.3.1.dist-info → redis_allocator-0.3.3.dist-info}/WHEEL +0 -0
- {redis_allocator-0.3.1.dist-info → redis_allocator-0.3.3.dist-info}/licenses/LICENSE +0 -0
- {redis_allocator-0.3.1.dist-info → redis_allocator-0.3.3.dist-info}/top_level.txt +0 -0
redis_allocator/_version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = '0.3.
|
1
|
+
__version__ = '0.3.3'
|
redis_allocator/allocator.py
CHANGED
@@ -97,7 +97,7 @@ class RedisAllocatableClass(ABC):
|
|
97
97
|
|
98
98
|
def open(self):
|
99
99
|
"""Open the object."""
|
100
|
-
|
100
|
+
return self
|
101
101
|
|
102
102
|
def close(self):
|
103
103
|
"""close the object."""
|
@@ -162,6 +162,7 @@ class RedisAllocatorObject(Generic[U]):
|
|
162
162
|
"""Open the object."""
|
163
163
|
if self.obj is not None:
|
164
164
|
self.obj.open()
|
165
|
+
return self
|
165
166
|
|
166
167
|
def close(self):
|
167
168
|
"""Kill the object."""
|
@@ -282,9 +283,11 @@ class RedisAllocatorPolicy(ABC):
|
|
282
283
|
|
283
284
|
def check_health_once(self, r_obj: RedisAllocatorObject, duration: int = 3600) -> bool:
|
284
285
|
"""Check the health of the object."""
|
285
|
-
with contextlib.closing(r_obj):
|
286
|
+
with contextlib.closing(r_obj.open()):
|
286
287
|
try:
|
287
288
|
if r_obj.is_healthy():
|
289
|
+
if r_obj.allocator.shared:
|
290
|
+
r_obj.allocator.unlock(r_obj.key) # set the key as free
|
288
291
|
return True
|
289
292
|
else:
|
290
293
|
r_obj.set_unhealthy(duration)
|
@@ -550,6 +553,9 @@ class RedisAllocator(RedisLockPool, Generic[U]):
|
|
550
553
|
"""
|
551
554
|
return f'''
|
552
555
|
{super()._lua_required_string}
|
556
|
+
local function time()
|
557
|
+
return tonumber(redis.call("TIME")[1])
|
558
|
+
end
|
553
559
|
local function pool_pointer_str(head)
|
554
560
|
local pointer_type = 'head'
|
555
561
|
if not head then
|
@@ -584,10 +590,10 @@ class RedisAllocator(RedisLockPool, Generic[U]):
|
|
584
590
|
if timeout == nil or timeout <= 0 then
|
585
591
|
return -1
|
586
592
|
end
|
587
|
-
return
|
593
|
+
return time() + timeout
|
588
594
|
end
|
589
595
|
local function is_expiry_invalid(expiry)
|
590
|
-
return expiry ~= nil and expiry > 0 and expiry <=
|
596
|
+
return expiry ~= nil and expiry > 0 and expiry <= time()
|
591
597
|
end
|
592
598
|
local function is_expired(value)
|
593
599
|
local _, _, expiry = split_pool_value(value)
|
@@ -1,15 +1,15 @@
|
|
1
1
|
redis_allocator/__init__.py,sha256=TVjUm-8YEu_MQD_PkfeIKiVknpCJBrUY9cWN1LlaZcU,1016
|
2
|
-
redis_allocator/_version.py,sha256=
|
3
|
-
redis_allocator/allocator.py,sha256=
|
2
|
+
redis_allocator/_version.py,sha256=on4Bj4mGEjEjyUkQExxprhOoEopcv_sPapsEnNxyelE,22
|
3
|
+
redis_allocator/allocator.py,sha256=oFJSRAhFJsBbeho5TibY81_3Vy07glrAuEhpIOYfeJI,47282
|
4
4
|
redis_allocator/lock.py,sha256=fqf6WUWHKYenEArWopMIF6kWEnDfADC-bZvnQImsQVo,27400
|
5
5
|
redis_allocator/task_queue.py,sha256=8DjNr2uxhzCsHatV_CHOeGh7_K9pqQZFApSbe2blRO0,14989
|
6
|
-
redis_allocator-0.3.
|
6
|
+
redis_allocator-0.3.3.dist-info/licenses/LICENSE,sha256=Wt4X1rHpffQfEiyWcDUx8BMLjXxfPqaiYZ7Lgsj7L4c,1068
|
7
7
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
-
tests/conftest.py,sha256=
|
8
|
+
tests/conftest.py,sha256=Ts82uylQSzP_GcaN0E02o3xcFdjw20cXNzh3RAdYKW4,3967
|
9
9
|
tests/test_allocator.py,sha256=hFKgLe_yONtEjjm6zssUnhK0tzihG_1xZMziztHmqqA,22404
|
10
10
|
tests/test_lock.py,sha256=MDMRNN46VhWqkHUIhYOMEDgZkFFCW_WjwRLTOjkFF-Q,46952
|
11
11
|
tests/test_task_queue.py,sha256=Fh5naikFajfOvL6GngEy_TPfOYCYZolZfVwtR6T4dTY,31710
|
12
|
-
redis_allocator-0.3.
|
13
|
-
redis_allocator-0.3.
|
14
|
-
redis_allocator-0.3.
|
15
|
-
redis_allocator-0.3.
|
12
|
+
redis_allocator-0.3.3.dist-info/METADATA,sha256=oEPcsqP1oiKP_HaZgIgfEEqIxuY6c9aoapC5ecLrP8w,21653
|
13
|
+
redis_allocator-0.3.3.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
14
|
+
redis_allocator-0.3.3.dist-info/top_level.txt,sha256=0hXzU7sK5FCeSolTEYxThOt3HOybnwaXv1FLRJvHVgI,22
|
15
|
+
redis_allocator-0.3.3.dist-info/RECORD,,
|
tests/conftest.py
CHANGED
@@ -66,6 +66,7 @@ class _TestObject(RedisAllocatableClass):
|
|
66
66
|
def open(self):
|
67
67
|
"""Open the object."""
|
68
68
|
self.closed = False
|
69
|
+
return self
|
69
70
|
|
70
71
|
def close(self):
|
71
72
|
"""Mark the object as closed."""
|
@@ -127,16 +128,6 @@ def test_updater() -> _TestUpdater:
|
|
127
128
|
return _TestUpdater([["key1", "key2"], ["key4", "key5", "key6"], ["key7", "key8", "key9"]])
|
128
129
|
|
129
130
|
|
130
|
-
class _TestRedisAllocator(RedisAllocator):
|
131
|
-
|
132
|
-
@property
|
133
|
-
def _lua_required_string(self):
|
134
|
-
return f'''
|
135
|
-
os.time = function() return tonumber(redis.call("TIME")[1]) end
|
136
|
-
{super()._lua_required_string}
|
137
|
-
'''
|
138
|
-
|
139
|
-
|
140
131
|
@pytest.fixture(params=[False, True])
|
141
132
|
def allocator_with_policy(redis_client: Redis, test_updater: _TestUpdater, request: pytest.FixtureRequest) -> RedisAllocator:
|
142
133
|
"""Create a RedisAllocator with a default policy."""
|
@@ -147,7 +138,7 @@ def allocator_with_policy(redis_client: Redis, test_updater: _TestUpdater, reque
|
|
147
138
|
updater=test_updater
|
148
139
|
)
|
149
140
|
|
150
|
-
alloc =
|
141
|
+
alloc = RedisAllocator(
|
151
142
|
redis_client,
|
152
143
|
'test-policy',
|
153
144
|
'alloc-lock',
|
File without changes
|
File without changes
|
File without changes
|