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

Commit f3574b7

Browse files
authored
Python package, bump version number (#4)
1 parent 7a5febc commit f3574b7

File tree

14 files changed

+126
-71
lines changed

14 files changed

+126
-71
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ tools/
55
__pycache__/
66
*.py[cod]
77
.Python
8+
rpq.egg-info/
9+
build/
10+
dist/
811

912
# Mac
1013
.DS_Store

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,20 @@ Output is similar to [ZCOUNT](https://redis.io/commands/zcount)
103103

104104
The queues can be easily monitored with the Python script `src/queue_monitor.py`
105105

106-
To use the queue monitor, you need to ensure python is installed and use the following command to add the required packages:
107-
`pip install prettytable argparse redis json`
106+
To use the queue monitor, you need to ensure python is installed and use the following command:
107+
```
108+
# Installation
109+
pip3 install rpq
110+
111+
# Usage
112+
rpq_monitor
113+
```
108114

109115
### Usage example
110116

111117
```
112118
# Basic usage
113-
./src/queue_monitor.py -H [host] -p [port] (-a [auth] -n [dbnum])
119+
rpq_monitor -H [host] -p [port] (-a [auth] -n [dbnum])
114120
+-------------------+-------+-----------+----------+
115121
| Queue name | Total | Up to 100 | From 101 |
116122
+-------------------+-------+-----------+----------+
@@ -122,7 +128,7 @@ To use the queue monitor, you need to ensure python is installed and use the fol
122128
+-------------------+-------+-----------+----------+
123129
124130
# Specify your own groups
125-
./src/queue_monitor.py -H [host] -p [port] (-a [auth] -n [dbnum]) -s "[[0, 1000], [1001, 2000], [2001, 3000]]"
131+
rpq_monitor -H [host] -p [port] (-a [auth] -n [dbnum]) -s "[[0, 1000], [1001, 2000], [2001, 3000]]"
126132
+-------------------+-------+------------+----------------+----------------+
127133
| Queue name | Total | 0 to 1,000 | 1,001 to 2,000 | 2,001 to 3,000 |
128134
+-------------------+-------+------------+----------------+----------------+

clients/python/README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ Python client for redis-priority-queue.
55
## Requirements
66

77
- Python 2.7 & 3
8-
- Redis Python package (`pip install redis`)
8+
9+
## Installation
10+
11+
```
12+
pip3 install rpq
13+
```
914

1015
## Sample use
1116

@@ -14,18 +19,18 @@ Python client for redis-priority-queue.
1419

1520
# Packages
1621
import redis
17-
from lib.RpqQueue import RpqQueue
18-
from lib.RpqLua import RpqLua
22+
from rpq import RpqQueue
23+
from rpq import RpqLua
1924

2025
# Redis instance
21-
r = redis.StrictRedis(host='127.0.0.1', port=6379, db=0, password='')
26+
r = redis.StrictRedis(host = '127.0.0.1', port = 6379, db = 0, password = '')
2227

2328
# Load LUA Script
24-
RpqLua = RpqLua(r, '../../src/redis-priority-queue.lua');
29+
RpqLua = RpqLua.RpqLua(r);
2530
queue = RpqLua.register();
2631

2732
# RpqQueue instance
28-
RpqQueue = RpqQueue(queue)
33+
RpqQueue = RpqQueue.RpqQueue(queue)
2934

3035
# Set queue name
3136
RpqQueue.setqueueName('simple_queue')

clients/python/count.py renamed to clients/python/examples/count.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
# Packages
44
import redis
5-
from lib.RpqQueue import RpqQueue
6-
from lib.RpqLua import RpqLua
7-
from utils.redis_vars import *
5+
from rpq import RpqQueue
6+
from rpq import RpqLua
87

98
# Redis instance
10-
# !!! set Redis credentials into utils/redis_vars.py
11-
r = redis.StrictRedis(host=rHost, port=rPort, db=rDbnum, password=rAuth)
9+
r = redis.StrictRedis(host = '127.0.0.1', port = 6379, db = 0, password = '')
1210

1311
# Load LUA Script
14-
RpqLua = RpqLua(r, '../../src/redis-priority-queue.lua');
12+
RpqLua = RpqLua.RpqLua(r);
1513
queue = RpqLua.register();
1614

1715
# RpqQueue instance
18-
RpqQueue = RpqQueue(queue);
16+
RpqQueue = RpqQueue.RpqQueue(queue);
1917

2018
# Set queue name
2119
RpqQueue.setqueueName('simple_queue')
@@ -29,4 +27,4 @@
2927
print (RpqQueue.count(0, 100))
3028

3129
print ('* count (priority > 100):')
32-
print (RpqQueue.count(101))
30+
print (RpqQueue.count(101))

clients/python/peek.py renamed to clients/python/examples/peek.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
# Packages
44
import redis
5-
from lib.RpqQueue import RpqQueue
6-
from lib.RpqLua import RpqLua
7-
from utils.redis_vars import *
5+
from rpq import RpqQueue
6+
from rpq import RpqLua
87

98
def listItems(items):
109
'''Helper to print items'''
1110
for item in items:
1211
print (item);
1312

1413
# Redis instance
15-
# !!! set Redis credentials into utils/redis_vars.py
16-
r = redis.StrictRedis(host=rHost, port=rPort, db=rDbnum, password=rAuth)
14+
r = redis.StrictRedis(host = '127.0.0.1', port = 6379, db = 0, password = '')
1715

1816
# Load LUA Script
19-
RpqLua = RpqLua(r, '../../src/redis-priority-queue.lua');
17+
RpqLua = RpqLua.RpqLua(r);
2018
queue = RpqLua.register();
2119

2220
# RpqQueue instance
23-
RpqQueue = RpqQueue(queue);
21+
RpqQueue = RpqQueue.RpqQueue(queue);
2422

2523
# Set queue name
2624
RpqQueue.setqueueName('simple_queue')

clients/python/pop.py renamed to clients/python/examples/pop.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
# Packages
44
import redis
5-
from lib.RpqQueue import RpqQueue
6-
from lib.RpqLua import RpqLua
7-
from utils.redis_vars import *
5+
from rpq import RpqQueue
6+
from rpq import RpqLua
87

98
def listItems(items):
109
'''Helper to print items'''
1110
for item in items:
1211
print (item);
1312

1413
# Redis instance
15-
# !!! set Redis credentials into utils/redis_vars.py
16-
r = redis.StrictRedis(host=rHost, port=rPort, db=rDbnum, password=rAuth)
14+
r = redis.StrictRedis(host = '127.0.0.1', port = 6379, db = 0, password = '')
1715

1816
# Load LUA Script
19-
RpqLua = RpqLua(r, '../../src/redis-priority-queue.lua');
17+
RpqLua = RpqLua.RpqLua(r);
2018
queue = RpqLua.register();
2119

2220
# RpqQueue instance
23-
RpqQueue = RpqQueue(queue);
21+
RpqQueue = RpqQueue.RpqQueue(queue);
2422

2523
# Set queue name
2624
RpqQueue.setqueueName('simple_queue')

clients/python/push.py renamed to clients/python/examples/push.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
# Packages
44
import redis, random
5-
from lib.RpqQueue import RpqQueue
6-
from lib.RpqLua import RpqLua
7-
from utils.redis_vars import *
5+
from rpq import RpqQueue
6+
from rpq import RpqLua
87

98
def generateRandom():
109
'''Helper: get a random integer'''
@@ -15,15 +14,14 @@ def getItem():
1514
return 'item_' + str(generateRandom());
1615

1716
# Redis instance
18-
# !!! set Redis credentials into utils/redis_vars.py
19-
r = redis.StrictRedis(host=rHost, port=rPort, db=rDbnum, password=rAuth)
17+
r = redis.StrictRedis(host = '127.0.0.1', port = 6379, db = 0, password = '')
2018

2119
# Load LUA Script
22-
RpqLua = RpqLua(r, '../../src/redis-priority-queue.lua');
20+
RpqLua = RpqLua.RpqLua(r);
2321
queue = RpqLua.register();
2422

2523
# RpqQueue instance
26-
RpqQueue = RpqQueue(queue);
24+
RpqQueue = RpqQueue.RpqQueue(queue);
2725

2826
# Set queue name
2927
RpqQueue.setqueueName('simple_queue')
@@ -38,4 +36,4 @@ def getItem():
3836
print ('* push (with priority):')
3937
item = getItem() # Item we will push to the queue
4038
print ('Pushing item "%s" to the queue' % (item))
41-
print (RpqQueue.push(item, 1000))
39+
print (RpqQueue.push(item, 1000))

clients/python/lib/RpqLua.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
11
#!/usr/bin/env python3
22

33
class RpqLua:
4-
def __init__(self, redisConnection, luaPath):
4+
def __init__(self, redisConnection):
55
'''Sets Redis connection, load LUA from path'''
6+
67
self.setRedisConnection(redisConnection);
7-
self.loadSource(luaPath);
8+
self.loadSource(self.getLuaPath());
9+
10+
def getLuaPath(self):
11+
"""
12+
Returns the LUA path in the filesystem
13+
"""
14+
15+
import rpq_src, pkg_resources
16+
17+
return pkg_resources.resource_filename('rpq_src', 'redis-priority-queue.lua');
818

919
def file_get_contents(self, filename):
1020
'''Get a file content'''
21+
1122
with open(filename) as f:
1223
return f.read()
1324

1425
def setRedisConnection(self, connection):
1526
'''Set a Redis connection'''
27+
1628
self.connection = connection;
1729

1830
def loadSource(self, path):
1931
'''Load LUA script source code from a file'''
32+
2033
self.source = self.file_get_contents(path);
2134

2235
def register(self):
2336
'''Load the script into Redis'''
37+
2438
self.queue = self.connection.register_script(self.source)
2539
return self.queue;

clients/python/utils/redis_vars.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
description-file = README.md

0 commit comments

Comments
 (0)