tigrbl_engine_redis 0.1.1.dev2__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.
- tigrbl_engine_redis-0.1.1.dev2/LICENSE +176 -0
- tigrbl_engine_redis-0.1.1.dev2/PKG-INFO +67 -0
- tigrbl_engine_redis-0.1.1.dev2/README.md +41 -0
- tigrbl_engine_redis-0.1.1.dev2/pyproject.toml +62 -0
- tigrbl_engine_redis-0.1.1.dev2/setup.cfg +4 -0
- tigrbl_engine_redis-0.1.1.dev2/src/tigrbl_engine_redis/__init__.py +19 -0
- tigrbl_engine_redis-0.1.1.dev2/src/tigrbl_engine_redis/engine.py +54 -0
- tigrbl_engine_redis-0.1.1.dev2/src/tigrbl_engine_redis/session.py +137 -0
- tigrbl_engine_redis-0.1.1.dev2/src/tigrbl_engine_redis.egg-info/PKG-INFO +67 -0
- tigrbl_engine_redis-0.1.1.dev2/src/tigrbl_engine_redis.egg-info/SOURCES.txt +13 -0
- tigrbl_engine_redis-0.1.1.dev2/src/tigrbl_engine_redis.egg-info/dependency_links.txt +1 -0
- tigrbl_engine_redis-0.1.1.dev2/src/tigrbl_engine_redis.egg-info/entry_points.txt +2 -0
- tigrbl_engine_redis-0.1.1.dev2/src/tigrbl_engine_redis.egg-info/requires.txt +2 -0
- tigrbl_engine_redis-0.1.1.dev2/src/tigrbl_engine_redis.egg-info/top_level.txt +1 -0
- tigrbl_engine_redis-0.1.1.dev2/tests/test_smoke.py +8 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tigrbl_engine_redis
|
|
3
|
+
Version: 0.1.1.dev2
|
|
4
|
+
Summary: Tigrbl engine plugin for Redis.
|
|
5
|
+
Author-email: Jacob Stewart <jacob@swarmauri.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Keywords: tigrbl,engine,plugin,redis,cache,database
|
|
8
|
+
Classifier: Development Status :: 1 - Planning
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Environment :: Plugins
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Topic :: Database
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Requires-Python: <3.13,>=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: tigrbl>=0.3.0.dev4
|
|
24
|
+
Requires-Dist: redis>=5.0.0
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# tigrbl_engine_redis
|
|
28
|
+
|
|
29
|
+
A Redis engine plugin for **tigrbl**. This package registers a new engine kind
|
|
30
|
+
`"redis"` that tigrbl auto-discovers via the `tigrbl.engine` entry-point group.
|
|
31
|
+
|
|
32
|
+
> The engine handle and session class in this package are implemented as
|
|
33
|
+
> **subclasses of tigrbl's first-class objects** (see notes below).
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install tigrbl_engine_redis
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
Once installed, refer to `kind="redis"` in your engine spec:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from tigrbl.engine.engine_spec import EngineSpec
|
|
47
|
+
|
|
48
|
+
spec = EngineSpec(kind="redis", mapping={"url": "redis://localhost:6379/0"})
|
|
49
|
+
eng, make_session = spec.build() # resolved through entry-points
|
|
50
|
+
s = make_session() # returns a RedisSession (TigrblSessionBase subclass)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### What this package provides
|
|
54
|
+
|
|
55
|
+
- `RedisEngine` — a thin subclass of `tigrbl.engine.Engine` to satisfy the
|
|
56
|
+
"first‑class engine" requirement. It stores connection parameters for
|
|
57
|
+
inspection; tigrbl keeps it as the provider's engine handle.
|
|
58
|
+
- `RedisSession` — a concrete subclass of `tigrbl.session.TigrblSessionBase`
|
|
59
|
+
that wraps a `redis.asyncio.Redis` client and implements the async
|
|
60
|
+
transaction‑aware Tigrbl Session ABC.
|
|
61
|
+
- `redis_engine()` — the entry‑point builder used by tigrbl to materialize
|
|
62
|
+
`(engine_handle, session_factory)`.
|
|
63
|
+
|
|
64
|
+
> tigrbl auto‑loads engine plugins on import (idempotent). See:
|
|
65
|
+
> `tigrbl.engine.__init__` (calls `load_engine_plugins()`), and
|
|
66
|
+
> `tigrbl.engine.plugins.load_engine_plugins()` which enumerates the `tigrbl.engine`
|
|
67
|
+
> entry‑point group and invokes each package's `register()` function.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# tigrbl_engine_redis
|
|
2
|
+
|
|
3
|
+
A Redis engine plugin for **tigrbl**. This package registers a new engine kind
|
|
4
|
+
`"redis"` that tigrbl auto-discovers via the `tigrbl.engine` entry-point group.
|
|
5
|
+
|
|
6
|
+
> The engine handle and session class in this package are implemented as
|
|
7
|
+
> **subclasses of tigrbl's first-class objects** (see notes below).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install tigrbl_engine_redis
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Once installed, refer to `kind="redis"` in your engine spec:
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from tigrbl.engine.engine_spec import EngineSpec
|
|
21
|
+
|
|
22
|
+
spec = EngineSpec(kind="redis", mapping={"url": "redis://localhost:6379/0"})
|
|
23
|
+
eng, make_session = spec.build() # resolved through entry-points
|
|
24
|
+
s = make_session() # returns a RedisSession (TigrblSessionBase subclass)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### What this package provides
|
|
28
|
+
|
|
29
|
+
- `RedisEngine` — a thin subclass of `tigrbl.engine.Engine` to satisfy the
|
|
30
|
+
"first‑class engine" requirement. It stores connection parameters for
|
|
31
|
+
inspection; tigrbl keeps it as the provider's engine handle.
|
|
32
|
+
- `RedisSession` — a concrete subclass of `tigrbl.session.TigrblSessionBase`
|
|
33
|
+
that wraps a `redis.asyncio.Redis` client and implements the async
|
|
34
|
+
transaction‑aware Tigrbl Session ABC.
|
|
35
|
+
- `redis_engine()` — the entry‑point builder used by tigrbl to materialize
|
|
36
|
+
`(engine_handle, session_factory)`.
|
|
37
|
+
|
|
38
|
+
> tigrbl auto‑loads engine plugins on import (idempotent). See:
|
|
39
|
+
> `tigrbl.engine.__init__` (calls `load_engine_plugins()`), and
|
|
40
|
+
> `tigrbl.engine.plugins.load_engine_plugins()` which enumerates the `tigrbl.engine`
|
|
41
|
+
> entry‑point group and invokes each package's `register()` function.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tigrbl_engine_redis"
|
|
3
|
+
version = "0.1.1.dev2"
|
|
4
|
+
description = "Tigrbl engine plugin for Redis."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = { text = "Apache-2.0" }
|
|
7
|
+
requires-python = ">=3.10,<3.13"
|
|
8
|
+
authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 1 - Planning",
|
|
11
|
+
"License :: OSI Approved :: Apache Software License",
|
|
12
|
+
"Programming Language :: Python",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"Programming Language :: Python :: 3.10",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Environment :: Plugins",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Topic :: Database",
|
|
21
|
+
"Topic :: Software Development :: Libraries",
|
|
22
|
+
]
|
|
23
|
+
keywords = [
|
|
24
|
+
"tigrbl",
|
|
25
|
+
"engine",
|
|
26
|
+
"plugin",
|
|
27
|
+
"redis",
|
|
28
|
+
"cache",
|
|
29
|
+
"database",
|
|
30
|
+
]
|
|
31
|
+
dependencies = [
|
|
32
|
+
"tigrbl>=0.3.0.dev4",
|
|
33
|
+
"redis>=5.0.0", # provides redis.asyncio
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.entry-points."tigrbl.engine"]
|
|
37
|
+
redis = "tigrbl_engine_redis:register"
|
|
38
|
+
|
|
39
|
+
[build-system]
|
|
40
|
+
requires = ["setuptools>=68", "wheel"]
|
|
41
|
+
build-backend = "setuptools.build_meta"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools]
|
|
44
|
+
package-dir = {"" = "src"}
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.packages.find]
|
|
47
|
+
where = ["src"]
|
|
48
|
+
include = ["tigrbl_engine_redis*"]
|
|
49
|
+
|
|
50
|
+
[dependency-groups]
|
|
51
|
+
dev = [
|
|
52
|
+
"pytest>=8.0",
|
|
53
|
+
"pytest-asyncio>=0.24.0",
|
|
54
|
+
"pytest-xdist>=3.6.1",
|
|
55
|
+
"pytest-json-report>=1.5.0",
|
|
56
|
+
"python-dotenv",
|
|
57
|
+
"requests>=2.32.3",
|
|
58
|
+
"flake8>=7.0",
|
|
59
|
+
"pytest-timeout>=2.3.1",
|
|
60
|
+
"ruff>=0.9.9",
|
|
61
|
+
"pytest-benchmark>=4.0.0",
|
|
62
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from .engine import RedisEngine, redis_engine
|
|
2
|
+
from .session import RedisSession
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def register() -> None:
|
|
6
|
+
"""Entry point hook invoked by tigrbl to register the engine kind."""
|
|
7
|
+
try:
|
|
8
|
+
from tigrbl.engine.registry import register_engine
|
|
9
|
+
except Exception: # pragma: no cover
|
|
10
|
+
from tigrbl.engine import register_engine # type: ignore
|
|
11
|
+
register_engine("redis", redis_engine)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"RedisEngine",
|
|
16
|
+
"RedisSession",
|
|
17
|
+
"redis_engine",
|
|
18
|
+
"register",
|
|
19
|
+
]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from typing import Any, Callable, Tuple, Mapping, Optional
|
|
3
|
+
|
|
4
|
+
from tigrbl.engine._engine import Engine # first-class engine façade
|
|
5
|
+
from .session import RedisSession
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class RedisEngine(Engine):
|
|
9
|
+
"""Thin, inspectable handle for Redis connectivity parameters.
|
|
10
|
+
|
|
11
|
+
This class subclasses tigrbl's first-class :class:`Engine`. It is **not**
|
|
12
|
+
responsible for connection pooling — the session constructs and owns the
|
|
13
|
+
actual Redis client.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
*,
|
|
19
|
+
url: Optional[str] = None,
|
|
20
|
+
host: Optional[str] = None,
|
|
21
|
+
port: Optional[int] = None,
|
|
22
|
+
db: Optional[int] = None,
|
|
23
|
+
**kwargs: Any,
|
|
24
|
+
) -> None:
|
|
25
|
+
# We intentionally do not call super().__init__ because the base Engine
|
|
26
|
+
# is a dataclass façade around EngineSpec. For plugin handles we only
|
|
27
|
+
# need a lightweight, inspectable object.
|
|
28
|
+
self.url = url
|
|
29
|
+
self.host = host or "localhost"
|
|
30
|
+
self.port = int(port or 6379)
|
|
31
|
+
self.db = int(db or 0)
|
|
32
|
+
self.kwargs = dict(kwargs)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def redis_engine(
|
|
36
|
+
*,
|
|
37
|
+
mapping: Optional[Mapping[str, object]] = None,
|
|
38
|
+
spec: Any = None,
|
|
39
|
+
dsn: Optional[str] = None,
|
|
40
|
+
**kwargs: Any,
|
|
41
|
+
) -> Tuple[RedisEngine, Callable[[], Any]]:
|
|
42
|
+
"""Builder function used by tigrbl to construct (engine, session_factory)."""
|
|
43
|
+
m = dict(mapping or {})
|
|
44
|
+
url = dsn or m.get("url") or m.get("dsn") or kwargs.get("url")
|
|
45
|
+
host = m.get("host") or kwargs.get("host")
|
|
46
|
+
port = m.get("port") or kwargs.get("port")
|
|
47
|
+
db = m.get("db") or kwargs.get("db")
|
|
48
|
+
engine = RedisEngine(url=url, host=host, port=port, db=db, **kwargs)
|
|
49
|
+
|
|
50
|
+
def session_factory() -> RedisSession:
|
|
51
|
+
# Let the session lazily create the redis client
|
|
52
|
+
return RedisSession(engine)
|
|
53
|
+
|
|
54
|
+
return engine, session_factory
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import inspect
|
|
4
|
+
from typing import Any, Callable, Optional
|
|
5
|
+
|
|
6
|
+
from tigrbl.session.base import TigrblSessionBase # first-class session base
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RedisSession(TigrblSessionBase):
|
|
10
|
+
"""A Tigrbl session backed by a Redis client (async).
|
|
11
|
+
|
|
12
|
+
This is a concrete subclass of Tigrbl's first-class session base. It wraps
|
|
13
|
+
a `redis.asyncio.Redis` client, exposing a minimal set of primitives to
|
|
14
|
+
satisfy the Session ABC. It treats Redis commands as statements for
|
|
15
|
+
`_execute_impl` and offers simple key/value helpers for `_get_impl`.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, engine: Any, *, url: Optional[str] = None) -> None:
|
|
19
|
+
super().__init__()
|
|
20
|
+
self._engine = engine
|
|
21
|
+
self._url_override = url
|
|
22
|
+
self._client = None
|
|
23
|
+
self._pipe = None
|
|
24
|
+
|
|
25
|
+
# ---- client lifecycle -------------------------------------------------
|
|
26
|
+
@property
|
|
27
|
+
def client(self):
|
|
28
|
+
if self._client is None:
|
|
29
|
+
try:
|
|
30
|
+
from redis.asyncio import Redis
|
|
31
|
+
except Exception as e: # pragma: no cover
|
|
32
|
+
raise RuntimeError("redis>=5.0.0 is required for RedisSession") from e
|
|
33
|
+
if self._url_override or self._engine.url:
|
|
34
|
+
self._client = Redis.from_url(self._url_override or self._engine.url) # type: ignore[arg-type]
|
|
35
|
+
else:
|
|
36
|
+
self._client = Redis(
|
|
37
|
+
host=self._engine.host, port=self._engine.port, db=self._engine.db
|
|
38
|
+
)
|
|
39
|
+
return self._client
|
|
40
|
+
|
|
41
|
+
def _target(self):
|
|
42
|
+
"""Return active pipeline if in a tx, else the client."""
|
|
43
|
+
return self._pipe if self._pipe is not None else self.client
|
|
44
|
+
|
|
45
|
+
# ---- TigrblSessionBase hooks -----------------------------------------
|
|
46
|
+
async def _tx_begin_impl(self) -> None:
|
|
47
|
+
self._pipe = self.client.pipeline(transaction=True)
|
|
48
|
+
|
|
49
|
+
async def _tx_commit_impl(self) -> None:
|
|
50
|
+
if self._pipe is not None:
|
|
51
|
+
await self._pipe.execute()
|
|
52
|
+
self._pipe = None
|
|
53
|
+
|
|
54
|
+
async def _tx_rollback_impl(self) -> None:
|
|
55
|
+
if self._pipe is not None:
|
|
56
|
+
# pipeline.reset() discards queued commands
|
|
57
|
+
reset = getattr(self._pipe, "reset", None)
|
|
58
|
+
if callable(reset):
|
|
59
|
+
rv = reset()
|
|
60
|
+
if inspect.isawaitable(rv):
|
|
61
|
+
await rv
|
|
62
|
+
self._pipe = None
|
|
63
|
+
|
|
64
|
+
def _add_impl(self, obj: Any) -> Any:
|
|
65
|
+
"""Best-effort 'add' for key/value; accepts {'key': k, 'value': v} or (k, v)."""
|
|
66
|
+
if isinstance(obj, dict) and "key" in obj and "value" in obj:
|
|
67
|
+
return self._target().set(obj["key"], obj["value"])
|
|
68
|
+
if isinstance(obj, (list, tuple)) and len(obj) == 2:
|
|
69
|
+
k, v = obj
|
|
70
|
+
return self._target().set(k, v)
|
|
71
|
+
raise NotImplementedError(
|
|
72
|
+
"RedisSession.add expects {'key','value'} or (key, value)"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
async def _delete_impl(self, obj: Any) -> None:
|
|
76
|
+
key = obj if isinstance(obj, str) else getattr(obj, "key", None)
|
|
77
|
+
if not key:
|
|
78
|
+
raise NotImplementedError("RedisSession.delete expects a key (str)")
|
|
79
|
+
await self._target().delete(key)
|
|
80
|
+
|
|
81
|
+
async def _flush_impl(self) -> None:
|
|
82
|
+
# No-op for Redis; commands are sent immediately or on execute()
|
|
83
|
+
return
|
|
84
|
+
|
|
85
|
+
async def _refresh_impl(self, obj: Any) -> None:
|
|
86
|
+
# No-op for key/value
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
async def _get_impl(self, model: type, ident: Any) -> Any | None:
|
|
90
|
+
# Interpret ident as a key; model is ignored in this simple adapter
|
|
91
|
+
return await self._target().get(ident)
|
|
92
|
+
|
|
93
|
+
async def _execute_impl(self, stmt: Any) -> Any:
|
|
94
|
+
"""Execute a Redis command.
|
|
95
|
+
- If `stmt` is a callable, call it with the underlying client/pipe.
|
|
96
|
+
- If `stmt` is a tuple/list like ('SET','k','v'), look up the method.
|
|
97
|
+
- If `stmt` is a raw command string, use execute_command().
|
|
98
|
+
"""
|
|
99
|
+
tgt = self._target()
|
|
100
|
+
if callable(stmt):
|
|
101
|
+
rv = stmt(tgt)
|
|
102
|
+
return await rv if inspect.isawaitable(rv) else rv
|
|
103
|
+
if isinstance(stmt, (list, tuple)) and stmt:
|
|
104
|
+
cmd, *args = stmt
|
|
105
|
+
fn = getattr(tgt, str(cmd).lower(), None)
|
|
106
|
+
if not callable(fn):
|
|
107
|
+
# Fall back to execute_command
|
|
108
|
+
return await tgt.execute_command(str(cmd), *args)
|
|
109
|
+
rv = fn(*args)
|
|
110
|
+
return await rv if inspect.isawaitable(rv) else rv
|
|
111
|
+
if isinstance(stmt, str):
|
|
112
|
+
return await tgt.execute_command(stmt)
|
|
113
|
+
raise NotImplementedError(f"Unsupported stmt type: {type(stmt)}")
|
|
114
|
+
|
|
115
|
+
async def _close_impl(self) -> None:
|
|
116
|
+
if self._pipe is not None:
|
|
117
|
+
try:
|
|
118
|
+
reset = getattr(self._pipe, "reset", None)
|
|
119
|
+
if callable(reset):
|
|
120
|
+
rv = reset()
|
|
121
|
+
if inspect.isawaitable(rv):
|
|
122
|
+
await rv
|
|
123
|
+
finally:
|
|
124
|
+
self._pipe = None
|
|
125
|
+
if self._client is not None:
|
|
126
|
+
close = getattr(self._client, "close", None)
|
|
127
|
+
if callable(close):
|
|
128
|
+
rv = close()
|
|
129
|
+
if inspect.isawaitable(rv):
|
|
130
|
+
await rv
|
|
131
|
+
self._client = None
|
|
132
|
+
|
|
133
|
+
# ---- async marker override -------------------------------------------
|
|
134
|
+
async def run_sync(self, fn: Callable[[Any], Any]) -> Any:
|
|
135
|
+
"""Run a callback against the *underlying Redis client or pipeline*."""
|
|
136
|
+
rv = fn(self._target())
|
|
137
|
+
return await rv if inspect.isawaitable(rv) else rv
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tigrbl_engine_redis
|
|
3
|
+
Version: 0.1.1.dev2
|
|
4
|
+
Summary: Tigrbl engine plugin for Redis.
|
|
5
|
+
Author-email: Jacob Stewart <jacob@swarmauri.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Keywords: tigrbl,engine,plugin,redis,cache,database
|
|
8
|
+
Classifier: Development Status :: 1 - Planning
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Environment :: Plugins
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Topic :: Database
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Requires-Python: <3.13,>=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: tigrbl>=0.3.0.dev4
|
|
24
|
+
Requires-Dist: redis>=5.0.0
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# tigrbl_engine_redis
|
|
28
|
+
|
|
29
|
+
A Redis engine plugin for **tigrbl**. This package registers a new engine kind
|
|
30
|
+
`"redis"` that tigrbl auto-discovers via the `tigrbl.engine` entry-point group.
|
|
31
|
+
|
|
32
|
+
> The engine handle and session class in this package are implemented as
|
|
33
|
+
> **subclasses of tigrbl's first-class objects** (see notes below).
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install tigrbl_engine_redis
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
Once installed, refer to `kind="redis"` in your engine spec:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from tigrbl.engine.engine_spec import EngineSpec
|
|
47
|
+
|
|
48
|
+
spec = EngineSpec(kind="redis", mapping={"url": "redis://localhost:6379/0"})
|
|
49
|
+
eng, make_session = spec.build() # resolved through entry-points
|
|
50
|
+
s = make_session() # returns a RedisSession (TigrblSessionBase subclass)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### What this package provides
|
|
54
|
+
|
|
55
|
+
- `RedisEngine` — a thin subclass of `tigrbl.engine.Engine` to satisfy the
|
|
56
|
+
"first‑class engine" requirement. It stores connection parameters for
|
|
57
|
+
inspection; tigrbl keeps it as the provider's engine handle.
|
|
58
|
+
- `RedisSession` — a concrete subclass of `tigrbl.session.TigrblSessionBase`
|
|
59
|
+
that wraps a `redis.asyncio.Redis` client and implements the async
|
|
60
|
+
transaction‑aware Tigrbl Session ABC.
|
|
61
|
+
- `redis_engine()` — the entry‑point builder used by tigrbl to materialize
|
|
62
|
+
`(engine_handle, session_factory)`.
|
|
63
|
+
|
|
64
|
+
> tigrbl auto‑loads engine plugins on import (idempotent). See:
|
|
65
|
+
> `tigrbl.engine.__init__` (calls `load_engine_plugins()`), and
|
|
66
|
+
> `tigrbl.engine.plugins.load_engine_plugins()` which enumerates the `tigrbl.engine`
|
|
67
|
+
> entry‑point group and invokes each package's `register()` function.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/tigrbl_engine_redis/__init__.py
|
|
5
|
+
src/tigrbl_engine_redis/engine.py
|
|
6
|
+
src/tigrbl_engine_redis/session.py
|
|
7
|
+
src/tigrbl_engine_redis.egg-info/PKG-INFO
|
|
8
|
+
src/tigrbl_engine_redis.egg-info/SOURCES.txt
|
|
9
|
+
src/tigrbl_engine_redis.egg-info/dependency_links.txt
|
|
10
|
+
src/tigrbl_engine_redis.egg-info/entry_points.txt
|
|
11
|
+
src/tigrbl_engine_redis.egg-info/requires.txt
|
|
12
|
+
src/tigrbl_engine_redis.egg-info/top_level.txt
|
|
13
|
+
tests/test_smoke.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tigrbl_engine_redis
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_package_assets_present() -> None:
|
|
5
|
+
package_dir = Path(__file__).resolve().parents[1]
|
|
6
|
+
assert (package_dir / "README.md").is_file()
|
|
7
|
+
assert (package_dir / "LICENSE").is_file()
|
|
8
|
+
assert (package_dir / "pyproject.toml").is_file()
|