Skip to content

Commit 5a2e26d

Browse files
committed
Connection URLs must have a valid scheme.
Fixes #969 Fixes #961
1 parent 04ddd34 commit 5a2e26d

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
* 3.1.0 (in development)
2+
* Connection URLs must have one of the following schemes:
3+
redis://, rediss://, unix://. Thanks @jdupl123. #961/#969
24
* Fixed an issue with retry_on_timeout logic that caused some TimeoutErrors
35
to be retried. Thanks Aaron Yang. #1022/#1023
46
* Added support for SNI for SSL. Thanks @oridistor and Roey Prat. #1087

redis/connection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,15 +885,15 @@ def from_url(cls, url, db=None, decode_components=False, **kwargs):
885885
path = url.path
886886
hostname = url.hostname
887887

888-
# We only support redis:// and unix:// schemes.
888+
# We only support redis://, rediss:// and unix:// schemes.
889889
if url.scheme == 'unix':
890890
url_options.update({
891891
'password': password,
892892
'path': path,
893893
'connection_class': UnixDomainSocketConnection,
894894
})
895895

896-
else:
896+
elif url.scheme in ('redis', 'rediss'):
897897
url_options.update({
898898
'host': hostname,
899899
'port': int(url.port or 6379),
@@ -910,6 +910,10 @@ def from_url(cls, url, db=None, decode_components=False, **kwargs):
910910

911911
if url.scheme == 'rediss':
912912
url_options['connection_class'] = SSLConnection
913+
else:
914+
valid_schemes = ', '.join(('redis://', 'rediss://', 'unix://'))
915+
raise ValueError('Redis URL must specify one of the following'
916+
'schemes (%s)' % valid_schemes)
913917

914918
# last shot at the db value
915919
url_options['db'] = int(url_options.get('db', db or 0))

tests/test_connection_pool.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ def test_client_creates_connection_pool(self):
308308
'password': None,
309309
}
310310

311+
def test_invalid_scheme_raises_error(self):
312+
with pytest.raises(ValueError):
313+
redis.ConnectionPool.from_url('localhost')
314+
311315

312316
class TestConnectionPoolUnixSocketURLParsing(object):
313317
def test_defaults(self):

0 commit comments

Comments
 (0)