{"id":19124203,"url":"https://github.com/tair-opensource/tairdoc","last_synced_at":"2025-05-05T19:12:03.840Z","repository":{"id":244881977,"uuid":"816087819","full_name":"tair-opensource/TairDoc","owner":"tair-opensource","description":"TairDoc is a Valkey module that supports JSON data storage and querying.","archived":false,"fork":false,"pushed_at":"2024-06-18T08:44:40.000Z","size":423,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-19T11:09:24.510Z","etag":null,"topics":["json","jsonpath","jsonpointer","redis","valkey"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tair-opensource.png","metadata":{"files":{"readme":"README-CN.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-17T02:33:18.000Z","updated_at":"2024-12-22T15:32:53.000Z","dependencies_parsed_at":"2024-06-18T03:58:51.312Z","dependency_job_id":"8f8042df-fc56-40f8-80be-6cf25757b784","html_url":"https://github.com/tair-opensource/TairDoc","commit_stats":null,"previous_names":["tair-opensource/tairdoc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tair-opensource%2FTairDoc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tair-opensource%2FTairDoc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tair-opensource%2FTairDoc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tair-opensource%2FTairDoc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tair-opensource","download_url":"https://codeload.github.com/tair-opensource/TairDoc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252561038,"owners_count":21768063,"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":["json","jsonpath","jsonpointer","redis","valkey"],"created_at":"2024-11-09T05:28:24.083Z","updated_at":"2025-05-05T19:12:03.790Z","avatar_url":"https://github.com/tair-opensource.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## TairDoc [English introduction](README.md)\nTairDoc 是一个支持 JSON 数据存储和查询的 Valkey 模块。\n\n## 主要特性\n- 支持 [RFC8259](https://datatracker.ietf.org/doc/html/rfc8259) JSON 标准。\n- 支持 [RFC6901](https://datatracker.ietf.org/doc/html/rfc6901) JSONPointer 语法。\n- 部分兼容 [RFC9535](https://datatracker.ietf.org/doc/rfc9535/) JSONPath 标准。（目前只有`JSON.GET`命令支持 JSONPath 语法）\n\n## 依赖项目\nTairDoc 依赖 [cJSON](https://github.com/DaveGamble/cJSON)，并再其之上实现了 JSONPath 语法，详见 src/cJSON/cJSON_Utils.[h|c]\n\n## 快速开始\n```\n127.0.0.1:6379\u003e JSON.SET key . '{\"store\":{\"book\":[{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":8.95},{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":12.99},{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":8.99},{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":22.99}],\"bicycle\":{\"color\":\"red\",\"price\":19.95}},\"expensive\":10}'\nOK\n127.0.0.1:6379\u003e JSON.GET key $.store.book[*].author\n\"[\\\"Nigel Rees\\\",\\\"Evelyn Waugh\\\",\\\"Herman Melville\\\",\\\"J. R. R. Tolkien\\\"]\"\n127.0.0.1:6379\u003e JSON.GET key $.store..price\n\"[8.95,12.99,8.99,22.99,19.95]\"\n127.0.0.1:6379\u003e JSON.GET key $..book[?(@.isbn)]\n\"[{\\\"category\\\":\\\"fiction\\\",\\\"author\\\":\\\"Herman Melville\\\",\\\"title\\\":\\\"Moby Dick\\\",\\\"isbn\\\":\\\"0-553-21311-3\\\",\\\"price\\\":8.99},{\\\"category\\\":\\\"fiction\\\",\\\"author\\\":\\\"J. R. R. Tolkien\\\",\\\"title\\\":\\\"The Lord of the Rings\\\",\\\"isbn\\\":\\\"0-395-19395-8\\\",\\\"price\\\":22.99}]\"\n```\n## 如何运行\n```\nmake\n```\n编译成功后，会在当前目录下产生`tairdoc.so`文件。\n```\n./valkey-server --loadmodule /path/to/tairdoc.so\n```\n\n## 测试方法\n修改 test 目录下 tairdoc.tcl 文件中的路径为：`set testmodule [file your_path/tairdoc.so]`\n\n将 test 目录下 tairdoc.tcl 拷贝至 valkey 目录 tests 下\n```  \ncp test/tairdoc.tcl your_valkey_path/tests\n```\n然后在 valkey 根目录下运行 ./runtest --single tairdoc，得到下述结果表明运行成功。\n```\n...\n[ok]: json.arrpush/json.arrpop master-slave (2 ms)\n[ok]: json.arrinsert/json.arrtrim (2 ms)\n[ok]: Check for memory leaks (pid 57468) (499 ms)\n[ok]: Check for memory leaks (pid 57456) (457 ms)\n[1/1 done]: tairdoc (5 seconds)\n\n                   The End\n\nExecution time of different units:\n  5 seconds - tairdoc\n\n\\o/ All tests passed without errors!\n```\n\n## 客户端\n| language | GitHub |\n|----------|---|\n| Java     |https://github.com/alibaba/alibabacloud-tairjedis-sdk|\n| Python   |https://github.com/alibaba/tair-py|\n| Go       |https://github.com/alibaba/tair-go|\n| .Net     |https://github.com/alibaba/AlibabaCloud.TairSDK|\n\n## API\n\n### JSON.SET\n\n- **语法**: `JSON.SET key path json [NX | XX]`\n- **时间复杂度**: O(N)\n- **命令描述**: 创建key并将JSON的值存储在对应的path中，若key及目标path已经存在，则更新对应的JSON值。\n- **选项**:\n    - key：TairDoc的key。\n    - path：目标key的path，根元素支持`.`或`$`。\n    - json：待新增或更新的JSON数据。\n    - NX：当path不存在时写入。\n    - XX：当path存在时写入。\n- **返回值**:\n    - 执行成功：OK。\n    - 指定了XX且path不存在：nil。\n    - 指定了NX且path已存在：nil。\n    - 若返回`ERR could not find object to add, please check path`：表示您输入的path有误。\n    - 其它情况返回相应的异常信息。\n\n### JSON.GET\n\n- **语法**: `JSON.GET key path`\n- **时间复杂度**: O(N)\n- **命令描述**: 获取目标key、path中存储的JSON数据。\n- **选项**:\n    - key：TairDoc的key。\n    - path：目标key的path，支持JSONPath与JSONPointer语法。\n- **返回值**:\n    - 执行成功：对应的JSON数据。\n    - 其它情况返回相应的异常信息。\n\n### JSON.DEL\n\n- **语法**: `JSON.DEL key path`\n- **时间复杂度**: O(N)\n- **命令描述**: 删除目标key中path对应的JSON数据。若未指定path，则删除整个key。若指定的key不存在或path不存在，则忽略该操作。\n\n- **选项**:\n  - **key**: TairDoc的key。\n  - **path**: 目标key的path，用于指定需要删除的JSON数据的部分。\n\n- **返回值**:\n  - 执行成功：返回 `1`。\n  - 执行失败：返回 `0`。\n  - 若key不存在或path不存在：返回 `-1` 或者相应的异常信息。\n\n### JSON.TYPE\n\n- **语法**: `JSON.TYPE key path`\n- **时间复杂度**: O(N)\n- **命令描述**: 获取目标key中path对应值的类型，结果可能包括`boolean`、`string`、`number`、`array`、`object`、`null`等。\n\n- **选项**:\n  - **key**: TairDoc的key。\n  - **path**: 目标key的path，用于指定需要查询类型的JSON数据的部分。\n\n- **返回值**:\n  - 执行成功：返回查询到的类型。\n  - 执行失败：返回 `0`。\n  - 若key或path不存在：返回 `nil`。\n  - 其它情况返回相应的异常信息。\n\n### JSON.NUMINCRBY\n\n- **语法**: `JSON.NUMINCRBY key path value`\n- **时间复杂度**: O(N)\n- **命令描述**: 对目标key中path对应的值增加value，path对应的值和待增加的value必须是int或double类型。\n\n- **选项**:\n  - **key**: TairDoc的key。\n  - **path**: 目标key的path。\n  - **value**: 待增加的数值。\n\n- **返回值**:\n  - 执行成功：返回操作完成后path对应的值。\n  - key或path不存在：返回错误。\n\n### JSON.STRAPPEND\n\n- **语法**: `JSON.STRAPPEND key path json-string`\n- **时间复杂度**: O(N)\n- **命令描述**: 在指定path对应值中追加json-string字符串，path对应值的类型也需要为字符串。\n\n- **选项**:\n  - **key**: TairDoc的key。\n  - **path**: 目标key的path。\n  - **json-string**: 待追加的字符串。\n\n- **返回值**:\n  - 执行成功：返回操作完成后path对应值的字符串长度。\n  - key不存在：返回 `-1`。\n\n### JSON.STRLEN\n\n- **语法**: `JSON.STRLEN key path`\n- **时间复杂度**: O(N)\n- **命令描述**: 获取目标key中path对应值的字符串长度，path对应值的类型需要为字符串。\n\n- **选项**:\n  - **key**: TairDoc的key。\n  - **path**: 目标key的path。\n\n- **返回值**:\n  - 执行成功：返回path对应值的字符串长度。\n  - key不存在：返回 `-1`。\n\n### JSON.ARRPOP\n\n- **语法**: `JSON.ARRPOP key path [index]`\n- **时间复杂度**: O(M*N)，M是key包含的子元素，N是数组元素数量。\n- **命令描述**: 移除并返回path对应数组中指定位置的元素。\n\n- **选项**:\n  - **key**: TairDoc的key。\n  - **path**: 目标key的path。\n  - **index**: 数组的索引，若不传该参数默认为最后一个元素。\n\n- **返回值**:\n  - 执行成功：移除并返回该元素。\n  - 数组为空：返回错误信息。\n\n### JSON.ARRINSERT\n\n- **语法**: `JSON.ARRINSERT key path [index] json [json ...]`\n- **时间复杂度**: O(M*N)，M是要插入的元素数量，N是数组元素数量。\n- **命令描述**: 将JSON插入到path对应的数组中，原有元素会往后移动。\n\n- **选项**:\n  - **key**: TairDoc的key。\n  - **path**: 目标key的path。\n  - **index**: 数组的索引。\n  - **json**: 需要插入的数据。\n\n- **返回值**:\n  - 执行成功：返回操作完成后数组中的元素数量。\n  - 数组为空：返回错误信息。\n\n### JSON.ARRLEN\n\n- **语法**: `JSON.ARRLEN key path`\n- **时间复杂度**: O(N)\n- **命令描述**: 获取path对应数组的长度。\n\n- **选项**:\n  - **key**: TairDoc的key。\n  - **path**: 目标key的path。\n\n- **返回值**:\n  - 执行成功：返回数组的长度。\n  - key不存在：返回 `-1`。\n\n### JSON.ARRTRIM\n\n- **语法**: `JSON.ARRTRIM key path start stop`\n- **时间复杂度**: O(N)\n- **命令描述**: 修剪目标key的path对应的数组，保留start至stop范围内的数据。\n\n- **选项**:\n  - **key**: TairDoc的key。\n  - **path**: 目标key的path。\n  - **start**: 修剪的开始位置。\n  - **stop**: 修剪的结束位置。\n\n- **返回值**:\n  - 执行成功：返回操作完成后数组的长度。\n  - key不存在：返回 `-1`。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftair-opensource%2Ftairdoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftair-opensource%2Ftairdoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftair-opensource%2Ftairdoc/lists"}