-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:add new command: compactrange $db $type $start_key $end_key #2163
Conversation
还请大佬把这个 python 测试改成 go 测试跟着这个 PR 一块提交: import redis
import sys
import time
import threading
import signal
START_FLAG = True
def random_enqueue(client: redis.Redis, quene_name: str):
while START_FLAG:
now_sec = int(time.time())
pipeline = client.pipeline(transaction=False)
for i in range(100):
score = now_sec << 16 | i
pipeline.zadd(quene_name, {str(i): score})
pipeline.execute()
print('random_enqueue exit')
def random_dequeue(client: redis.Redis, quene_name: str):
loop = 0
while START_FLAG:
start_time = time.time()
n = client.zcard(quene_name)
if n < 100:
continue
res = client.zremrangebyrank(quene_name, 0, 49)
duration = time.time() - start_time
loop += 1
if loop % 10 == 0:
print('duration: {}, res: {}'.format(duration, res))
loop = 0
print('random_dequeue exit')
def main():
if len(sys.argv) != 4:
print('Usage: python redis_queue.py <redis_host> <port> <passwd>')
sys.exit(1)
host = sys.argv[1]
port = int(sys.argv[2])
passwd = sys.argv[3]
client_enque = redis.Redis(host=host, port=port, password=passwd)
client_deque = redis.Redis(host=host, port=port, password=passwd)
quene_name = 'test_queue'
t1 = threading.Thread(target=random_enqueue, args=(client_enque, quene_name))
t1.start()
t2 = threading.Thread(target=random_dequeue, args=(client_deque, quene_name))
t2.start()
def signal_handler(signal, frame):
print("You pressed Ctrl+C!")
global START_FLAG
START_FLAG = False
t1.join()
t2.join()
print('exit')
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGQUIT, signal_handler)
while True:
time.sleep(60)
if __name__ == '__main__':
main() |
@@ -112,6 +112,28 @@ class CompactCmd : public Cmd { | |||
std::set<std::string> compact_dbs_; | |||
}; | |||
|
|||
class CompactRangeCmd : public Cmd { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
非 Redis 指令而是作为Pika 内置指令的话, 建议改为 PkCompactRangeCmd
@@ -29,6 +29,7 @@ const std::string kCmdNameDbSlaveof = "dbslaveof"; | |||
const std::string kCmdNameAuth = "auth"; | |||
const std::string kCmdNameBgsave = "bgsave"; | |||
const std::string kCmdNameCompact = "compact"; | |||
const std::string kCmdNameCompactRange = "compactrange"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议改为 pkcompactrange,类似于 pksetatex pkrange,标明这是一个 pika 内置指令,区别于 redis 指令
如果 把这个 Python 脚本改成 Go 很困难,那就把这个工具放到 github.com/OpenAtomFoundation/pika/tests/helpers 目录下,然后在 CompactRangeCmd 之上加上英文注释,说明下这个工具可以对这个命令进行功能测试 |
…nAtomFoundation#2163) * add new command: compactrange $db $type $start_key $end_key * update unused value * update test script about compactrange command --------- Co-authored-by: denghao.denghao <[email protected]>
…nAtomFoundation#2163) * add new command: compactrange $db $type $start_key $end_key * update unused value * update test script about compactrange command --------- Co-authored-by: denghao.denghao <[email protected]>
ref from #2119:
ref issue #2040