-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
176daa5
commit b949968
Showing
16 changed files
with
1,452 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: "2" | ||
|
||
build: | ||
os: "ubuntu-lts-latest" | ||
tools: | ||
python: "3.12" | ||
|
||
jobs: | ||
pre_build: | ||
- pip install poetry | ||
- poetry config virtualenvs.create false | ||
- poetry config virtualenvs.path $READTHEDOCS_VIRTUALENV_PATH | ||
- poetry install --with docs | ||
- deactivate | ||
|
||
sphinx: | ||
configuration: docs/source/conf.py | ||
|
||
formats: | ||
- epub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Version 0.0.15 | ||
-------------- | ||
|
||
Released 2024/09/07 | ||
|
||
- Added this documentation! | ||
|
||
- changed ``VALKEY_CLIENT_CLASS`` to ``BASE_CLIENT_CLASS`` for clarity | ||
|
||
- changed ``CLIENT_KWARGS`` to ``BASE_CLIENT_KWARGS`` for clarity | ||
|
||
- added some docstring to compressor classes | ||
|
||
- fixed some messages generated by autocomplete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line, and also | ||
# from the environment for the first two. | ||
SPHINXOPTS ?= | ||
SPHINXBUILD ?= sphinx-build | ||
SOURCEDIR = source | ||
BUILDDIR = build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@ECHO OFF | ||
|
||
pushd %~dp0 | ||
|
||
REM Command file for Sphinx documentation | ||
|
||
if "%SPHINXBUILD%" == "" ( | ||
set SPHINXBUILD=sphinx-build | ||
) | ||
set SOURCEDIR=source | ||
set BUILDDIR=build | ||
|
||
%SPHINXBUILD% >NUL 2>NUL | ||
if errorlevel 9009 ( | ||
echo. | ||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx | ||
echo.installed, then set the SPHINXBUILD environment variable to point | ||
echo.to the full path of the 'sphinx-build' executable. Alternatively you | ||
echo.may add the Sphinx directory to PATH. | ||
echo. | ||
echo.If you don't have Sphinx installed, grab it from | ||
echo.https://www.sphinx-doc.org/ | ||
exit /b 1 | ||
) | ||
|
||
if "%1" == "" goto help | ||
|
||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
goto end | ||
|
||
:help | ||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
|
||
:end | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
======= | ||
Changes | ||
======= | ||
|
||
.. include:: ../../CHANGES.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
======== | ||
Commands | ||
======== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
connection_pool_commands | ||
valkey_native_commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
========================== | ||
Access the connection pool | ||
========================== | ||
|
||
you can get the connection pool using this code: | ||
|
||
.. code-block:: python | ||
from django_valkey import get_valkey_connection | ||
r = get_valkey_connection("default") # use the name defined in ``CACHES`` settings | ||
connection_pool = r.connection_pool | ||
print(f"created connections so far: {connection_pool._created_connections}") | ||
this will verify how many connections the pool has opened. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
=============== | ||
valkey commands | ||
=============== | ||
|
||
if you need to use valkey operations, you can access the client as follows: | ||
|
||
.. code-block:: pycon | ||
>>> from django.core.cache import cache | ||
>>> cache.set("key", "value1", nx=True) | ||
True | ||
>>> cache.set("key", "value2", nx=True) | ||
False | ||
>>> cache.get("key") | ||
"value1" | ||
the list of supported commands is very long, if needed you can check the methods at ``django_valkey.cache.ValkeyCache``` | ||
|
||
Infinite timeout | ||
**************** | ||
|
||
django-valkey comes with infinite timeouts supported out of the box. And it | ||
behaves in the same way as django backend contract specifies: | ||
|
||
- ``timeout=0`` expires the value immediately. | ||
- ``timeout=None`` infinite timeout. | ||
|
||
.. code-block:: python | ||
cache.set("key", "value", timeout=None) | ||
Scan and Delete in bulk | ||
*********************** | ||
|
||
when you need to search for keys that have similar patterns, or delete them, you can use the helper methods that come with django-valkey: | ||
|
||
.. code-block:: pycon | ||
>>> from django.core.cache import cache | ||
>>> cache.keys("foo_*") | ||
["foo_1", "foo_2"] | ||
if you are looking for a very large amount of data, this is **not** suitable; instead use ``iter_keys``. | ||
this will return a generator that you can iterate over more efficiently. | ||
|
||
.. code-block:: python | ||
>>> from django.core.cache import cache | ||
>>> cache.iter_keys("foo_*") | ||
<generator object algo at 0x7ff432 | ||
>>> next(cache.iter_keys("foo_*)) | ||
'foo_1' | ||
>>> foos = cache.iter_keys("foo_*") | ||
>>> for i in foos: | ||
print(i) | ||
'foo_1' | ||
'foo_2' | ||
to delete keys, you should use ``delete_pattern`` which has the same glob pattern syntax as ``keys`` and returns the number of deleted keys. | ||
.. code-block:: pycon | ||
>>> from django.core.cache import cache | ||
>>> cache.delete_pattern("foo_*") | ||
2 | ||
To achieve the best performance while deleting many keys, you should set ``DJANGO_VALKEY_SCAN_ITERSIZE`` to a relatively | ||
high number (e.g., 100_000) by default in Django settings or pass it directly to the ``delete_pattern``. | ||
.. code-block:: pycon | ||
>>> from django.core.cache import cache | ||
>>> cache.delete_pattern("foo_*", itersize=100_000) | ||
Get ttl (time-to-live) from key | ||
******************************* | ||
with valkey you can access to ttl of any sorted key, to do so, django-valky exposes the ``ttl`` method. | ||
the ttl method returns: | ||
- `0` if key does not exists (or already expired). | ||
- ``None`` for keys that exist but does not have expiration. | ||
- the ttl value for any volatile key (any key that has expiration). | ||
.. code-block:: pycon | ||
>>> from django.core.cache import cache | ||
>>> cache.set("foo", "value", timeout=25) | ||
>>> cache.ttl("foo") | ||
25 | ||
>>> cache.ttl("not-exists") | ||
0 | ||
you can also access the ttl of any sorted key in milliseconds, use the ``pttl`` method to do so: | ||
.. code-block:: pycon | ||
>>> from django.core.cache import cache | ||
>>> cache.set("foo", "value", timeout=25) | ||
>>> cache.pttl("foo") | ||
25000 | ||
>>> cache.pttl("non-existent") | ||
0 | ||
Expire & Persist | ||
**************** | ||
in addition to the ``ttl`` and ``pttl`` methods, you can use the ``persist`` method so the key would have infinite timout: | ||
.. code-block:: pycon | ||
>>> cache.set("foo", "bar", timeout=22) | ||
>>> cache.ttl("foo") | ||
22 | ||
>>> cache.persist("foo") | ||
True | ||
>>> cache.ttl("foo") | ||
None | ||
you can also use ``expire`` to set a new timeout on the key: | ||
.. code-block:: pycon | ||
>>> cache.set("foo", "bar", timeout=22) | ||
>>> cache.expire("foo", timeout=5) | ||
True | ||
>>> cache.ttl("foo") | ||
5 | ||
The ``pexpire`` method can be used to set new timeout in millisecond precision: | ||
.. code-block:: pycon | ||
>>> cache.set("foo", "bar", timeout=22) | ||
>>> cache.pexpire("foo", timeout=5505) | ||
True | ||
>>> cache.pttl("foo") | ||
5505 | ||
The ``expire_at`` method can be used to make the key expire at a specific moment in time: | ||
.. code-block:: pycon | ||
>>> cache.set("foo", "bar", timeout=22) | ||
>>> cache.expire_at("foo", datetime.now() + timedelta(hours=1)) | ||
True | ||
>>> cache.ttl("foo") | ||
3600 | ||
The ``pexpire_at`` method can be used to make the key expire at a specific moment in time, with milliseconds precision: | ||
.. code-block:: pycon | ||
>>> cache.set("foo", "bar", timeout=22) | ||
>>> cache.pexpire_at("foo", datetime.now() + timedelta(milliseconds=900, hours=1)) | ||
True | ||
>>> cache.ttl("foo") | ||
3601 | ||
>>> cache.pttl("foo") | ||
3600900 | ||
Locks | ||
***** | ||
django-valkey also supports locks. | ||
valkey has distributed named locks which are identical to ``threading.Lock`` so you can useit as replacement. | ||
.. code-block:: python | ||
with cache.lock("somekey"): | ||
do_something()) | ||
Access Raw client | ||
***************** | ||
if the commands provided by django-valkey backend is not enough, or you want to use them in a different way, you can access the underlying client as follows: | ||
.. code-block:: pycon | ||
>>> from django-valkey import get_valkey_connection | ||
>>> con = get_valkey_connection("default") | ||
>>> con | ||
<valkey.client.Valkey object at 0x2dc4510> | ||
**Warning**: not all clients support this feature: | ||
ShardClient will raise an exception if tried to be used like this. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# For the full list of built-in configuration values, see the documentation: | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html | ||
|
||
# -- Project information ----------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information | ||
import sphinx_pdj_theme | ||
|
||
|
||
project = "django-valkey" | ||
copyright = "2024, amirreza" | ||
author = "amirreza" | ||
release = "0.0.15" | ||
|
||
# -- General configuration --------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration | ||
|
||
extensions = [] | ||
|
||
templates_path = ["_templates"] | ||
exclude_patterns = [] | ||
|
||
|
||
# -- Options for HTML output ------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output | ||
|
||
|
||
html_theme = "sphinx_pdj_theme" | ||
html_static_path = [sphinx_pdj_theme.get_html_theme_path()] | ||
|
||
html_sidebars = { | ||
"**": ["globaltoc.html", "sourcelink.html", "searchbox.html"], | ||
} |
Oops, something went wrong.