Skip to content

Commit

Permalink
Remove six dependency and adding host to conn_pool_args
Browse files Browse the repository at this point in the history
* Remove six dependency 
* Add support for param 'host'
* Add Daniel as author

Resolve #48, #50
  • Loading branch information
cunla committed Sep 27, 2022
1 parent 2468c56 commit 88c0d48
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
5 changes: 3 additions & 2 deletions fakeredis/_basefakesocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import weakref

import redis
import six

from . import _msgs as msgs
from ._commands import (
Expand Down Expand Up @@ -190,7 +189,9 @@ def _blocking(self, timeout, func):
return ret

def _name_to_func(self, name):
name = six.ensure_str(name, encoding='utf-8', errors='replace')
name = (name.decode(encoding='utf-8', errors='replace')
if isinstance(name, bytes)
else str(name).encode(encoding='utf-8', errors='replace'))
func_name = name.lower()
func = getattr(self, func_name, None)
if name.startswith('_') or not func or not hasattr(func, '_fakeredis_sig'):
Expand Down
7 changes: 4 additions & 3 deletions fakeredis/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ def __init__(self, *args, server=None, connected=True, version=7, **kwargs):
'connection_class': FakeConnection,
'server': server
}
conn_pool_args = [
conn_pool_args = {
'host',
'db',
# Ignoring because AUTH is not implemented
# 'username',
Expand All @@ -139,8 +140,8 @@ def __init__(self, *args, server=None, connected=True, version=7, **kwargs):
'retry_on_timeout',
'max_connections',
'health_check_interval',
'client_name'
]
'client_name',
}
for arg in conn_pool_args:
if arg in kwds:
kwargs[arg] = kwds[arg]
Expand Down
41 changes: 16 additions & 25 deletions poetry.lock

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

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ readme = "README.md"
keywords = ["redis", "rq", "django-rq", "rq-scheduler"]
authors = [
"James Saryerwinnie <js@jamesls.com>",
"Bruce Merry <bmerry@ska.ac.za>"
"Bruce Merry <bmerry@ska.ac.za>",
"Daniel Moran <daniel.maruani@gmail.com>"
]
maintainers = [
"Daniel Moran <daniel.maruani@gmail.com>"
Expand All @@ -39,7 +40,6 @@ repository = "https://github.com/cunla/fakeredis-py"
[tool.poetry.dependencies]
python = "^3.7"
redis = "<4.4"
six = "^1.16.0"
sortedcontainers = "^2.4.0"
lupa = { version = "^1.13", optional = true }
aioredis = { version = "^2.0.1", optional = true }
Expand Down
5 changes: 5 additions & 0 deletions test/test_init_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def test_singleton(self):
assert 'bar' in r4
assert 'bar' not in r1

def test_host_init_arg(self):
db = fakeredis.FakeStrictRedis(host='localhost')
db.set('foo', 'bar')
assert db.get('foo') == b'bar'

def test_from_url(self):
db = fakeredis.FakeStrictRedis.from_url(
'redis://localhost:6379/0')
Expand Down

0 comments on commit 88c0d48

Please sign in to comment.