redis-simplify 0.1.0__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.
@@ -0,0 +1,364 @@
1
+ Metadata-Version: 2.4
2
+ Name: redis-simplify
3
+ Version: 0.1.0
4
+ Summary: Wrapper de conveniência para Redis - conexão, JSON helpers e reconexão automática
5
+ Author-email: Paulo Ricardo Tebet Lyrio <tebetpaulo91@yahoo.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Paulouuul/redis-simplify
8
+ Project-URL: Repository, https://github.com/Paulouuul/redis-simplify
9
+ Project-URL: Issues, https://github.com/Paulouuul/redis-simplify/issues
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: redis>=4.0.0
22
+
23
+ # redis-simplify
24
+
25
+ [![PyPI Version](https://img.shields.io/pypi/v/redis-simplify)](https://pypi.org/project/redis-simplify/)
26
+ [![Python Versions](https://img.shields.io/pypi/pyversions/redis-simplify)](https://pypi.org/project/redis-simplify/)
27
+ [![License](https://img.shields.io/pypi/l/redis-simplify)](LICENSE)
28
+
29
+ A lightweight synchronous convenience wrapper for Redis built on top of **redis-py**.
30
+
31
+ `redis-simplify` was created to reduce repetitive Redis boilerplate in Python applications by providing a simple and consistent interface with automatic reconnection, JSON helpers, centralized logging, and defensive error handling.
32
+
33
+ > This package is not a Redis client replacement. It is a convenience layer built on top of `redis-py` to simplify common Redis operations.
34
+
35
+ ---
36
+
37
+ ## Features
38
+
39
+ * Explicit Redis configuration (`host`, `port`, `password`, `db`)
40
+ * Does **not** automatically read `.env` files
41
+ * Automatic reconnection when Redis becomes unavailable
42
+ * Centralized logging and error handling
43
+ * JSON helpers for storing Python dictionaries
44
+ * Safe fallback values on failures
45
+ * Fully tested with `pytest`
46
+ * Lightweight implementation
47
+ * Synchronous API
48
+ * Support for the most commonly used Redis operations:
49
+
50
+ * Strings
51
+ * Sets
52
+ * Hashes
53
+ * Lists
54
+ * Pipelines
55
+ * SCAN iteration
56
+
57
+ ---
58
+
59
+ ## Installation
60
+
61
+ ```bash
62
+ pip install redis-simplify
63
+ ```
64
+
65
+ ---
66
+
67
+ ## Requirements
68
+
69
+ * Python >= 3.8
70
+ * redis-py >= 4.0.0
71
+
72
+ ---
73
+
74
+ ## Quick Start
75
+
76
+ ```python
77
+ from redis_simplify import RedisClient
78
+
79
+ client = RedisClient(
80
+ host="localhost",
81
+ port=6379
82
+ )
83
+ ```
84
+
85
+ ---
86
+
87
+ ## Basic Usage
88
+
89
+ ### Strings
90
+
91
+ ```python
92
+ from redis_simplify import RedisClient
93
+
94
+ client = RedisClient(host="localhost", port=6379)
95
+
96
+ client.set("chave", "valor")
97
+
98
+ print(client.get("chave"))
99
+ ```
100
+
101
+ Output:
102
+
103
+ ```python
104
+ valor
105
+ ```
106
+
107
+ ---
108
+
109
+ ### JSON Helpers
110
+
111
+ Store Python dictionaries directly in Redis.
112
+
113
+ ```python
114
+ client.set_json(
115
+ "usuario:1",
116
+ {
117
+ "nome": "João",
118
+ "idade": 30
119
+ }
120
+ )
121
+
122
+ print(client.get_json("usuario:1"))
123
+ ```
124
+
125
+ Output:
126
+
127
+ ```python
128
+ {
129
+ "nome": "João",
130
+ "idade": 30
131
+ }
132
+ ```
133
+
134
+ ---
135
+
136
+ ### Sets
137
+
138
+ ```python
139
+ client.sadd("tags", "python", "redis")
140
+
141
+ print(client.smembers("tags"))
142
+ ```
143
+
144
+ Possible output:
145
+
146
+ ```python
147
+ {"python", "redis"}
148
+ ```
149
+
150
+ ---
151
+
152
+ ### Connection Check
153
+
154
+ ```python
155
+ if client.ping():
156
+ print("Redis online")
157
+ else:
158
+ print("Redis unavailable")
159
+ ```
160
+
161
+ ---
162
+
163
+ ## Automatic Reconnection
164
+
165
+ Before executing operations, the client verifies the connection status.
166
+
167
+ If Redis becomes unavailable, the wrapper automatically attempts to reconnect before executing the requested command.
168
+
169
+ This behavior is transparent to application code and helps reduce connection-management boilerplate.
170
+
171
+ ---
172
+
173
+ ## Error Handling
174
+
175
+ All operations include consistent exception handling and logging.
176
+
177
+ Instead of propagating Redis exceptions, the wrapper logs errors and returns safe fallback values whenever possible.
178
+
179
+ ### Fallback Values
180
+
181
+ | Return Type | Fallback |
182
+ | --------------- | -------- |
183
+ | Object / String | `None` |
184
+ | Boolean | `False` |
185
+ | Numeric | `0` |
186
+ | List | `[]` |
187
+ | Dictionary | `{}` |
188
+ | Set | `set()` |
189
+
190
+ This approach helps keep application code clean and reduces repetitive `try/except` blocks.
191
+
192
+ ---
193
+
194
+ ## Available Methods
195
+
196
+ ### Strings
197
+
198
+ | Method | Description |
199
+ | -------------------------------------- | ----------------------- |
200
+ | `set(key, value, expire_seconds=None)` | Set a value |
201
+ | `get(key)` | Retrieve a value |
202
+ | `delete(*keys)` | Delete one or more keys |
203
+ | `exists(key)` | Check if a key exists |
204
+ | `expire(key, seconds)` | Set expiration time |
205
+ | `incr(key)` | Increment a value |
206
+ | `decr(key)` | Decrement a value |
207
+
208
+ ---
209
+
210
+ ### JSON
211
+
212
+ | Method | Description |
213
+ | ------------------------------------------ | ----------------------------- |
214
+ | `set_json(key, data, expire_seconds=None)` | Store a dictionary as JSON |
215
+ | `get_json(key)` | Retrieve and deserialize JSON |
216
+
217
+ ---
218
+
219
+ ### Sets
220
+
221
+ | Method | Description |
222
+ | ----------------------- | -------------------- |
223
+ | `sadd(key, *values)` | Add members |
224
+ | `srem(key, *values)` | Remove members |
225
+ | `smembers(key)` | Retrieve all members |
226
+ | `sismember(key, value)` | Check membership |
227
+ | `scard(key)` | Count members |
228
+
229
+ ---
230
+
231
+ ### Hashes
232
+
233
+ | Method | Description |
234
+ | ------------------------- | ------------------- |
235
+ | `hset(key, field, value)` | Set a hash field |
236
+ | `hget(key, field)` | Retrieve a field |
237
+ | `hgetall(key)` | Retrieve all fields |
238
+
239
+ ---
240
+
241
+ ### Lists
242
+
243
+ | Method | Description |
244
+ | ------------------------- | ---------------------------- |
245
+ | `lpush(key, *values)` | Push values to the beginning |
246
+ | `rpush(key, *values)` | Push values to the end |
247
+ | `lrange(key, start, end)` | Retrieve a range of values |
248
+
249
+ ---
250
+
251
+ ### Utilities
252
+
253
+ | Method | Description |
254
+ | ---------------------------------------- | -------------------------- |
255
+ | `ping()` | Verify connectivity |
256
+ | `pipeline()` | Create a Redis pipeline |
257
+ | `scan(cursor=0, match=None, count=None)` | Iterate keys using SCAN |
258
+ | `flush_all()` | Remove all Redis databases |
259
+ | `close()` | Close the connection |
260
+
261
+ ---
262
+
263
+ ## Pipeline Example
264
+
265
+ ```python
266
+ pipe = client.pipeline()
267
+
268
+ pipe.set("user:1", "John")
269
+ pipe.set("user:2", "Jane")
270
+
271
+ pipe.execute()
272
+ ```
273
+
274
+ ---
275
+
276
+ ## SCAN Example
277
+
278
+ ```python
279
+ cursor = 0
280
+
281
+ while True:
282
+ cursor, keys = client.scan(
283
+ cursor=cursor,
284
+ match="user:*",
285
+ count=100
286
+ )
287
+
288
+ print(keys)
289
+
290
+ if cursor == 0:
291
+ break
292
+ ```
293
+
294
+ ---
295
+
296
+ ## Shared Instance Pattern
297
+
298
+ `redis-simplify` does not enforce a Singleton pattern.
299
+
300
+ However, many applications create a single shared instance and reuse it throughout the project:
301
+
302
+ ```python
303
+ from redis_simplify import RedisClient
304
+
305
+ redis_client = RedisClient(
306
+ host="localhost",
307
+ port=6379
308
+ )
309
+ ```
310
+
311
+ ---
312
+
313
+ ## Why redis-simplify?
314
+
315
+ Many projects repeatedly implement:
316
+
317
+ * Redis connection setup
318
+ * Health checks
319
+ * Reconnection logic
320
+ * JSON serialization and deserialization
321
+ * Logging
322
+ * Defensive exception handling
323
+
324
+ `redis-simplify` centralizes these concerns into a small reusable wrapper while preserving the familiar Redis workflow provided by `redis-py`.
325
+
326
+ ---
327
+
328
+ ## Running Tests
329
+
330
+ The project includes automated tests built with `pytest`.
331
+
332
+ ```bash
333
+ pytest
334
+ ```
335
+
336
+ ---
337
+
338
+ ## Contributing
339
+
340
+ Contributions are welcome.
341
+
342
+ To contribute:
343
+
344
+ 1. Fork the repository
345
+ 2. Create a feature branch
346
+ 3. Make your changes
347
+ 4. Add or update tests when applicable
348
+ 5. Open a Pull Request
349
+
350
+ Bug reports, improvements, and feature suggestions are appreciated.
351
+
352
+ ---
353
+
354
+ ## License
355
+
356
+ This project is licensed under the MIT License.
357
+
358
+ ---
359
+
360
+ ## Author
361
+
362
+ **Paulo Ricardo Tebet Lyrio**
363
+
364
+ GitHub: https://github.com/Paulouuul/redis-simplify
@@ -0,0 +1,342 @@
1
+ # redis-simplify
2
+
3
+ [![PyPI Version](https://img.shields.io/pypi/v/redis-simplify)](https://pypi.org/project/redis-simplify/)
4
+ [![Python Versions](https://img.shields.io/pypi/pyversions/redis-simplify)](https://pypi.org/project/redis-simplify/)
5
+ [![License](https://img.shields.io/pypi/l/redis-simplify)](LICENSE)
6
+
7
+ A lightweight synchronous convenience wrapper for Redis built on top of **redis-py**.
8
+
9
+ `redis-simplify` was created to reduce repetitive Redis boilerplate in Python applications by providing a simple and consistent interface with automatic reconnection, JSON helpers, centralized logging, and defensive error handling.
10
+
11
+ > This package is not a Redis client replacement. It is a convenience layer built on top of `redis-py` to simplify common Redis operations.
12
+
13
+ ---
14
+
15
+ ## Features
16
+
17
+ * Explicit Redis configuration (`host`, `port`, `password`, `db`)
18
+ * Does **not** automatically read `.env` files
19
+ * Automatic reconnection when Redis becomes unavailable
20
+ * Centralized logging and error handling
21
+ * JSON helpers for storing Python dictionaries
22
+ * Safe fallback values on failures
23
+ * Fully tested with `pytest`
24
+ * Lightweight implementation
25
+ * Synchronous API
26
+ * Support for the most commonly used Redis operations:
27
+
28
+ * Strings
29
+ * Sets
30
+ * Hashes
31
+ * Lists
32
+ * Pipelines
33
+ * SCAN iteration
34
+
35
+ ---
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ pip install redis-simplify
41
+ ```
42
+
43
+ ---
44
+
45
+ ## Requirements
46
+
47
+ * Python >= 3.8
48
+ * redis-py >= 4.0.0
49
+
50
+ ---
51
+
52
+ ## Quick Start
53
+
54
+ ```python
55
+ from redis_simplify import RedisClient
56
+
57
+ client = RedisClient(
58
+ host="localhost",
59
+ port=6379
60
+ )
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Basic Usage
66
+
67
+ ### Strings
68
+
69
+ ```python
70
+ from redis_simplify import RedisClient
71
+
72
+ client = RedisClient(host="localhost", port=6379)
73
+
74
+ client.set("chave", "valor")
75
+
76
+ print(client.get("chave"))
77
+ ```
78
+
79
+ Output:
80
+
81
+ ```python
82
+ valor
83
+ ```
84
+
85
+ ---
86
+
87
+ ### JSON Helpers
88
+
89
+ Store Python dictionaries directly in Redis.
90
+
91
+ ```python
92
+ client.set_json(
93
+ "usuario:1",
94
+ {
95
+ "nome": "João",
96
+ "idade": 30
97
+ }
98
+ )
99
+
100
+ print(client.get_json("usuario:1"))
101
+ ```
102
+
103
+ Output:
104
+
105
+ ```python
106
+ {
107
+ "nome": "João",
108
+ "idade": 30
109
+ }
110
+ ```
111
+
112
+ ---
113
+
114
+ ### Sets
115
+
116
+ ```python
117
+ client.sadd("tags", "python", "redis")
118
+
119
+ print(client.smembers("tags"))
120
+ ```
121
+
122
+ Possible output:
123
+
124
+ ```python
125
+ {"python", "redis"}
126
+ ```
127
+
128
+ ---
129
+
130
+ ### Connection Check
131
+
132
+ ```python
133
+ if client.ping():
134
+ print("Redis online")
135
+ else:
136
+ print("Redis unavailable")
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Automatic Reconnection
142
+
143
+ Before executing operations, the client verifies the connection status.
144
+
145
+ If Redis becomes unavailable, the wrapper automatically attempts to reconnect before executing the requested command.
146
+
147
+ This behavior is transparent to application code and helps reduce connection-management boilerplate.
148
+
149
+ ---
150
+
151
+ ## Error Handling
152
+
153
+ All operations include consistent exception handling and logging.
154
+
155
+ Instead of propagating Redis exceptions, the wrapper logs errors and returns safe fallback values whenever possible.
156
+
157
+ ### Fallback Values
158
+
159
+ | Return Type | Fallback |
160
+ | --------------- | -------- |
161
+ | Object / String | `None` |
162
+ | Boolean | `False` |
163
+ | Numeric | `0` |
164
+ | List | `[]` |
165
+ | Dictionary | `{}` |
166
+ | Set | `set()` |
167
+
168
+ This approach helps keep application code clean and reduces repetitive `try/except` blocks.
169
+
170
+ ---
171
+
172
+ ## Available Methods
173
+
174
+ ### Strings
175
+
176
+ | Method | Description |
177
+ | -------------------------------------- | ----------------------- |
178
+ | `set(key, value, expire_seconds=None)` | Set a value |
179
+ | `get(key)` | Retrieve a value |
180
+ | `delete(*keys)` | Delete one or more keys |
181
+ | `exists(key)` | Check if a key exists |
182
+ | `expire(key, seconds)` | Set expiration time |
183
+ | `incr(key)` | Increment a value |
184
+ | `decr(key)` | Decrement a value |
185
+
186
+ ---
187
+
188
+ ### JSON
189
+
190
+ | Method | Description |
191
+ | ------------------------------------------ | ----------------------------- |
192
+ | `set_json(key, data, expire_seconds=None)` | Store a dictionary as JSON |
193
+ | `get_json(key)` | Retrieve and deserialize JSON |
194
+
195
+ ---
196
+
197
+ ### Sets
198
+
199
+ | Method | Description |
200
+ | ----------------------- | -------------------- |
201
+ | `sadd(key, *values)` | Add members |
202
+ | `srem(key, *values)` | Remove members |
203
+ | `smembers(key)` | Retrieve all members |
204
+ | `sismember(key, value)` | Check membership |
205
+ | `scard(key)` | Count members |
206
+
207
+ ---
208
+
209
+ ### Hashes
210
+
211
+ | Method | Description |
212
+ | ------------------------- | ------------------- |
213
+ | `hset(key, field, value)` | Set a hash field |
214
+ | `hget(key, field)` | Retrieve a field |
215
+ | `hgetall(key)` | Retrieve all fields |
216
+
217
+ ---
218
+
219
+ ### Lists
220
+
221
+ | Method | Description |
222
+ | ------------------------- | ---------------------------- |
223
+ | `lpush(key, *values)` | Push values to the beginning |
224
+ | `rpush(key, *values)` | Push values to the end |
225
+ | `lrange(key, start, end)` | Retrieve a range of values |
226
+
227
+ ---
228
+
229
+ ### Utilities
230
+
231
+ | Method | Description |
232
+ | ---------------------------------------- | -------------------------- |
233
+ | `ping()` | Verify connectivity |
234
+ | `pipeline()` | Create a Redis pipeline |
235
+ | `scan(cursor=0, match=None, count=None)` | Iterate keys using SCAN |
236
+ | `flush_all()` | Remove all Redis databases |
237
+ | `close()` | Close the connection |
238
+
239
+ ---
240
+
241
+ ## Pipeline Example
242
+
243
+ ```python
244
+ pipe = client.pipeline()
245
+
246
+ pipe.set("user:1", "John")
247
+ pipe.set("user:2", "Jane")
248
+
249
+ pipe.execute()
250
+ ```
251
+
252
+ ---
253
+
254
+ ## SCAN Example
255
+
256
+ ```python
257
+ cursor = 0
258
+
259
+ while True:
260
+ cursor, keys = client.scan(
261
+ cursor=cursor,
262
+ match="user:*",
263
+ count=100
264
+ )
265
+
266
+ print(keys)
267
+
268
+ if cursor == 0:
269
+ break
270
+ ```
271
+
272
+ ---
273
+
274
+ ## Shared Instance Pattern
275
+
276
+ `redis-simplify` does not enforce a Singleton pattern.
277
+
278
+ However, many applications create a single shared instance and reuse it throughout the project:
279
+
280
+ ```python
281
+ from redis_simplify import RedisClient
282
+
283
+ redis_client = RedisClient(
284
+ host="localhost",
285
+ port=6379
286
+ )
287
+ ```
288
+
289
+ ---
290
+
291
+ ## Why redis-simplify?
292
+
293
+ Many projects repeatedly implement:
294
+
295
+ * Redis connection setup
296
+ * Health checks
297
+ * Reconnection logic
298
+ * JSON serialization and deserialization
299
+ * Logging
300
+ * Defensive exception handling
301
+
302
+ `redis-simplify` centralizes these concerns into a small reusable wrapper while preserving the familiar Redis workflow provided by `redis-py`.
303
+
304
+ ---
305
+
306
+ ## Running Tests
307
+
308
+ The project includes automated tests built with `pytest`.
309
+
310
+ ```bash
311
+ pytest
312
+ ```
313
+
314
+ ---
315
+
316
+ ## Contributing
317
+
318
+ Contributions are welcome.
319
+
320
+ To contribute:
321
+
322
+ 1. Fork the repository
323
+ 2. Create a feature branch
324
+ 3. Make your changes
325
+ 4. Add or update tests when applicable
326
+ 5. Open a Pull Request
327
+
328
+ Bug reports, improvements, and feature suggestions are appreciated.
329
+
330
+ ---
331
+
332
+ ## License
333
+
334
+ This project is licensed under the MIT License.
335
+
336
+ ---
337
+
338
+ ## Author
339
+
340
+ **Paulo Ricardo Tebet Lyrio**
341
+
342
+ GitHub: https://github.com/Paulouuul/redis-simplify