Skip to content

Conversation

@u6th9d
Copy link
Contributor

@u6th9d u6th9d commented Nov 24, 2023

ref from #2119:
ref issue #2040

image

@github-actions github-actions bot added the ✏️ Feature New feature or request label Nov 24, 2023
@AlexStocks
Copy link
Contributor

还请大佬把这个 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()

std::set<std::string> compact_dbs_;
};

class CompactRangeCmd : public Cmd {
Copy link
Contributor

@AlexStocks AlexStocks Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非 Redis 指令而是作为Pika 内置指令的话, 建议改为 PkCompactRangeCmd

const std::string kCmdNameAuth = "auth";
const std::string kCmdNameBgsave = "bgsave";
const std::string kCmdNameCompact = "compact";
const std::string kCmdNameCompactRange = "compactrange";
Copy link
Contributor

@AlexStocks AlexStocks Nov 24, 2023

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 指令

@AlexStocks
Copy link
Contributor

AlexStocks commented Nov 27, 2023

如果 把这个 Python 脚本改成 Go 很困难,那就把这个工具放到 github.com/OpenAtomFoundation/pika/tests/helpers 目录下,然后在 CompactRangeCmd 之上加上英文注释,说明下这个工具可以对这个命令进行功能测试

@AlexStocks AlexStocks merged commit 6048295 into OpenAtomFoundation:unstable Nov 27, 2023
@u6th9d u6th9d deleted the patch-0 branch November 27, 2023 11:59
bigdaronlee163 pushed a commit to bigdaronlee163/pika that referenced this pull request Jun 8, 2024
…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]>
cheniujh pushed a commit to cheniujh/pika that referenced this pull request Sep 24, 2024
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.5.3 ✏️ Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants