Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

Commit 840cb6f

Browse files
committed
Merge branch 'unstable'
2 parents 4a499a9 + 9c1b763 commit 840cb6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2731
-1322
lines changed

.travis.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
sudo: false
2+
dist: xenial
23
language: python
4+
cache: pip
35
python:
46
- "2.7"
5-
- "3.3"
67
- "3.4"
78
- "3.5"
8-
- "3.6-dev"
9+
- "3.6"
910
- "nightly"
1011
services:
1112
- redis-server
@@ -14,9 +15,12 @@ install:
1415
- "if [[ $REDIS_VERSION == '3.2' ]]; then REDIS_VERSION=3.2 make redis-install; fi"
1516
- "if [[ $REDIS_VERSION == '4.0' ]]; then REDIS_VERSION=4.0 make redis-install; fi"
1617
- "if [[ $REDIS_VERSION == '5.0' ]]; then REDIS_VERSION=5.0 make redis-install; fi"
18+
- "if [[ $TEST_PYCODESTYLE == '1' ]]; then pip install pycodestyle; fi"
1719
- pip install -r dev-requirements.txt
1820
- pip install -e .
1921
- "if [[ $HIREDIS == '1' ]]; then pip install hiredis; fi"
22+
- "pip freeze | grep redis"
23+
- "pip freeze"
2024
env:
2125
# Redis 3.0 & HIREDIS
2226
- HIREDIS=0 REDIS_VERSION=3.0
@@ -30,14 +34,30 @@ env:
3034
# Redis 5.0 & HIREDIS
3135
- HIREDIS=0 REDIS_VERSION=5.0
3236
- HIREDIS=1 REDIS_VERSION=5.0
33-
script:
37+
script:
3438
- make start
3539
- coverage erase
3640
- coverage run --source rediscluster -p -m py.test
41+
- py.test
3742
- make stop
38-
after_success:
43+
after_success:
3944
- coverage combine
4045
- coveralls
46+
- "if [[ $TEST_PYCODESTYLE == '1' ]]; then pycodestyle --repeat --show-source --exclude=.venv,.tox,dist,docs,build,*.egg,redis_install .; fi"
4147
matrix:
4248
allow_failures:
4349
- python: "nightly"
50+
- python: 2.7
51+
env: TEST_PYCODESTYLE=1
52+
- python: 3.6
53+
env: TEST_PYCODESTYLE=1
54+
# python 3.7 has to be specified manually in the matrix
55+
# https://github.com/travis-ci/travis-ci/issues/9815
56+
- python: 3.7
57+
dist: xenial
58+
sudo: true
59+
env: TEST_HIREDIS=0
60+
- python: 3.7
61+
dist: xenial
62+
sudo: true
63+
env: TEST_HIREDIS=1

LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2014-2019 Johan Andersson
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ ifndef REDIS_TRIB_RB
216216
endif
217217

218218
ifndef REDIS_VERSION
219-
REDIS_VERSION=4.0.10
219+
REDIS_VERSION=5.0.5
220220
endif
221221

222222
export REDIS_CLUSTER_NODE1_CONF
@@ -378,16 +378,16 @@ redis-install:
378378

379379
benchmark:
380380
@echo ""
381-
@echo " -- Running Simple benchmark with StrictRedis lib and non cluster server --"
381+
@echo " -- Running Simple benchmark with Redis lib and non cluster server --"
382382
python benchmarks/simple.py --port 7007 --timeit --nocluster
383383
@echo ""
384-
@echo " -- Running Simple benchmark with StrictRedisCluster lib and cluster server --"
384+
@echo " -- Running Simple benchmark with RedisCluster lib and cluster server --"
385385
python benchmarks/simple.py --port 7001 --timeit
386386
@echo ""
387-
@echo " -- Running Simple benchmark with pipelines & StrictRedis lib and non cluster server --"
387+
@echo " -- Running Simple benchmark with pipelines & Redis lib and non cluster server --"
388388
python benchmarks/simple.py --port 7007 --timeit --pipeline --nocluster
389389
@echo ""
390-
@echo " -- Running Simple benchmark with StrictRedisCluster lib and cluster server"
390+
@echo " -- Running Simple benchmark with RedisCluster lib and cluster server"
391391
python benchmarks/simple.py --port 7001 --timeit --pipeline
392392

393393
ptp:

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ This client provides a client for redis cluster that was added in redis 3.0.
44

55
This project is a port of `redis-rb-cluster` by antirez, with alot of added functionality. The original source can be found at https://github.com/antirez/redis-rb-cluster
66

7-
Gitter chat room: [![Gitter](https://badges.gitter.im/Grokzen/redis-py-cluster.svg)](https://gitter.im/Grokzen/redis-py-cluster?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
8-
97
[![Build Status](https://travis-ci.org/Grokzen/redis-py-cluster.svg?branch=master)](https://travis-ci.org/Grokzen/redis-py-cluster) [![Coverage Status](https://coveralls.io/repos/Grokzen/redis-py-cluster/badge.png)](https://coveralls.io/r/Grokzen/redis-py-cluster) [![PyPI version](https://badge.fury.io/py/redis-py-cluster.svg)](http://badge.fury.io/py/redis-py-cluster)
108

119

@@ -30,19 +28,21 @@ Latest stable release from pypi
3028
$ pip install redis-py-cluster
3129
```
3230

31+
This major version of `redis-py-cluster` supports `redis-py>=3.0.0,<3.1.0`.
32+
3333

3434

3535
## Usage example
3636

3737
Small sample script that shows how to get started with RedisCluster. It can also be found in [examples/basic.py](examples/basic.py)
3838

3939
```python
40-
>>> from rediscluster import StrictRedisCluster
40+
>>> from rediscluster import RedisCluster
4141

4242
>>> # Requires at least one node for cluster discovery. Multiple nodes is recommended.
4343
>>> startup_nodes = [{"host": "127.0.0.1", "port": "7000"}]
4444

45-
>>> rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)
45+
>>> rc = RedisCluster(startup_nodes=startup_nodes, decode_responses=True)
4646

4747
>>> rc.set("foo", "bar")
4848
True
@@ -54,7 +54,7 @@ True
5454

5555
## License & Authors
5656

57-
Copyright (c) 2013-2018 Johan Andersson
57+
Copyright (c) 2013-2019 Johan Andersson
5858

5959
MIT (See docs/License.txt file)
6060

benchmarks/simple.py

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
# -*- coding: utf-8 -*-
1+
#!/usr/bin/env python3
2+
# -*- coding:utf-8 -*-
3+
"""
4+
Usage:
5+
redis-cluster-benchmark.py [--host <ip>] [-p <port>] [-n <request>] [-c <concurrent>] [--nocluster] [--timeit] [--pipeline] [--resetlastkey] [-h] [--version]
26
3-
# python std lib
4-
import time
7+
Options:
8+
--host <ip> Redis server to test against [default: 127.0.0.1]
9+
-p <port> Port on redis server [default: 7000]
10+
-n <request> Request number [default: 100000]
11+
-c <concurrent> Concurrent client number [default: 1]
12+
--nocluster If flag is set then Redis will be used instead of cluster lib
13+
--timeit Run a mini benchmark to test performance
14+
--pipeline Only usable with --timeit flag. Runs SET/GET inside pipelines.
15+
--resetlastkey Reset __last__ key
16+
-h --help Output this help and exit
17+
--version Output version and exit
18+
"""
519

20+
import time
21+
from multiprocessing import Process
622
# 3rd party imports
723
from docopt import docopt
8-
from redis._compat import xrange
924

1025

1126
def loop(rc, reset_last_key=None):
@@ -25,7 +40,7 @@ def loop(rc, reset_last_key=None):
2540
print("error {0}".format(e))
2641
time.sleep(1)
2742

28-
for i in xrange(last, 1000000000): # noqa
43+
for i in range(last, 1000000000): # noqa
2944
try:
3045
print("SET foo{0} {1}".format(i, i))
3146
rc.set("foo{0}".format(i), i)
@@ -38,78 +53,54 @@ def loop(rc, reset_last_key=None):
3853
time.sleep(0.05)
3954

4055

41-
def timeit(rc, itterations=50000):
56+
def timeit(rc, num):
4257
"""
4358
Time how long it take to run a number of set/get:s
4459
"""
45-
t0 = time.time()
46-
for i in xrange(0, itterations): # noqa
60+
for i in range(0, num//2): # noqa
4761
s = "foo{0}".format(i)
4862
rc.set(s, i)
4963
rc.get(s)
5064

51-
t1 = time.time() - t0
52-
print("{0}k SET/GET operations took: {1} seconds... {2} operations per second".format((itterations / 1000) * 2, t1, (itterations / t1) * 2))
5365

54-
55-
def timeit_pipeline(rc, itterations=50000):
66+
def timeit_pipeline(rc, num):
5667
"""
5768
Time how long it takes to run a number of set/get:s inside a cluster pipeline
5869
"""
59-
t0 = time.time()
60-
for i in xrange(0, itterations): # noqa
70+
for i in range(0, num//2): # noqa
6171
s = "foo{0}".format(i)
62-
6372
p = rc.pipeline()
6473
p.set(s, i)
6574
p.get(s)
6675
p.execute()
6776

68-
t1 = time.time() - t0
69-
print("{0}k SET/GET operations inside pipelines took: {1} seconds... {2} operations per second".format(
70-
(itterations / 1000) * 2, t1, (itterations / t1) * 2)
71-
)
72-
7377

7478
if __name__ == "__main__":
75-
__docopt__ = """
76-
Usage:
77-
simple [--host IP] [--port PORT] [--nocluster] [--timeit] [--pipeline] [--resetlastkey] [-h] [--version]
78-
79-
Options:
80-
--nocluster If flag is set then StrictRedis will be used instead of cluster lib
81-
--host IP Redis server to test against [default: 127.0.0.1]
82-
--port PORT Port on redis server [default: 7000]
83-
--timeit run a mini benchmark to test performance
84-
--pipeline Only usable with --timeit flag. Runs SET/GET inside pipelines.
85-
--resetlastkey reset __last__ key
86-
-h --help show this help and exit
87-
-v --version show version and exit
88-
"""
89-
90-
args = docopt(__docopt__, version="0.3.0")
91-
92-
startup_nodes = [{"host": args["--host"], "port": args["--port"]}]
79+
args = docopt(__doc__, version="0.3.1")
80+
startup_nodes = [{"host": args['--host'], "port": args['-p']}]
9381

9482
if not args["--nocluster"]:
95-
from rediscluster import StrictRedisCluster
96-
rc = StrictRedisCluster(startup_nodes=startup_nodes, max_connections=32, socket_timeout=0.1, decode_responses=True)
83+
from rediscluster import RedisCluster
84+
rc = RedisCluster(startup_nodes=startup_nodes, max_connections=32, socket_timeout=0.1, decode_responses=True)
9785
else:
98-
from redis import StrictRedis
99-
rc = StrictRedis(host=args["--host"], port=args["--port"], socket_timeout=0.1, decode_responses=True)
100-
101-
if args["--timeit"]:
102-
test_itterstions = [
103-
5000,
104-
10000,
105-
20000,
106-
]
107-
108-
if args["--pipeline"]:
109-
for itterations in test_itterstions:
110-
timeit_pipeline(rc, itterations=itterations)
86+
from redis import Redis
87+
rc = Redis(host=args["--host"], port=args["-p"], socket_timeout=0.1, decode_responses=True)
88+
# create specified number processes
89+
processes = []
90+
single_request = int(args["-n"]) // int(args["-c"])
91+
for j in range(int(args["-c"])):
92+
if args["--timeit"]:
93+
if args["--pipeline"]:
94+
p = Process(target=timeit_pipeline, args=(rc, single_request))
95+
else:
96+
p = Process(target=timeit, args=(rc, single_request))
11197
else:
112-
for itterations in test_itterstions:
113-
timeit(rc, itterations=itterations)
114-
else:
115-
loop(rc, reset_last_key=args["--resetlastkey"])
98+
p = Process(target=loop, args=(rc, args["--resetlastkey"]))
99+
processes.append(p)
100+
t1 = time.time()
101+
for p in processes:
102+
p.start()
103+
for p in processes:
104+
p.join()
105+
t2 = time.time() - t1
106+
print("Tested {0}k SET & GET (each 50%) operations took: {1} seconds... {2} operations per second".format(int(args["-n"]) / 1000, t2, int(args["-n"]) / t2 * 2))

dev-requirements.txt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
-r requirements.txt
22

3-
coverage>=4.0,<5.0
4-
pytest>=2.8.3,<4.0.0
5-
testfixtures>=4.5.0,<5.5.0
6-
mock>=1.3.0,<2.1.0
7-
docopt>=0.6.2,<1.0.0
8-
tox>=2.2.0,<3.0.0
9-
python-coveralls>=2.5.0,<3.0.0
10-
ptpdb>=0.16,<1.0
11-
ptpython>=0.31,<1.0
3+
coverage
4+
pytest
5+
testfixtures
6+
mock
7+
docopt
8+
tox
9+
python-coveralls
10+
ptpdb
11+
ptpython
12+
pysnooper

docs/License.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014-2016 Johan Andersson
1+
Copyright (c) 2014-2019 Johan Andersson
22

33
Permission is hereby granted, free of charge, to any person
44
obtaining a copy of this software and associated documentation

docs/benchmarks.rst

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ These are a few benchmarks that are designed to test specific parts of the code
88
Setup benchmarks
99
----------------
1010

11-
Before running any benchmark you should install this lib in editable mode inside a virtualenv so it can import `StrictRedisCluster` lib.
11+
Before running any benchmark you should install this lib in editable mode inside a virtualenv so it can import `RedisCluster` lib.
1212

1313
Install with
1414

1515
.. code-block:: bash
16-
16+
1717
pip install -e .
1818
1919
You also need a few redis servers to test against. You must have one cluster with at least one node on port `7001` and you must also have a non-clustered server on port `7007`.
@@ -42,26 +42,18 @@ Example output and comparison of different runmodes
4242

4343
.. code-block::
4444
45-
-- Running Simple benchmark with StrictRedis lib and non cluster server --
46-
python benchmarks/simple.py --port 7007 --timeit --nocluster
47-
10.0k SET/GET operations took: 0.9711470603942871 seconds... 10297.10165208139 operations per second
48-
20.0k SET/GET operations took: 1.9136295318603516 seconds... 10451.343725113202 operations per second
49-
40.0k SET/GET operations took: 3.8409764766693115 seconds... 10414.018477584079 operations per second
50-
51-
-- Running Simple benchmark with StrictRedisCluster lib and cluster server --
52-
python benchmarks/simple.py --port 7001 --timeit
53-
10.0k SET/GET operations took: 0.760077714920044 seconds... 13156.549394494412 operations per second
54-
20.0k SET/GET operations took: 1.5251967906951904 seconds... 13113.061948474155 operations per second
55-
40.0k SET/GET operations took: 3.05112361907959 seconds... 13109.924406165655 operations per second
56-
57-
-- Running Simple benchmark with pipelines & StrictRedis lib and non cluster server --
58-
python benchmarks/simple.py --port 7007 --timeit --pipeline --nocluster
59-
10.0k SET/GET operations inside pipelines took: 0.8831894397735596 seconds... 11322.599149921782 operations per second
60-
20.0k SET/GET operations inside pipelines took: 1.6283915042877197 seconds... 12282.058674058404 operations per second
61-
40.0k SET/GET operations inside pipelines took: 3.2882907390594482 seconds... 12164.374495498905 operations per second
62-
63-
-- Running Simple benchmark with StrictRedisCluster lib and cluster server
64-
python benchmarks/simple.py --port 7001 --timeit --pipeline
65-
10.0k SET/GET operations inside pipelines took: 0.709221601486206 seconds... 14099.965340937933 operations per second
66-
20.0k SET/GET operations inside pipelines took: 1.3776116371154785 seconds... 14517.879684783395 operations per second
67-
40.0k SET/GET operations inside pipelines took: 2.794893980026245 seconds... 14311.813001087214 operations per second
45+
-- Running Simple benchmark with Redis lib and non cluster server, 50 concurrent processes and total 50000*2 requests --
46+
python benchmarks/simple.py --host 127.0.0.1 --timeit --nocluster -c 50 -n 50000
47+
50.0k SET/GET operations took: 2.45 seconds... 40799.93 operations per second
48+
49+
-- Running Simple benchmark with RedisCluster lib and cluster server, 50 concurrent processes and total 50000*2 requests --
50+
python benchmarks/simple.py --host 127.0.0.1 --timeit -c 50 -n 50000
51+
50.0k SET & GET (each 50%) operations took: 9.51 seconds... 31513.71 operations per second
52+
53+
-- Running Simple benchmark with pipelines & Redis lib and non cluster server --
54+
python benchmarks/simple.py --host 127.0.0.1 --timeit --nocluster -c 50 -n 50000 --pipeline
55+
50.0k SET & GET (each 50%) operations took: 2.1728243827819824 seconds... 46023.047602201834 operations per second
56+
57+
-- Running Simple benchmark with RedisCluster lib and cluster server
58+
python benchmarks/simple.py --host 127.0.0.1 --timeit -c 50 -n 50000 --pipeline
59+
50.0k SET & GET (each 50%) operations took: 1.7181339263916016 seconds... 58202.68051514381 operations per second

0 commit comments

Comments
 (0)