Skip to content

Commit 966004d

Browse files
authored
Import Redis cache backend from defunkt kinto-redis (#3638)
* Import Redis cache backend from defunkt kinto-redis * Pin setuptools * pin setuptools in docs too * Fix redis import
1 parent 15fd62e commit 966004d

File tree

19 files changed

+274
-17
lines changed

19 files changed

+274
-17
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ jobs:
6666
--health-retries 5
6767
ports:
6868
- 11211:11211
69+
redis:
70+
image: redis
71+
options: >-
72+
--health-cmd "redis-cli ping"
73+
--health-interval 10s
74+
--health-timeout 5s
75+
--health-retries 5
76+
ports:
77+
- 6379:6379
6978

7079
steps:
7180
- uses: actions/checkout@v6

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ COPY constraints.txt pyproject.toml ./
1717
RUN pip install --upgrade pip && pip install -r constraints.txt
1818
COPY kinto/ kinto/
1919
RUN cp -r /kinto-admin/kinto/plugins/admin/build kinto/plugins/admin/
20-
RUN pip install ".[postgresql,memcached,monitoring]" -c constraints.txt && pip install kinto-attachment kinto-emailer httpie
20+
RUN pip install ".[postgresql,memcached,redis,monitoring]" -c constraints.txt && pip install kinto-attachment kinto-emailer httpie
2121

2222
FROM python:3.10-slim-bullseye
2323
RUN groupadd --gid 10001 app && \

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ install-postgres: $(INSTALL_STAMP) $(DEV_STAMP) ## install postgresql support
4242
install-memcached: $(INSTALL_STAMP) $(DEV_STAMP) ## install memcached support
4343
$(VENV)/bin/pip install -Ue ".[memcached]" -c constraints.txt
4444

45+
install-redis: $(INSTALL_STAMP) $(DEV_STAMP) ## install redis support
46+
$(VENV)/bin/pip install -Ue ".[redis]" -c constraints.txt
47+
4548
install-dev: $(INSTALL_STAMP) $(DEV_STAMP) ## install dependencies and everything needed to run tests
4649
$(DEV_STAMP): $(PYTHON) constraints.txt
47-
$(VENV)/bin/pip install -Ue ".[dev,test,monitoring,postgresql,memcached]" -c constraints.txt
50+
$(VENV)/bin/pip install -Ue ".[dev,test,monitoring,postgresql,memcached,redis]" -c constraints.txt
4851
touch $(DEV_STAMP)
4952

5053
install-docs: $(DOC_STAMP) ## install dependencies to build the docs
@@ -87,8 +90,10 @@ tests-raw: version-file install-dev
8790
.PHONY: test-deps
8891
test-deps:
8992
docker pull memcached
93+
docker pull redis
9094
docker pull postgres
9195
docker run -p 11211:11211 --name kinto-memcached -d memcached || echo "cannot start memcached, already exists?"
96+
docker run -p 6379:6379 --name kinto-redis -d redis || echo "cannot start redis, already exists?"
9297
docker run -p 5432:5432 --name kinto-postgres -e POSTGRES_PASSWORD=postgres -d postgres || echo "cannot start postgres, already exists?"
9398
sleep 2
9499
PGPASSWORD=postgres psql -c "CREATE DATABASE testdb ENCODING 'UTF8' TEMPLATE template0;" -U postgres -h localhost
@@ -131,6 +136,7 @@ clean: ## remove built files and start fresh
131136
rm -fr kinto/plugins/admin/build/ kinto/plugins/admin/node_modules/
132137
docker rm -f kinto-memcached || echo ""
133138
docker rm -f kinto-postgres || echo ""
139+
docker rm -f kinto-redis || echo ""
134140

135141
docs: install-docs ## build the docs
136142
$(VENV)/bin/sphinx-build -a -W -n -b html -d $(SPHINX_BUILDDIR)/doctrees docs $(SPHINX_BUILDDIR)/html

constraints.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ python-rapidjson
1616
# optional dependencies
1717
# memcached
1818
python-memcached
19+
# redis
20+
redis
1921
# postgresql
2022
SQLAlchemy < 3
2123
psycopg2-binary
@@ -36,3 +38,4 @@ webtest
3638
# dev
3739
build
3840
ruff
41+
setuptools<82.0

constraints.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#
2-
# This file is autogenerated by pip-compile with Python 3.12
2+
# This file is autogenerated by pip-compile with Python 3.14
33
# by the following command:
44
#
5-
# pip-compile --output-file=constraints.txt --strip-extras constraints.in
5+
# pip-compile --allow-unsafe --output-file=constraints.txt --strip-extras constraints.in
66
#
77
arrow==1.3.0
88
# via isoduration
@@ -37,9 +37,7 @@ execnet==2.0.2
3737
fqdn==1.5.1
3838
# via jsonschema
3939
greenlet==3.1.1
40-
# via
41-
# playwright
42-
# sqlalchemy
40+
# via playwright
4341
hupper==1.12
4442
# via pyramid
4543
idna==3.7
@@ -139,6 +137,8 @@ pyyaml==6.0.1
139137
# via
140138
# bravado-core
141139
# swagger-spec-validator
140+
redis==7.1.0
141+
# via -r constraints.in
142142
referencing==0.32.1
143143
# via
144144
# jsonschema
@@ -228,4 +228,9 @@ zope-sqlalchemy==4.1
228228
# via -r constraints.in
229229

230230
# The following packages are considered to be unsafe in a requirements file:
231-
# setuptools
231+
setuptools==81.0.0
232+
# via
233+
# -r constraints.in
234+
# pyramid
235+
# zope-deprecation
236+
# zope-interface

docs/configuration/settings.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ You would need to install the memcached dependencies: ``pip install kinto[memcac
190190
kinto.cache_backend = kinto.core.cache.memcached
191191
kinto.cache_hosts = 127.0.0.1:11211 127.0.0.2:11211
192192
193+
For **Redis**
194+
195+
You would need to install the Redis dependencies: ``pip install kinto[redis]``
196+
197+
.. code-block:: ini
198+
199+
kinto.cache_backend = kinto.core.cache.redis
200+
# kinto.cache_url = redis://127.0.0.1:6379/0
201+
202+
193203
Permissions
194204
:::::::::::
195205

docs/core/cache.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Memcached
2727

2828
.. autoclass:: kinto.core.cache.memcached.Cache
2929

30+
Redis
31+
=====
32+
33+
.. autoclass:: kinto.core.cache.redis.Cache
3034

3135
API
3236
===

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ webtest==3.0.7
99
pyramid==2.0.2
1010
python-rapidjson==1.23
1111
SQLAlchemy==2.0.46
12+
setuptools<82.0

kinto/__main__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def main(args=None):
8383
)
8484
subparser.add_argument(
8585
"--cache-backend",
86-
help="{memory,postgresql,memcached}",
86+
help="{memory,postgresql,memcached,redis}",
8787
dest="cache-backend",
8888
required=False,
8989
default=None,
@@ -176,13 +176,14 @@ def main(args=None):
176176
while True:
177177
prompt = (
178178
"Select the cache backend you would like to use: "
179-
"(1 - postgresql, 2 - memcached, default - memory) "
179+
"(1 - postgresql, 2 - memcached, 3 - redis, default - memory) "
180180
)
181181
answer = input(prompt).strip()
182182
try:
183183
cache_backends = {
184184
"1": "postgresql",
185185
"2": "memcached",
186+
"3": "redis",
186187
"": "memory",
187188
}
188189
cache_backend = cache_backends[answer]
@@ -205,6 +206,11 @@ def main(args=None):
205206
import memcache # NOQA
206207
except ImportError:
207208
subprocess.check_call([sys.executable, "-m", "pip", "install", "kinto[memcached]"])
209+
elif cache_backend == "redis":
210+
try:
211+
import redis # NOQA
212+
except ImportError:
213+
subprocess.check_call([sys.executable, "-m", "pip", "install", "kinto[redis]"])
208214

209215
elif which_command == "migrate":
210216
dry_run = parsed_args["dry_run"]

kinto/config/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def render_template(template, destination, **kwargs):
5454
"cache_backend": "kinto.core.cache.memcached",
5555
"cache_url": "127.0.0.1:11211 127.0.0.2:11211",
5656
},
57+
"redis": {"cache_backend": "kinto.core.cache.redis", "cache_url": "redis://127.0.0.1/0"},
5758
"memory": {"cache_backend": "kinto.core.cache.memory", "cache_url": ""},
5859
}
5960

0 commit comments

Comments
 (0)