{"id":16387183,"url":"https://github.com/zackshen/python-redis-queue-sample","last_synced_at":"2025-06-12T02:05:43.018Z","repository":{"id":30266520,"uuid":"33817954","full_name":"zackshen/python-redis-queue-sample","owner":"zackshen","description":"python redis任务队列demo, 自备","archived":false,"fork":false,"pushed_at":"2015-04-12T13:31:53.000Z","size":100,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-30T18:03:24.280Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zackshen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-12T13:30:26.000Z","updated_at":"2023-03-05T00:48:27.000Z","dependencies_parsed_at":"2022-09-06T23:40:31.214Z","dependency_job_id":null,"html_url":"https://github.com/zackshen/python-redis-queue-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zackshen/python-redis-queue-sample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackshen%2Fpython-redis-queue-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackshen%2Fpython-redis-queue-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackshen%2Fpython-redis-queue-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackshen%2Fpython-redis-queue-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zackshen","download_url":"https://codeload.github.com/zackshen/python-redis-queue-sample/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackshen%2Fpython-redis-queue-sample/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259382283,"owners_count":22848834,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T04:25:31.280Z","updated_at":"2025-06-12T02:05:42.990Z","avatar_url":"https://github.com/zackshen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 任务队列\n\n## 环境准备\n\n### Python Redis\n\n    # pip install -i http://pypi.douban.com/simple redis\n\n### RQ\n\n    # pip install -i http://pypi.douban.com/simple rq\n\n### Redis Server\n\n\t# docker pull redis:latest\n\t# docker run -d -p 6379:6379 -t redis:latest\n\t\n### RqWorker\n\n启动rqworker，等待任务\n\n\t# rqworker -P . -u redis://192.168.59.103:6379\t\n\n## 运行一个任务\n\t\n\t# python create.py\n\t\n```\nimport sys\nimport os\nimport time\nfrom redis import Redis\nfrom rq import Queue\nfrom rq.job import Job\n\n_dir = os.path.abspath(os.path.dirname(__file__))\nsys.path.insert(0, _dir)\n\nif __name__ == \"__main__\":\n    from handles import count_words_at_url\n    # 连接redis服务器\n    conn = Redis(host=\"192.168.59.103\")\n    # 创建RQ任务队列\n    q = Queue(connection=conn)\n    # 将任务处理函数和参数传入队列，这里会将任务发到redis服务器，任务创建完毕返回job实例\n    job = q.enqueue(count_words_at_url, 'http://www.baidu.com')\n\n\t# 新建一个任务等待结果\n    waiting_job = Job(connection=conn, id=job.id)\n\n    while True:\n        if waiting_job.is_queued:\n            print \"job is in queue\"\n        if waiting_job.is_started:\n            print \"job has been started\"\n        if waiting_job.is_finished:\n            print \"job has finished\"\n            print \"job result is\", waiting_job.result\n            break\n        time.sleep(1)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackshen%2Fpython-redis-queue-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzackshen%2Fpython-redis-queue-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackshen%2Fpython-redis-queue-sample/lists"}