redis-allocator 0.0.1__py3-none-any.whl → 0.3.1__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.
@@ -1,229 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: redis-allocator
3
- Version: 0.0.1
4
- Summary: Redis-based resource allocation system.
5
- Home-page: https://github.com/invoker-bot/RedisAllocator-python
6
- Author: Invoker Bot
7
- Author-email: invoker-bot@outlook.com
8
- License: MIT
9
- Classifier: Development Status :: 4 - Beta
10
- Classifier: Intended Audience :: Developers
11
- Classifier: Programming Language :: Python :: 3.9
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
15
- Requires-Python: >=3.10
16
- Description-Content-Type: text/markdown
17
- License-File: LICENSE
18
- Requires-Dist: redis>=5.0.0
19
- Provides-Extra: test
20
- Requires-Dist: pytest>=7.4.3; extra == "test"
21
- Requires-Dist: pytest-cov>=4.1.0; extra == "test"
22
- Requires-Dist: pytest-mock>=3.12.0; extra == "test"
23
- Requires-Dist: fakeredis[lua]>=2.20.1; extra == "test"
24
- Requires-Dist: flake8>=6.1.0; extra == "test"
25
- Requires-Dist: freezegun>=1.4.0; extra == "test"
26
- Dynamic: author
27
- Dynamic: author-email
28
- Dynamic: classifier
29
- Dynamic: description
30
- Dynamic: description-content-type
31
- Dynamic: home-page
32
- Dynamic: license
33
- Dynamic: license-file
34
- Dynamic: provides-extra
35
- Dynamic: requires-dist
36
- Dynamic: requires-python
37
- Dynamic: summary
38
-
39
- # RedisAllocator
40
-
41
- ## Project Overview
42
-
43
- RedisAllocator is an efficient Redis-based distributed memory allocation system. This system simulates traditional memory allocation mechanisms but implements them in a distributed environment, using Redis as the underlying storage and coordination tool.
44
-
45
- > **Note**: Currently, RedisAllocator only supports single Redis instance deployments. For Redis cluster environments, we recommend using RedLock for distributed locking operations.
46
-
47
- ### Core Features
48
-
49
- - **Distributed Locking**: Provides robust distributed locking mechanisms to ensure data consistency in concurrent environments
50
- - **Resource Allocation**: Implements a distributed resource allocation system with support for:
51
- - Priority-based distribution
52
- - Soft binding
53
- - Garbage collection
54
- - Health checking
55
- - **Task Management**: Implements a distributed task queue system for efficient task processing across multiple workers
56
- - **Object Allocation**: Supports allocation of resources with priority-based distribution and soft binding
57
- - **Health Checking**: Monitors the health of distributed instances and automatically handles unhealthy resources
58
- - **Garbage Collection**: Automatically identifies and reclaims unused resources, optimizing memory usage
59
-
60
-
61
- ## Installation
62
-
63
- ```bash
64
- pip install redis-allocator
65
- ```
66
-
67
- ## Quick Start
68
-
69
- ### Using RedisLock for Distributed Locking
70
-
71
- ```python
72
- from redis import Redis
73
- from redis_allocator import RedisLock
74
-
75
- # Initialize Redis client
76
- redis = Redis(host='localhost', port=6379)
77
-
78
- # Create a RedisLock instance
79
- lock = RedisLock(redis, "myapp", "resource-lock")
80
-
81
- # Acquire a lock
82
- if lock.lock("resource-123", timeout=60):
83
- try:
84
- # Perform operations with the locked resource
85
- print("Resource locked successfully")
86
- finally:
87
- # Release the lock when done
88
- lock.unlock("resource-123")
89
- ```
90
-
91
- ### Using RedisAllocator for Resource Management
92
-
93
- ```python
94
- from redis import Redis
95
- from redis_allocator import RedisAllocator
96
-
97
- # Initialize Redis client
98
- redis = Redis(host='localhost', port=6379)
99
-
100
- # Create a RedisAllocator instance
101
- allocator = RedisAllocator(
102
- redis,
103
- prefix='myapp',
104
- suffix='allocator',
105
- shared=False # Whether resources can be shared
106
- )
107
-
108
- # Add resources to the pool
109
- allocator.extend(['resource-1', 'resource-2', 'resource-3'])
110
-
111
- # Allocate a resource key (returns only the key)
112
- key = allocator.malloc_key(timeout=120)
113
- if key:
114
- try:
115
- # Use the allocated resource
116
- print(f"Allocated resource: {key}")
117
- finally:
118
- # Free the resource when done
119
- allocator.free_keys(key)
120
-
121
- # Allocate a resource with object (returns a RedisAllocatorObject)
122
- allocated_obj = allocator.malloc(timeout=120)
123
- if allocated_obj:
124
- try:
125
- # The key is available as a property
126
- print(f"Allocated resource: {allocated_obj.key}")
127
-
128
- # Update the resource's lock timeout
129
- allocated_obj.update(timeout=60)
130
- finally:
131
- # Free the resource when done
132
- allocator.free(allocated_obj)
133
-
134
- # Using soft binding (associates a name with a resource)
135
- allocator.update_soft_bind("worker-1", "resource-1")
136
- # Later...
137
- allocator.unbind_soft_bind("worker-1")
138
-
139
- # Garbage collection (reclaims unused resources)
140
- allocator.gc(count=10) # Check 10 items for cleanup
141
- ```
142
-
143
- ### Using RedisTaskQueue for Distributed Task Processing
144
-
145
- ```python
146
- from redis import Redis
147
- from redis_allocator import RedisTaskQueue, TaskExecutePolicy
148
- import json
149
-
150
- # Initialize Redis client
151
- redis = Redis(host='localhost', port=6379)
152
-
153
- # Process tasks in a worker
154
- def process_task(task):
155
- # Process the task (task is a RedisTask object)
156
- # You can access task.id, task.name, task.params
157
- # You can update progress with task.update(current, total)
158
- return json.dumps({"result": "processed"})
159
-
160
-
161
- # Create a task queue
162
- task_queue = RedisTaskQueue(redis, "myapp", task_fn=process_task)
163
-
164
- # Submit a task with query method
165
- result = task_queue.query(
166
- id="task-123",
167
- name="example-task",
168
- params={"input": "data"},
169
- timeout=300, # Optional timeout in seconds
170
- policy=TaskExecutePolicy.Auto, # Execution policy
171
- once=False # Whether to delete the result after getting it
172
- )
173
-
174
- # Start listening for tasks
175
- task_queue.listen(
176
- names=["example-task"], # List of task names to listen for
177
- workers=128, # Number of worker threads
178
- event=None # Optional event to signal when to stop listening
179
- )
180
- ```
181
-
182
- ## Modules
183
-
184
- RedisAllocator consists of several modules, each providing specific functionality:
185
-
186
- - **lock.py**: Provides `RedisLock` and `RedisLockPool` for distributed locking mechanisms
187
- - **task_queue.py**: Implements `RedisTaskQueue` for distributed task processing
188
- - **allocator.py**: Contains `RedisAllocator` and `RedisThreadHealthChecker` for resource allocation
189
-
190
-
191
- ## Roadmap
192
-
193
- ### Phase 1 (Completed)
194
- - [x] Distributed lock mechanism implementation
195
- - [x] Task queue processing system
196
- - [x] Resource allocation and management
197
- - [x] Basic health checking and monitoring
198
- - [x] Object allocation with serialization
199
- - [x] Unit tests for core components
200
-
201
- ### Phase 2 (In Progress)
202
- - [ ] Advanced sharding implementation
203
- - [ ] Performance optimization and benchmarking
204
- - [ ] Documentation improvement
205
- - [ ] Enhanced error handling and recovery
206
-
207
- ### Phase 3 (Planned)
208
- - [ ] Advanced garbage collection strategies
209
- - [ ] Redis cluster support
210
- - [ ] Fault recovery mechanisms
211
- - [ ] Automated resource scaling
212
-
213
- ### Phase 4 (Future)
214
- - [ ] API stability and backward compatibility
215
- - [ ] Performance monitoring and tuning tools
216
- - [ ] Advanced features (transaction support, data compression, etc.)
217
- - [ ] Production environment validation and case studies
218
-
219
- ## Contributing
220
-
221
- Contributions and suggestions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
222
-
223
- ## License
224
-
225
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
226
-
227
- ## Contact
228
-
229
- For questions or suggestions, please contact us through GitHub Issues.
@@ -1,14 +0,0 @@
1
- redis_allocator/__init__.py,sha256=x4koK9zx8W1wWnrwt72tPve-LwKdhKbKxTGgacZ8q84,800
2
- redis_allocator/allocator.py,sha256=qqxKOAPG_QgTp3gxvi8O443dPC9DGr3_iM5nCP3lidM,21831
3
- redis_allocator/lock.py,sha256=HSCXyBhO3qBMylvByqskekHp6CMgqwbVcwMyP77pBmM,24768
4
- redis_allocator/task_queue.py,sha256=NalI77hk1u8X-JBWpGoZFv5nJXzfem5fDthiSa9cgFg,13596
5
- redis_allocator-0.0.1.dist-info/licenses/LICENSE,sha256=NiCCQOo0TQ_djjGpoCphsT59Bgu2sLOk8rVwIRxrqQE,1089
6
- tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- tests/conftest.py,sha256=gsMBUrUTGxD-ki29rWrtJCZZymb7n7biRV6lWcd7fWo,1124
8
- tests/test_allocator.py,sha256=F-GHbgWGss5CvbUsQt1AvLib9V0Rxyih1HisHWFi6jU,18608
9
- tests/test_lock.py,sha256=wA2po5vSgeoyOeH9-bTF3fxVwh-CmR-CSH-ZThVHisY,35294
10
- tests/test_task_queue.py,sha256=pohhYpw9RIPJma9wQPEF9r4pKkK__PZDd6Y10mEPtjs,33071
11
- redis_allocator-0.0.1.dist-info/METADATA,sha256=nSxDu1WR1H6NJGdEu3eoVkPivnzEiM04DbVxk5VmLss,7465
12
- redis_allocator-0.0.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
13
- redis_allocator-0.0.1.dist-info/top_level.txt,sha256=0hXzU7sK5FCeSolTEYxThOt3HOybnwaXv1FLRJvHVgI,22
14
- redis_allocator-0.0.1.dist-info/RECORD,,