{"id":20180698,"url":"https://github.com/xdusongwei/porkpepper","last_synced_at":"2026-05-06T00:05:22.951Z","repository":{"id":57454198,"uuid":"191772270","full_name":"xdusongwei/porkpepper","owner":"xdusongwei","description":"编写基于 Redis 通信协议的服务, 并且支持对 Websocket 会话进行操作","archived":false,"fork":false,"pushed_at":"2019-08-20T15:51:20.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-20T12:12:35.158Z","etag":null,"topics":["asyncio","python","python3","redis","server","websocket"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xdusongwei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-13T13:51:24.000Z","updated_at":"2019-07-12T15:19:04.000Z","dependencies_parsed_at":"2022-08-29T11:12:07.258Z","dependency_job_id":null,"html_url":"https://github.com/xdusongwei/porkpepper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xdusongwei/porkpepper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdusongwei%2Fporkpepper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdusongwei%2Fporkpepper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdusongwei%2Fporkpepper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdusongwei%2Fporkpepper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xdusongwei","download_url":"https://codeload.github.com/xdusongwei/porkpepper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xdusongwei%2Fporkpepper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32672685,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-05T11:29:49.557Z","status":"ssl_error","status_checked_at":"2026-05-05T11:29:48.587Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["asyncio","python","python3","redis","server","websocket"],"created_at":"2024-11-14T02:32:28.596Z","updated_at":"2026-05-06T00:05:22.935Z","avatar_url":"https://github.com/xdusongwei.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"porkpepper\n==========\n\n使用 Redis 协议编写服务，以及使用 Redis 协议控制 Websocket 会话\n\n\n示例: 启动一个 Redis 服务\n\n```python\nimport asyncio\nfrom porkpepper.design import service, RedisServiceNode\n\n\nclass MyService:\n    @classmethod\n    @service(key=\"add\", output=True, meta=dict(version=\"0.1.0\"))\n    async def add(cls, message):\n        a = message.get(\"a\", 0)\n        b = message.get(\"b\", 0)\n        result = a + b\n        return dict(result=result)\n\n\nclass MyService2:\n    @service(key=\"plus\", output=True)\n    async def add(self, x, y, **kwargs):\n        result = x + y\n        return dict(result=result)\n    \n    @service(key=\"without_output\")\n    async def without_output(self, message):\n        print(message)\n\n\nasync def main():\n    node = RedisServiceNode()\n    # 设置类型和实例都可以\n    db_map = {\n        0: MyService,\n        1: MyService2(),\n    }\n    await node.serve(db_map, redis_host=\"127.0.0.1\", redis_port=6379)\n\n\nif __name__ == '__main__':\n    asyncio.run(main())\n\n```\n\n```\n$ redis-cli\n127.0.0.1:6379\u003e KEYS *\n1) \"add\"\n127.0.0.1:6379\u003e GETSET add \"{\\\"a\\\": 1, \\\"b\\\": 2}\"\n\"{\\\"result\\\": 3}\"\n127.0.0.1:6379\u003e SELECT 1\nOK\n127.0.0.1:6379[1]\u003e KEYS *\n1) \"plus\"\n2) \"without_output\"\n127.0.0.1:6379[1]\u003e GET plus\n\"{\\\"type\\\": \\\"api\\\", \\\"key\\\": \\\"plus\\\", \\\"output\\\": true, \\\"signature\\\": \\\"(self, x, y, **kwargs)\\\", \\\"description\\\": null, \\\"meta\\\": {}}\"\n127.0.0.1:6379[1]\u003e GET without_output\n\"{\\\"type\\\": \\\"api\\\", \\\"key\\\": \\\"without_output\\\", \\\"output\\\": false, \\\"signature\\\": \\\"(self, message)\\\", \\\"description\\\": null, \\\"meta\\\": {}}\"\n127.0.0.1:6379[1]\u003e GETSET plus \"{\\\"x\\\": 1, \\\"y\\\": 2}\"\n\"{\\\"result\\\": 3}\"\n127.0.0.1:6379[1]\u003e SET without_output \"{\\\"foo\\\": \\\"bar\\\"}\"\nOK\n```\n\n\n\n\n示例: 启动 Redis 和 Websocket 服务\n\n```Python\nimport aiohttp\nimport porkpepper\n\n\nclass HelloSession(porkpepper.WebsocketSession):\n    async def request(self, message):\n        if message[\"type\"] == \"hello\":\n            await self.send(dict(type=\"world\"))\n        else:\n            await self.close()\n\n\nasync def serve():\n    node = porkpepper.WebsocketNode(HelloSession, \"/porkpepper\")\n    await node.serve(host=\"127.0.0.1\", port=9090)\n\n\nasync def client():\n    async with aiohttp.ClientSession() as session:\n        async with session.ws_connect('http://127.0.0.1:9090/porkpepper') as ws:\n            await ws.send_json(dict(type=\"hello\"))\n            message = await ws.receive_json()\n            assert message == {\"type\": \"world\"}\n            await ws.close()\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdusongwei%2Fporkpepper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxdusongwei%2Fporkpepper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxdusongwei%2Fporkpepper/lists"}