Skip to content

Commit

Permalink
Release 1.8
Browse files Browse the repository at this point in the history
* Refactor tests
* Restore python3.7 support
* Improve readme

Fix #21 #17 #22
  • Loading branch information
cunla authored May 27, 2022
1 parent 5372299 commit 3125429
Show file tree
Hide file tree
Showing 16 changed files with 969 additions and 1,018 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
redis-py: ["4.1.2", "4.3.1"]
python-version: [ "3.7", "3.8", "3.9", "3.10" ]
redis-py: [ "4.1.2", "4.3.1" ]
include:
- python-version: "3.10"
redis-py: "2.10.6"
Expand Down Expand Up @@ -63,16 +63,21 @@ jobs:
if: ${{ matrix.lupa }}
run: |
poetry run pip install lupa==${{ matrix.lupa }}
- name: Test import
run: |
poetry build
pip install dist/fakeredis-*.tar.gz
python -c 'import fakeredis'
- name: Test with coverage
if: ${{ matrix.coverage == 'yes' }}
run: |
run: |
poetry run flake8 fakeredis/
poetry run pytest -v --cov=fakeredis --cov-branch
poetry run coverage json
echo "COVERAGE=$(jq '.totals.percent_covered_display|tonumber' coverage.json)" >> $GITHUB_ENV
- name: Test without coverage
if: ${{ matrix.coverage != 'yes' }}
run: |
run: |
poetry run pytest -v
- name: Create coverage badge
if: ${{ matrix.coverage == 'yes' && github.event_name == 'push' }}
Expand Down
121 changes: 61 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ fakeredis: A fake version of a redis-py

![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/cunla/b756396efb895f0e34558c980f1ca0c7/raw/fakeredis-py.json)

- [fakeredis: A fake version of a redis-py](#fakeredis--a-fake-version-of-a-redis-py)
- [How to Use](#how-to-use)
- [Support for aioredis](#support-for-aioredis)
* [aioredis 1.x](#aioredis-1x)
* [aioredis 2.x](#aioredis-2x)
- [Other limitations](#other-limitations)
- [Contributing](#contributing)
- [Support for redis-py <4.2 with aioredis](#support-for-redis-py--42-with-aioredis)
+ [aioredis 1.x](#aioredis-1x)
+ [aioredis 2.x](#aioredis-2x)
- [Running the Tests](#running-the-tests)
- [Contributing](#contributing)
- [Alternatives](#alternatives)


fakeredis is a pure-Python implementation of the redis-py python client
that simulates talking to a redis server. This was created for a single
purpose: **to write unittests**. Setting up redis is not hard, but
Expand Down Expand Up @@ -89,55 +91,6 @@ Fakeredis implements the same interface as `redis-py`, the
popular redis client for python, and models the responses
of redis 6.2 (although most new features are not supported).

# Support for aioredis

You can also use fakeredis to mock out [aioredis](https://aioredis.readthedocs.io/). This is a much newer
addition to fakeredis (added in 1.4.0) with less testing, so your mileage may
vary. Both version 1 and version 2 (which have very different APIs) are
supported. The API provided by fakeredis depends on the version of aioredis that is
installed.

aioredis 1.x
------------

Example:

```
>>> import fakeredis.aioredis
>>> r = await fakeredis.aioredis.create_redis_pool()
>>> await r.set('foo', 'bar')
True
>>> await r.get('foo')
b'bar'
```

You can pass a `FakeServer` as the first argument to `create_redis` or
`create_redis_pool` to share state (you can even share state with a
`fakeredis.FakeRedis`). It should even be safe to do this state sharing between
threads (as long as each connection/pool is only used in one thread).

It is highly recommended that you only use the aioredis support with
Python 3.5.3 or higher. Earlier versions will not work correctly with
non-default event loops.

aioredis 2.x
------------

Example:

```
>>> import fakeredis.aioredis
>>> r = fakeredis.aioredis.FakeRedis()
>>> await r.set('foo', 'bar')
True
>>> await r.get('foo')
b'bar'
```

The support is essentially the same as for redis-py e.g., you can pass a
`server` keyword argument to the `FakeRedis` constructor.


# Other limitations

Apart from unimplemented commands, there are a number of cases where fakeredis
Expand Down Expand Up @@ -180,14 +133,53 @@ bugs in Github.
**WARNING**: Do not use RESTORE with untrusted data, as a malicious pickle
can execute arbitrary code.

# Contributing
Contributions are welcome. Please see the
[contributing guide](.github/CONTRIBUTING.md) for more details.
The maintainer generally has very little time to work on fakeredis, so the
best way to get a bug fixed is to contribute a pull request.
# Support for redis-py <4.2 with aioredis

If you'd like to help out, you can start with any of the issues
labeled with `Help wanted`.
Aioredis is now in redis-py 4.2.0. But support is maintained until fakeredis 2 for older version of redis-py.

You can also use fakeredis to mock out [aioredis](https://aioredis.readthedocs.io/). This is a much newer
addition to fakeredis (added in 1.4.0) with less testing, so your mileage may
vary. Both version 1 and version 2 (which have very different APIs) are
supported. The API provided by fakeredis depends on the version of aioredis that is
installed.

### aioredis 1.x

Example:

```
>>> import fakeredis.aioredis
>>> r = await fakeredis.aioredis.create_redis_pool()
>>> await r.set('foo', 'bar')
True
>>> await r.get('foo')
b'bar'
```

You can pass a `FakeServer` as the first argument to `create_redis` or
`create_redis_pool` to share state (you can even share state with a
`fakeredis.FakeRedis`). It should even be safe to do this state sharing between
threads (as long as each connection/pool is only used in one thread).

It is highly recommended that you only use the aioredis support with
Python 3.5.3 or higher. Earlier versions will not work correctly with
non-default event loops.

### aioredis 2.x

Example:

```
>>> import fakeredis.aioredis
>>> r = fakeredis.aioredis.FakeRedis()
>>> await r.set('foo', 'bar')
True
>>> await r.get('foo')
b'bar'
```

The support is essentially the same as for redis-py e.g., you can pass a
`server` keyword argument to the `FakeRedis` constructor.


# Running the Tests
Expand Down Expand Up @@ -235,6 +227,15 @@ they have all been tagged as 'slow' so you can skip them by running::
poetry run pytest -m "not slow"
```

# Contributing
Contributions are welcome. Please see the
[contributing guide](.github/CONTRIBUTING.md) for more details.
The maintainer generally has very little time to work on fakeredis, so the
best way to get a bug fixed is to contribute a pull request.

If you'd like to help out, you can start with any of the issues
labeled with `Help wanted`.

# Alternatives

Consider using [redislite](https://redislite.readthedocs.io/en/latest/) instead of fakeredis.
Expand Down
11 changes: 6 additions & 5 deletions fakeredis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ._server import FakeServer, FakeRedis, FakeStrictRedis, FakeConnection # noqa: F401
from ._server import FakeServer, FakeRedis, FakeStrictRedis, FakeConnection # noqa: F401


import importlib.metadata

__version__ = importlib.metadata.version('fakeredis')
try:
from importlib import metadata
except ImportError: # for Python<3.8
import importlib_metadata as metadata
__version__ = metadata.version("fakeredis")
35 changes: 24 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name = "fakeredis"
packages = [
{ include = "fakeredis" },
]
version = "1.7.6.1"
version = "1.8"
description = "Fake implementation of redis API for testing purposes."
readme = "README.md"
keywords = ["redis", "rq", "django-rq", "rq-scheduler"]
Expand All @@ -27,6 +27,7 @@ classifiers = [
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
Expand All @@ -36,12 +37,12 @@ homepage = "https://github.com/dsoftwareinc/fakeredis-py"
repository = "https://github.com/dsoftwareinc/fakeredis-py"

[tool.poetry.dependencies]
python = "^3.8"
lupa = { version = "^1.13", optional = true }
python = "^3.7"
redis = "<=4.3.1"
aioredis = { version = "^2.0.1", optional = true }
six = "^1.16.0"
sortedcontainers = "^2.4.0"
lupa = { version = "^1.13", optional = true }
aioredis = { version = "^2.0.1", optional = true }

[tool.poetry.extras]
lua = ["lupa"]
Expand All @@ -61,4 +62,15 @@ pytest-mock = "^3.7.0"
flake8 = "^4.0.1"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/dsoftwareinc/fakeredis-py/issues"
"Bug Tracker" = "https://github.com/dsoftwareinc/fakeredis-py/issues"

[tool.pytest.ini_options]
markers = [
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
"fake: run tests only with fake redis",
"real: run tests with a locally running real Redis server",
"disconnected",
"min_server",
"decode_responses",
]
asyncio_mode="strict"
8 changes: 0 additions & 8 deletions pytest.ini

This file was deleted.

Loading

0 comments on commit 3125429

Please sign in to comment.