RedisServer-Queue 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- redisserver_queue-0.0.1/LICENSE +19 -0
- redisserver_queue-0.0.1/PKG-INFO +13 -0
- redisserver_queue-0.0.1/README.md +0 -0
- redisserver_queue-0.0.1/RedisServer/RedisServer.py +115 -0
- redisserver_queue-0.0.1/RedisServer_Queue.egg-info/PKG-INFO +13 -0
- redisserver_queue-0.0.1/RedisServer_Queue.egg-info/SOURCES.txt +8 -0
- redisserver_queue-0.0.1/RedisServer_Queue.egg-info/dependency_links.txt +1 -0
- redisserver_queue-0.0.1/RedisServer_Queue.egg-info/top_level.txt +1 -0
- redisserver_queue-0.0.1/pyproject.toml +21 -0
- redisserver_queue-0.0.1/setup.cfg +4 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: RedisServer-Queue
|
3
|
+
Version: 0.0.1
|
4
|
+
Summary: RedisServer-Queue is a simple redis server
|
5
|
+
Author-email: NelsonLongXiang <1169207670@qq.com>
|
6
|
+
Project-URL: Homepage, https://github.com/NelsonLongxiang/RedisServer
|
7
|
+
Project-URL: Issues, https://github.com/NelsonLongxiang/RedisServer/issues
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Python: >=3.9
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
License-File: LICENSE
|
File without changes
|
@@ -0,0 +1,115 @@
|
|
1
|
+
#!/user/bin/env python3
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
# @Time : 2024/6/6 上午6:16
|
4
|
+
# @Author : 龙翔
|
5
|
+
# @File :RedisServer.py
|
6
|
+
# @Software: PyCharm
|
7
|
+
import json
|
8
|
+
import os
|
9
|
+
import sys
|
10
|
+
import time
|
11
|
+
import uuid
|
12
|
+
|
13
|
+
import redis
|
14
|
+
|
15
|
+
# 将当前文件夹添加到环境变量
|
16
|
+
if os.path.basename(__file__) in ['run.py', 'main.py', '__main__.py']:
|
17
|
+
if '.py' in __file__:
|
18
|
+
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
|
19
|
+
else:
|
20
|
+
sys.path.append(os.path.abspath(__file__))
|
21
|
+
|
22
|
+
r = redis.Redis(host='localhost', port=6379, db=0)
|
23
|
+
|
24
|
+
|
25
|
+
class RedisQueue:
|
26
|
+
def __init__(self, topic=None):
|
27
|
+
self.topic = topic
|
28
|
+
|
29
|
+
def get(self):
|
30
|
+
# 弹出指定数量的数据
|
31
|
+
data = r.rpop(self.topic)
|
32
|
+
return data if data else None
|
33
|
+
|
34
|
+
def put(self, value):
|
35
|
+
if isinstance(value, list):
|
36
|
+
r.lpush(self.topic, *value)
|
37
|
+
else:
|
38
|
+
r.lpush(self.topic, *[value])
|
39
|
+
|
40
|
+
def clear(self):
|
41
|
+
r.delete(self.topic)
|
42
|
+
|
43
|
+
def size(self):
|
44
|
+
return r.llen(self.topic)
|
45
|
+
|
46
|
+
def qsize(self):
|
47
|
+
return self.size()
|
48
|
+
|
49
|
+
def get_mul(self, num):
|
50
|
+
return [self.get() for _ in range(num)]
|
51
|
+
|
52
|
+
def re_data(self):
|
53
|
+
ch_keys = r.keys(f"ack_{self.topic}_*")
|
54
|
+
for key in ch_keys:
|
55
|
+
data = r.get(key)
|
56
|
+
if data:
|
57
|
+
q = RedisQueue(self.topic)
|
58
|
+
t, _data = json.loads(data)
|
59
|
+
r.delete(key)
|
60
|
+
q.put(_data)
|
61
|
+
return len(ch_keys)
|
62
|
+
|
63
|
+
def get_all(self):
|
64
|
+
return r.lrange(self.topic, 0, -1)
|
65
|
+
|
66
|
+
|
67
|
+
class RedisMQ:
|
68
|
+
def __init__(self):
|
69
|
+
self.switch = 1
|
70
|
+
|
71
|
+
def start_receive(self, topic, callback, count=-1):
|
72
|
+
while self.switch:
|
73
|
+
data = r.rpop(topic)
|
74
|
+
if data:
|
75
|
+
ch = RedisCh(topic, data)
|
76
|
+
callback(ch, data)
|
77
|
+
if count == 1:
|
78
|
+
return
|
79
|
+
continue
|
80
|
+
ch_keys = r.keys(f"ack_{topic}_*")
|
81
|
+
for key in ch_keys:
|
82
|
+
data = r.get(key)
|
83
|
+
if data:
|
84
|
+
q = RedisQueue(topic)
|
85
|
+
t, _data = json.loads(data)
|
86
|
+
if time.time() - t > 10 * 60:
|
87
|
+
r.delete(key)
|
88
|
+
q.put(_data)
|
89
|
+
del q
|
90
|
+
if len(ch_keys) == 0:
|
91
|
+
time.sleep(10)
|
92
|
+
time.sleep(1)
|
93
|
+
|
94
|
+
def stop(self):
|
95
|
+
self.switch = 0
|
96
|
+
|
97
|
+
|
98
|
+
class RedisCh:
|
99
|
+
def __init__(self, topic, data):
|
100
|
+
self.topic = topic
|
101
|
+
self.id = uuid.uuid4()
|
102
|
+
r.set(f"ack_{topic}_{self.id}", json.dumps([time.time(), data.decode()]))
|
103
|
+
|
104
|
+
def basic_ack(self):
|
105
|
+
r.delete(f"ack_{self.topic}_{self.id}")
|
106
|
+
|
107
|
+
|
108
|
+
if __name__ == '__main__':
|
109
|
+
r.delete('test')
|
110
|
+
# a = RedisQueue("test")
|
111
|
+
# a.put(1)
|
112
|
+
# print(type(a.get()))
|
113
|
+
# r.set('test', 1)
|
114
|
+
# print(r.get('test'), type(r.get('test').decode('utf8')))
|
115
|
+
# RedisQueue.put(value=1, topic="test")
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: RedisServer-Queue
|
3
|
+
Version: 0.0.1
|
4
|
+
Summary: RedisServer-Queue is a simple redis server
|
5
|
+
Author-email: NelsonLongXiang <1169207670@qq.com>
|
6
|
+
Project-URL: Homepage, https://github.com/NelsonLongxiang/RedisServer
|
7
|
+
Project-URL: Issues, https://github.com/NelsonLongxiang/RedisServer/issues
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Python: >=3.9
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
License-File: LICENSE
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
RedisServer
|
@@ -0,0 +1,21 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["setuptools>=61.0"]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
[project]
|
5
|
+
name = "RedisServer-Queue"
|
6
|
+
version = "0.0.1"
|
7
|
+
authors = [
|
8
|
+
{ name="NelsonLongXiang", email="1169207670@qq.com" },
|
9
|
+
]
|
10
|
+
description = "RedisServer-Queue is a simple redis server"
|
11
|
+
readme = "README.md"
|
12
|
+
requires-python = ">=3.9"
|
13
|
+
classifiers = [
|
14
|
+
"Programming Language :: Python :: 3",
|
15
|
+
"License :: OSI Approved :: MIT License",
|
16
|
+
"Operating System :: OS Independent",
|
17
|
+
]
|
18
|
+
|
19
|
+
[project.urls]
|
20
|
+
Homepage = "https://github.com/NelsonLongxiang/RedisServer"
|
21
|
+
Issues = "https://github.com/NelsonLongxiang/RedisServer/issues"
|