Skip to content

Commit af8a70a

Browse files
authored
Merge pull request #281 from doyoubi/PythonClusterClientTest
Add python cluster client tests
2 parents e927010 + 532366c commit af8a70a

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,17 @@ jobs:
121121
env:
122122
CLIENT_TEST_NODE_HOST: 127.0.0.1
123123
CLIENT_TEST_NODE_PORT: 5299
124+
# Run python tests
125+
- name: Install Python
126+
uses: actions/setup-python@v2
127+
with:
128+
python-version: '3.8'
129+
- name: Install dependencies
130+
run: pip install -r requirements.txt
131+
working-directory: ./clienttest/python
132+
- name: Run Python client tests
133+
run: python redis_py_cluster_test.py
134+
working-directory: ./clienttest/python
135+
env:
136+
CLIENT_TEST_NODE_HOST: 127.0.0.1
137+
CLIENT_TEST_NODE_PORT: 5299
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
import time
3+
4+
from rediscluster import RedisCluster
5+
6+
7+
def create_client(host, port):
8+
startup_nodes = [{"host": host, "port": port}]
9+
return RedisCluster(
10+
startup_nodes=startup_nodes,
11+
decode_responses=True,
12+
skip_full_coverage_check=True,
13+
)
14+
15+
16+
def gen_key(testcase, key):
17+
return 'goredis:{}:{}:{}'.format(time.time(), testcase, key)
18+
19+
20+
def test_single_key_command(client):
21+
key = gen_key('singlekey', 'key')
22+
value = 'singlevalue'
23+
24+
client.setex(key, 60, value)
25+
v = client.get(key)
26+
assert v == value
27+
28+
29+
def test_multi_key_command(client):
30+
key1 = gen_key('multikey', 'key1:{hashtag}')
31+
key2 = gen_key('multikey', 'key2:{hashtag}')
32+
value1 = 'value1'
33+
value2 = 'value2'
34+
35+
client.mset({
36+
key1: value1,
37+
key2: value2,
38+
})
39+
count = client.delete(key1, key2)
40+
assert count == 2
41+
42+
values = client.mget(key1, key2)
43+
assert len(values) == 2
44+
assert values[0] is None
45+
assert values[1] is None
46+
47+
48+
if __name__ == '__main__':
49+
host = os.environ.get('CLIENT_TEST_NODE_HOST') or '127.0.0.1'
50+
port = os.environ.get('CLIENT_TEST_NODE_PORT') or '5299'
51+
client = create_client(host, port)
52+
53+
test_single_key_command(client)
54+
test_multi_key_command(client)

clienttest/python/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
redis-py-cluster==2.1.0

0 commit comments

Comments
 (0)