| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <title>Pegasus | Python Client</title> |
| <link rel="stylesheet" href="/zh/assets/css/app.css"> |
| <link rel="shortcut icon" href="/zh/assets/images/favicon.ico"> |
| <link rel="stylesheet" href="/zh/assets/css/utilities.min.css"> |
| <link rel="stylesheet" href="/zh/assets/css/docsearch.v3.css"> |
| <script src="/assets/js/jquery.min.js"></script> |
| <script src="/assets/js/all.min.js"></script> |
| <script src="/assets/js/docsearch.v3.js"></script> |
| <!-- Begin Jekyll SEO tag v2.8.0 --> |
| <title>Python Client | Pegasus</title> |
| <meta name="generator" content="Jekyll v4.3.3" /> |
| <meta property="og:title" content="Python Client" /> |
| <meta property="og:locale" content="en_US" /> |
| <meta name="description" content="pegasus python client" /> |
| <meta property="og:description" content="pegasus python client" /> |
| <meta property="og:site_name" content="Pegasus" /> |
| <meta property="og:type" content="article" /> |
| <meta property="article:published_time" content="2024-04-22T06:39:52+00:00" /> |
| <meta name="twitter:card" content="summary" /> |
| <meta property="twitter:title" content="Python Client" /> |
| <script type="application/ld+json"> |
| {"@context":"https://schema.org","@type":"BlogPosting","dateModified":"2024-04-22T06:39:52+00:00","datePublished":"2024-04-22T06:39:52+00:00","description":"pegasus python client","headline":"Python Client","mainEntityOfPage":{"@type":"WebPage","@id":"/clients/python-client"},"url":"/clients/python-client"}</script> |
| <!-- End Jekyll SEO tag --> |
| </head> |
| |
| |
| <body> |
| <div class="dashboard is-full-height"> |
| <!-- left panel --> |
| <div class="dashboard-panel is-medium is-hidden-mobile pl-0"> |
| <div class="dashboard-panel-header has-text-centered"> |
| <a href="/zh/"> |
| <img src="/assets/images/pegasus-logo-inv.png" style="width: 80%;"> |
| </a> |
| |
| </div> |
| <div class="dashboard-panel-main is-scrollable pl-6"> |
| |
| |
| <aside class="menu"> |
| |
| <p class="menu-label">Pegasus 产品文档</p> |
| <ul class="menu-list"> |
| |
| <li> |
| <a href="/zh/docs/downloads" |
| class=""> |
| 下载 |
| </a> |
| </li> |
| |
| </ul> |
| |
| <p class="menu-label">编译构建</p> |
| <ul class="menu-list"> |
| |
| <li> |
| <a href="/zh/docs/build/compile-by-docker" |
| class=""> |
| 使用 Docker 完成编译(推荐) |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/docs/build/compile-from-source" |
| class=""> |
| 从源码编译 |
| </a> |
| </li> |
| |
| </ul> |
| |
| <p class="menu-label">客户端库</p> |
| <ul class="menu-list"> |
| |
| <li> |
| <a href="/zh/clients/java-client" |
| class=""> |
| Java 客户端 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/clients/cpp-client" |
| class=""> |
| C++ 客户端 |
| </a> |
| </li> |
| |
| <li> |
| <a href="https://github.com/apache/incubator-pegasus/tree/master/go-client" |
| class=""> |
| Golang 客户端 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/clients/python-client" |
| class="is-active"> |
| Python 客户端 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/clients/node-client" |
| class=""> |
| NodeJS 客户端 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/clients/scala-client" |
| class=""> |
| Scala 客户端 |
| </a> |
| </li> |
| |
| </ul> |
| |
| <p class="menu-label">生态工具</p> |
| <ul class="menu-list"> |
| |
| <li> |
| <a href="/zh/docs/tools/shell" |
| class=""> |
| Pegasus Shell 工具 |
| </a> |
| </li> |
| |
| <li> |
| <a href="https://github.com/pegasus-kv/admin-cli" |
| class=""> |
| 集群管理命令行 |
| </a> |
| </li> |
| |
| <li> |
| <a href="https://github.com/pegasus-kv/pegic" |
| class=""> |
| 数据访问命令行 |
| </a> |
| </li> |
| |
| </ul> |
| |
| <p class="menu-label">用户接口</p> |
| <ul class="menu-list"> |
| |
| <li> |
| <a href="/zh/api/ttl" |
| class=""> |
| TTL |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/api/single-atomic" |
| class=""> |
| 单行原子操作 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/api/redis" |
| class=""> |
| Redis 适配 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/api/geo" |
| class=""> |
| GEO 支持 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/api/http" |
| class=""> |
| HTTP 接口 |
| </a> |
| </li> |
| |
| </ul> |
| |
| <p class="menu-label">高效运维</p> |
| <ul class="menu-list"> |
| |
| <li> |
| <a href="/zh/administration/deployment" |
| class=""> |
| 集群部署 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/config" |
| class=""> |
| 配置说明 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/rebalance" |
| class=""> |
| 负载均衡 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/monitoring" |
| class=""> |
| 可视化监控 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/rolling-update" |
| class=""> |
| 集群重启和升级 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/scale-in-out" |
| class=""> |
| 集群扩容缩容 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/resource-management" |
| class=""> |
| 资源管理 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/cold-backup" |
| class=""> |
| 冷备份 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/meta-recovery" |
| class=""> |
| 元数据恢复 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/replica-recovery" |
| class=""> |
| Replica 数据恢复 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/zk-migration" |
| class=""> |
| Zookeeper 迁移 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/table-migration" |
| class=""> |
| Table 迁移 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/table-soft-delete" |
| class=""> |
| Table 软删除 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/table-env" |
| class=""> |
| Table 环境变量 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/remote-commands" |
| class=""> |
| 远程命令 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/partition-split" |
| class=""> |
| Partition-Split |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/duplication" |
| class=""> |
| 跨机房同步 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/compression" |
| class=""> |
| 数据压缩 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/throttling" |
| class=""> |
| 流量控制 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/experiences" |
| class=""> |
| 运维经验 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/manual-compact" |
| class=""> |
| Manual Compact 功能 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/usage-scenario" |
| class=""> |
| Usage Scenario 功能 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/bad-disk" |
| class=""> |
| 坏盘检修 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/whitelist" |
| class=""> |
| Replica Server 白名单 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/backup-request" |
| class=""> |
| Backup Request |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/administration/hotspot-detection" |
| class=""> |
| 热点检测 |
| </a> |
| </li> |
| |
| </ul> |
| |
| </aside> |
| </div> |
| </div> |
| |
| <!-- main section --> |
| <div class="dashboard-main is-scrollable"> |
| <nav class="navbar is-hidden-desktop"> |
| <div class="navbar-brand"> |
| <a href="/zh/" class="navbar-item"> |
| <!-- Pegasus Icon --> |
| <img src="/assets/images/pegasus-square.png"> |
| </a> |
| <div class="navbar-item"> |
| |
| |
| <!--A simple language switch button that only supports zh and en.--> |
| <!--IF its language is zh, then switches to en.--> |
| |
| <!--If you don't want a url to be relativized, you can add a space explicitly into the href to |
| prevents a url from being relativized by polyglot.--> |
| <a class="button is-light is-outlined is-inverted" href=" /clients/python-client"><strong>En</strong></a> |
| |
| </div> |
| <a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navMenu"> |
| <!-- Appears in mobile mode only --> |
| <span aria-hidden="true"></span> |
| <span aria-hidden="true"></span> |
| <span aria-hidden="true"></span> |
| </a> |
| </div> |
| <div class="navbar-menu" id="navMenu"> |
| <div class="navbar-end"> |
| |
| <!--dropdown--> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a href="" |
| class="navbar-link "> |
| <span> |
| Pegasus 产品文档 |
| </span> |
| </a> |
| <div class="navbar-dropdown"> |
| |
| <a href="/zh/docs/downloads" |
| class="navbar-item "> |
| 下载 |
| </a> |
| |
| </div> |
| </div> |
| |
| <!--dropdown--> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a href="" |
| class="navbar-link "> |
| <span> |
| 编译构建 |
| </span> |
| </a> |
| <div class="navbar-dropdown"> |
| |
| <a href="/zh/docs/build/compile-by-docker" |
| class="navbar-item "> |
| 使用 Docker 完成编译(推荐) |
| </a> |
| |
| <a href="/zh/docs/build/compile-from-source" |
| class="navbar-item "> |
| 从源码编译 |
| </a> |
| |
| </div> |
| </div> |
| |
| <!--dropdown--> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a href="" |
| class="navbar-link "> |
| <span> |
| 客户端库 |
| </span> |
| </a> |
| <div class="navbar-dropdown"> |
| |
| <a href="/zh/clients/java-client" |
| class="navbar-item "> |
| Java 客户端 |
| </a> |
| |
| <a href="/zh/clients/cpp-client" |
| class="navbar-item "> |
| C++ 客户端 |
| </a> |
| |
| <a href="https://github.com/apache/incubator-pegasus/tree/master/go-client" |
| class="navbar-item "> |
| Golang 客户端 |
| </a> |
| |
| <a href="/zh/clients/python-client" |
| class="navbar-item is-active"> |
| Python 客户端 |
| </a> |
| |
| <a href="/zh/clients/node-client" |
| class="navbar-item "> |
| NodeJS 客户端 |
| </a> |
| |
| <a href="/zh/clients/scala-client" |
| class="navbar-item "> |
| Scala 客户端 |
| </a> |
| |
| </div> |
| </div> |
| |
| <!--dropdown--> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a href="" |
| class="navbar-link "> |
| <span> |
| 生态工具 |
| </span> |
| </a> |
| <div class="navbar-dropdown"> |
| |
| <a href="/zh/docs/tools/shell" |
| class="navbar-item "> |
| Pegasus Shell 工具 |
| </a> |
| |
| <a href="https://github.com/pegasus-kv/admin-cli" |
| class="navbar-item "> |
| 集群管理命令行 |
| </a> |
| |
| <a href="https://github.com/pegasus-kv/pegic" |
| class="navbar-item "> |
| 数据访问命令行 |
| </a> |
| |
| </div> |
| </div> |
| |
| <!--dropdown--> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a href="" |
| class="navbar-link "> |
| <span> |
| 用户接口 |
| </span> |
| </a> |
| <div class="navbar-dropdown"> |
| |
| <a href="/zh/api/ttl" |
| class="navbar-item "> |
| TTL |
| </a> |
| |
| <a href="/zh/api/single-atomic" |
| class="navbar-item "> |
| 单行原子操作 |
| </a> |
| |
| <a href="/zh/api/redis" |
| class="navbar-item "> |
| Redis 适配 |
| </a> |
| |
| <a href="/zh/api/geo" |
| class="navbar-item "> |
| GEO 支持 |
| </a> |
| |
| <a href="/zh/api/http" |
| class="navbar-item "> |
| HTTP 接口 |
| </a> |
| |
| </div> |
| </div> |
| |
| <!--dropdown--> |
| <div class="navbar-item has-dropdown is-hoverable"> |
| <a href="" |
| class="navbar-link "> |
| <span> |
| 高效运维 |
| </span> |
| </a> |
| <div class="navbar-dropdown"> |
| |
| <a href="/zh/administration/deployment" |
| class="navbar-item "> |
| 集群部署 |
| </a> |
| |
| <a href="/zh/administration/config" |
| class="navbar-item "> |
| 配置说明 |
| </a> |
| |
| <a href="/zh/administration/rebalance" |
| class="navbar-item "> |
| 负载均衡 |
| </a> |
| |
| <a href="/zh/administration/monitoring" |
| class="navbar-item "> |
| 可视化监控 |
| </a> |
| |
| <a href="/zh/administration/rolling-update" |
| class="navbar-item "> |
| 集群重启和升级 |
| </a> |
| |
| <a href="/zh/administration/scale-in-out" |
| class="navbar-item "> |
| 集群扩容缩容 |
| </a> |
| |
| <a href="/zh/administration/resource-management" |
| class="navbar-item "> |
| 资源管理 |
| </a> |
| |
| <a href="/zh/administration/cold-backup" |
| class="navbar-item "> |
| 冷备份 |
| </a> |
| |
| <a href="/zh/administration/meta-recovery" |
| class="navbar-item "> |
| 元数据恢复 |
| </a> |
| |
| <a href="/zh/administration/replica-recovery" |
| class="navbar-item "> |
| Replica 数据恢复 |
| </a> |
| |
| <a href="/zh/administration/zk-migration" |
| class="navbar-item "> |
| Zookeeper 迁移 |
| </a> |
| |
| <a href="/zh/administration/table-migration" |
| class="navbar-item "> |
| Table 迁移 |
| </a> |
| |
| <a href="/zh/administration/table-soft-delete" |
| class="navbar-item "> |
| Table 软删除 |
| </a> |
| |
| <a href="/zh/administration/table-env" |
| class="navbar-item "> |
| Table 环境变量 |
| </a> |
| |
| <a href="/zh/administration/remote-commands" |
| class="navbar-item "> |
| 远程命令 |
| </a> |
| |
| <a href="/zh/administration/partition-split" |
| class="navbar-item "> |
| Partition-Split |
| </a> |
| |
| <a href="/zh/administration/duplication" |
| class="navbar-item "> |
| 跨机房同步 |
| </a> |
| |
| <a href="/zh/administration/compression" |
| class="navbar-item "> |
| 数据压缩 |
| </a> |
| |
| <a href="/zh/administration/throttling" |
| class="navbar-item "> |
| 流量控制 |
| </a> |
| |
| <a href="/zh/administration/experiences" |
| class="navbar-item "> |
| 运维经验 |
| </a> |
| |
| <a href="/zh/administration/manual-compact" |
| class="navbar-item "> |
| Manual Compact 功能 |
| </a> |
| |
| <a href="/zh/administration/usage-scenario" |
| class="navbar-item "> |
| Usage Scenario 功能 |
| </a> |
| |
| <a href="/zh/administration/bad-disk" |
| class="navbar-item "> |
| 坏盘检修 |
| </a> |
| |
| <a href="/zh/administration/whitelist" |
| class="navbar-item "> |
| Replica Server 白名单 |
| </a> |
| |
| <a href="/zh/administration/backup-request" |
| class="navbar-item "> |
| Backup Request |
| </a> |
| |
| <a href="/zh/administration/hotspot-detection" |
| class="navbar-item "> |
| 热点检测 |
| </a> |
| |
| </div> |
| </div> |
| |
| </div> |
| </div> |
| </nav> |
| |
| <nav class="navbar is-hidden-mobile"> |
| <div class="navbar-start w-full"> |
| <div class="navbar-item pl-0 w-full"> |
| <!--TODO(wutao): Given the limitation of docsearch that couldn't handle multiple input, |
| I make searchbox only shown in desktop. Fix this issue when docsearch.js v3 released. |
| Related issue: https://github.com/algolia/docsearch/issues/230--> |
| <div id="docsearch"></div> |
| </div> |
| </div> |
| <div class="navbar-end"> |
| <div class="navbar-item"> |
| |
| |
| <!--A simple language switch button that only supports zh and en.--> |
| <!--IF its language is zh, then switches to en.--> |
| |
| <!--If you don't want a url to be relativized, you can add a space explicitly into the href to |
| prevents a url from being relativized by polyglot.--> |
| <a class="button is-light is-outlined is-inverted" href=" /clients/python-client"><strong>En</strong></a> |
| |
| </div> |
| </div> |
| </nav> |
| |
| <section class="hero is-info lg:mr-3"> |
| <div class="hero-body"> |
| |
| <p class="title is-size-2 is-centered">Python 客户端</p> |
| </div> |
| </section> |
| <section class="section" style="padding-top: 2rem;"> |
| <div class="content"> |
| <h1 id="pegasus-python-client">pegasus python client</h1> |
| |
| <h2 id="项目地址">项目地址</h2> |
| |
| <p><a href="https://github.com/apache/incubator-pegasus/tree/master/python-client">https://github.com/apache/incubator-pegasus/tree/master/python-client</a></p> |
| |
| <h2 id="版本要求">版本要求</h2> |
| |
| <p>Python 3.7+</p> |
| |
| <h2 id="安装">安装</h2> |
| |
| <p><code class="language-plaintext highlighter-rouge">pip3 install pypegasus3</code></p> |
| |
| <h2 id="使用">使用</h2> |
| |
| <p>pegasus python client使用了<a href="https://github.com/twisted/twisted">twisted</a>, 编写的代码会带有twisted的影子。</p> |
| |
| <h3 id="示例">示例</h3> |
| |
| <p>完整的示例请参考<a href="https://github.com/apache/incubator-pegasus/tree/master/python-client/sample.py">sample</a>。以下是简单的示例:</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#!/usr/bin/env python |
| # coding:utf-8 |
| |
| from pypegasus.pgclient import Pegasus |
| |
| from twisted.internet import reactor |
| from twisted.internet.defer import inlineCallbacks |
| |
| |
| @inlineCallbacks |
| def basic_test(): |
| # init |
| c = Pegasus(['127.0.0.1:34601', '127.0.0.1:34602'], 'temp') |
| |
| suc = yield c.init() |
| if not suc: |
| reactor.stop() |
| print('ERROR: connect pegasus server failed') |
| return |
| |
| # set |
| try: |
| ret = yield c.set('hkey1', 'skey1', 'value', 0, 500) |
| print('set ret: ', ret) |
| except Exception as e: |
| print(e) |
| |
| # get |
| ret = yield c.get('hkey1', 'skey1') |
| print('get ret: ', bytes.decode(ret)) |
| |
| reactor.stop() |
| |
| |
| if __name__ == "__main__": |
| reactor.callWhenRunning(basic_test) |
| reactor.run() |
| </code></pre></div></div> |
| |
| <h3 id="log配置文件">log配置文件</h3> |
| |
| <p>pegasus python client使用了<a href="https://docs.python.org/2/library/logging.html">logging</a>日志包,默认配置如下:</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[loggers] |
| keys=root |
| [logger_root] |
| level=INFO |
| handlers=hand01 |
| propagate=0 |
| [handlers] |
| keys=hand01 |
| [handler_hand01] |
| class=handlers.RotatingFileHandler |
| formatter=form01 |
| args=('pegasus.log', 'a', 100*1024*1024, 10) |
| [formatters] |
| keys=form01 |
| [formatter_form01] |
| format=%(asctime)s [%(thread)d] [%(levelname)s] %(filename)s:%(lineno)d %(message)s |
| datefmt=%Y-%m-%d %H:%M:%S |
| </code></pre></div></div> |
| |
| <p>如果用户有定制需求,可以在自己的代码目录添加配置文件<code class="language-plaintext highlighter-rouge">logger.conf</code></p> |
| |
| <h3 id="api说明">API说明</h3> |
| |
| <h4 id="初始化">初始化</h4> |
| |
| <p>初始化先构造Pegasus对象,在使用init函数完成初始化:</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class Pegasus(object): |
| """ |
| Pegasus client class. |
| """ |
| |
| def __init__(self, meta_addrs=None, table_name='', |
| timeout=DEFAULT_TIMEOUT): |
| """ |
| :param meta_addrs: (list) pagasus meta servers list. |
| example: ['127.0.0.1:34601', '127.0.0.1:34602', '127.0.0.1:34603'] |
| :param table_name: (bytes) table name/app name used in pegasus. |
| :param timeout: (int) default timeout in milliseconds when communicate with meta sever and replica server. |
| """ |
| </code></pre></div></div> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> def init(self): |
| """ |
| Initialize the client before you can use it. |
| |
| :return: (DeferredList) True when initialized succeed, others when failed. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="ttl">ttl</h4> |
| |
| <p>判断key的剩余的ttl时间</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def ttl(self, hash_key, sort_key, timeout=0): |
| """ |
| Get ttl(time to live) of the data. |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param sort_key: (bytes) which sort key used for this API. |
| :param timeout: (int) how long will the operation timeout in milliseconds. |
| if timeout > 0, it is a timeout value for current operation, |
| else the timeout value specified to create the instance will be used. |
| :return: (tuple<error_types.code.value, int>) (code, ttl) |
| code: error_types.ERR_OK.value when data exist, error_types.ERR_OBJECT_NOT_FOUND.value when data not found. |
| ttl: in seconds, -1 means forever. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="exist">exist</h4> |
| |
| <p>判断key是否存在</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def exist(self, hash_key, sort_key, timeout=0): |
| """ |
| Check value exist. |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param sort_key: (bytes) which sort key used for this API. |
| :param timeout: (int) how long will the operation timeout in milliseconds. |
| if timeout > 0, it is a timeout value for current operation, |
| else the timeout value specified to create the instance will be used. |
| :return: (tuple<error_types.code.value, None>) (code, ign) |
| code: error_types.ERR_OK.value when data exist, error_types.ERR_OBJECT_NOT_FOUND.value when data not found. |
| ign: useless, should be ignored. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="set">set</h4> |
| |
| <p>插入一条数据(若已存在则会覆盖)</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def set(self, hash_key, sort_key, value, ttl=0, timeout=0): |
| """ |
| Set value to be stored in <hash_key, sort_key>. |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param sort_key: (bytes) which sort key used for this API. |
| :param value: (bytes) value to be stored under <hash_key, sort_key>. |
| :param ttl: (int) ttl(time to live) in seconds of this data. |
| :param timeout: (int) how long will the operation timeout in milliseconds. |
| if timeout > 0, it is a timeout value for current operation, |
| else the timeout value specified to create the instance will be used. |
| :return: (tuple<error_types.code.value, None>) (code, ign) |
| code: error_types.ERR_OK.value when data stored succeed. |
| ign: useless, should be ignored. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="multi_set">multi_set</h4> |
| |
| <p>同时写一条hashkey的多条sortkey数据</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def multi_set(self, hash_key, sortkey_value_dict, ttl=0, timeout=0): |
| """ |
| Set multiple sort_keys-values under hash_key to be stored. |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param sortkey_value_dict: (dict) <sort_key, value> pairs in dict. |
| :param ttl: (int) ttl(time to live) in seconds of these data. |
| :param timeout: (int) how long will the operation timeout in milliseconds. |
| if timeout > 0, it is a timeout value for current operation, |
| else the timeout value specified to create the instance will be used. |
| :return: (tuple<error_types.code.value, _>) (code, ign) |
| code: error_types.ERR_OK.value when data stored succeed. |
| ign: useless, should be ignored. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="get">get</h4> |
| |
| <p>获取一条数据</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def get(self, hash_key, sort_key, timeout=0): |
| """ |
| Get value stored in <hash_key, sort_key>. |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param sort_key: (bytes) which sort key used for this API. |
| :param timeout: (int) how long will the operation timeout in milliseconds. |
| if timeout > 0, it is a timeout value for current operation, |
| else the timeout value specified to create the instance will be used. |
| :return: (tuple<error_types.code.value, bytes>) (code, value). |
| code: error_types.ERR_OK.value when data got succeed, error_types.ERR_OBJECT_NOT_FOUND.value when data not found. |
| value: data stored in this <hash_key, sort_key> |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="multi_get">multi_get</h4> |
| |
| <p>同时读一条hashkey的多条sortkey数据</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def multi_get(self, hash_key, |
| sortkey_set, |
| max_kv_count=100, |
| max_kv_size=1000000, |
| no_value=False, |
| timeout=0): |
| """ |
| Get multiple values stored in <hash_key, sortkey> pairs. |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param sortkey_set: (set) sort keys in set. |
| :param max_kv_count: (int) max count of k-v pairs to be fetched. max_fetch_count <= 0 means no limit. |
| :param max_kv_size: (int) max total data size of k-v pairs to be fetched. max_fetch_size <= 0 means no limit. |
| :param no_value: (bool) whether to fetch value of these keys. |
| :param timeout: (int) how long will the operation timeout in milliseconds. |
| if timeout > 0, it is a timeout value for current operation, |
| else the timeout value specified to create the instance will be used. |
| :return: (tuple<error_types.code.value, dict>) (code, kvs) |
| code: error_types.ERR_OK.value when data got succeed. |
| kvs: <sort_key, value> pairs in dict. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="multi_get_opt">multi_get_opt</h4> |
| |
| <p>同时读一条hashkey的多条sortkey数据, 读取的数据根据<code class="language-plaintext highlighter-rouge">multi_get_options</code>参数指定的模式确定。</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def multi_get_opt(self, hash_key, |
| start_sort_key, stop_sort_key, |
| multi_get_options, |
| max_kv_count=100, |
| max_kv_size=1000000, |
| timeout=0): |
| """ |
| Get multiple values stored in hash_key, and sort key range in [start_sort_key, stop_sort_key) as default. |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param start_sort_key: (bytes) returned k-v pairs is start from start_sort_key. |
| :param stop_sort_key: (bytes) returned k-v pairs is stop at stop_sort_key. |
| :param multi_get_options: (MultiGetOptions) configurable multi_get options. |
| :param max_kv_count: (int) max count of k-v pairs to be fetched. max_fetch_count <= 0 means no limit. |
| :param max_kv_size: (int) max total data size of k-v pairs to be fetched. max_fetch_size <= 0 means no limit. |
| :param timeout: (int) how long will the operation timeout in milliseconds. |
| if timeout > 0, it is a timeout value for current operation, |
| else the timeout value specified to create the instance will be used. |
| :return: (tuple<error_types.code.value, dict>) (code, kvs) |
| code: error_types.ERR_OK.value when data got succeed. |
| kvs: <sort_key, value> pairs in dict. |
| """ |
| </code></pre></div></div> |
| |
| <p>其中,<code class="language-plaintext highlighter-rouge">MultiGetOptions</code>可以指定sortkey的范围、是否包含边界、子串匹配、是否返回value、是否逆序等,具体定义如下:</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class MultiGetOptions(object): |
| """ |
| configurable options for multi_get. |
| """ |
| |
| def __init__(self): |
| self.start_inclusive = True |
| self.stop_inclusive = False |
| self.sortkey_filter_type = filter_type.FT_NO_FILTER |
| self.sortkey_filter_pattern = "" |
| self.no_value = False |
| self.reverse = False |
| |
| class filter_type: |
| FT_NO_FILTER = 0 |
| FT_MATCH_ANYWHERE = 1 |
| FT_MATCH_PREFIX = 2 |
| FT_MATCH_POSTFIX = 3 |
| </code></pre></div></div> |
| |
| <h4 id="remove">remove</h4> |
| |
| <p>删除一条数据</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def remove(self, hash_key, sort_key, timeout=0): |
| """ |
| Remove the entire <hash_key, sort_key>-value in pegasus. |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param sort_key: (bytes) which sort key used for this API. |
| :param timeout: (int) how long will the operation timeout in milliseconds. |
| if timeout > 0, it is a timeout value for current operation, |
| else the timeout value specified to create the instance will be used. |
| :return: (tuple<error_types.code.value, None>) (code, ign) |
| code: error_types.ERR_OK.value when data stored succeed. |
| ign: useless, should be ignored. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="multi_del">multi_del</h4> |
| |
| <p>批量删除一个hashkey下的多条sortkey数据</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def multi_del(self, hash_key, sortkey_set, timeout=0): |
| """ |
| Remove multiple entire <hash_key, sort_key>-values in pegasus. |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param sortkey_set: (set) sort keys in set. |
| :param timeout: (int) how long will the operation timeout in milliseconds. |
| if timeout > 0, it is a timeout value for current operation, |
| else the timeout value specified to create the instance will be used. |
| :return: (tuple<error_types.code.value, int>) (code, count). |
| code: error_types.ERR_OK.value when data got succeed. |
| count: count of deleted k-v pairs. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="sort_key_count">sort_key_count</h4> |
| |
| <p>获取一个hashkey下的sortkey数量</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def sort_key_count(self, hash_key, timeout=0): |
| """ |
| Get the total sort key count under the hash_key. |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param timeout: (int) how long will the operation timeout in milliseconds. |
| if timeout > 0, it is a timeout value for current operation, |
| else the timeout value specified to create the instance will be used. |
| :return: (tuple<error_types.code.value, count>) (code, count) |
| code: error_types.ERR_OK.value when data got succeed, error_types.ERR_OBJECT_NOT_FOUND.value when data not found. |
| value: total sort key count under the hash_key. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="get_sort_keys">get_sort_keys</h4> |
| |
| <p>获取一个hashkey下的sortkey值</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def get_sort_keys(self, hash_key, |
| max_kv_count=100, |
| max_kv_size=1000000, |
| timeout=0): |
| """ |
| Get multiple sort keys under hash_key. |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param max_kv_count: (int) max count of k-v pairs to be fetched. max_fetch_count <= 0 means no limit. |
| :param max_kv_size: (int) max total data size of k-v pairs to be fetched. max_fetch_size <= 0 means no limit. |
| :param timeout: (int) how long will the operation timeout in milliseconds. |
| if timeout > 0, it is a timeout value for current operation, |
| else the timeout value specified to create the instance will be used. |
| :return: (tuple<error_types.code.value, set>) (code, ks) |
| code: error_types.ERR_OK.value when data got succeed. |
| ks: <sort_key, ign> pairs in dict, ign will always be empty bytes. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="get_scanner">get_scanner</h4> |
| |
| <p>获取scanner对象,用于指定范围的数据扫描。可以通过<code class="language-plaintext highlighter-rouge">scan_options</code>参数指定扫描的模式。</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def get_scanner(self, hash_key, |
| start_sort_key, stop_sort_key, |
| scan_options): |
| """ |
| Get scanner for hash_key, start from start_sort_key, and stop at stop_sort_key. |
| Whether the scanner include the start_sort_key and stop_sort_key is configurable by scan_options |
| |
| :param hash_key: (bytes) which hash key used for this API. |
| :param start_sort_key: (bytes) returned scanner is start from start_sort_key. |
| :param stop_sort_key: (bytes) returned scanner is stop at stop_sort_key. |
| :param scan_options: (ScanOptions) configurable scan options. |
| :return: (PegasusScanner) scanner, instance of PegasusScanner. |
| """ |
| </code></pre></div></div> |
| |
| <p>其中,<code class="language-plaintext highlighter-rouge">ScanOptions</code>可以指定是否包含边界、超时时间、一次从replica server批量获取的sortkey-value数量等,具体定义如下:</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class ScanOptions(object): |
| """ |
| configurable options for scan. |
| """ |
| |
| def __init__(self): |
| self.timeout_millis = 5000 |
| self.batch_size = 1000 |
| self.start_inclusive = True |
| self.stop_inclusive = False |
| self.snapshot = None # for future use |
| </code></pre></div></div> |
| |
| <h4 id="get_unordered_scanners">get_unordered_scanners</h4> |
| |
| <p>一次性获取多个scanner,用于整个table的数据扫描。可以通过<code class="language-plaintext highlighter-rouge">scan_options</code>参数指定扫描的模式。</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def get_unordered_scanners(self, max_split_count, scan_options): |
| """ |
| Get scanners for the whole pegasus table. |
| |
| :param max_split_count: (int) max count of scanners will be returned. |
| :param scan_options: (ScanOptions) configurable scan options. |
| :return: (list) instance of PegasusScanner list. |
| each scanner in this list can scan separate part of the whole pegasus table. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="scanner对象">scanner对象</h4> |
| |
| <p>用于数据扫描的对象,由<code class="language-plaintext highlighter-rouge">get_scanner</code>和<code class="language-plaintext highlighter-rouge">get_unordered_scanners</code>返回。使用它的<code class="language-plaintext highlighter-rouge">next</code>函数执行扫描过程。</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class PegasusScanner(object): |
| """ |
| Pegasus scanner class, used for scanning data in pegasus table. |
| """ |
| </code></pre></div></div> |
| |
| <h4 id="get_next">get_next</h4> |
| |
| <p>获取扫描得到的数据,需要循环执行,直到返回<code class="language-plaintext highlighter-rouge">None</code>结束扫描。</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>def get_next(self): |
| """ |
| scan the next k-v pair for the scanner. |
| :return: (tuple<tuple<hash_key, sort_key>, value> or None) |
| all the sort_keys returned by this API are in ascend order. |
| """ |
| </code></pre></div></div> |
| |
| </div> |
| </section> |
| <footer class="footer"> |
| <div class="container"> |
| <div class="content is-small has-text-centered"> |
| <div style="margin-bottom: 20px;"> |
| <a href="http://incubator.apache.org"> |
| <img src="/assets/images/egg-logo.png" |
| width="15%" |
| alt="Apache Incubator"/> |
| </a> |
| </div> |
| Copyright © 2023 <a href="http://www.apache.org">The Apache Software Foundation</a>. |
| Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version |
| 2.0</a>. |
| <br><br> |
| |
| Apache Pegasus is an effort undergoing incubation at The Apache Software Foundation (ASF), |
| sponsored by the Apache Incubator. Incubation is required of all newly accepted projects |
| until a further review indicates that the infrastructure, communications, and decision making process |
| have stabilized in a manner consistent with other successful ASF projects. While incubation status is |
| not necessarily a reflection of the completeness or stability of the code, it does indicate that the |
| project has yet to be fully endorsed by the ASF. |
| |
| <br><br> |
| Apache Pegasus, Pegasus, Apache, the Apache feather logo, and the Apache Pegasus project logo are either |
| registered trademarks or trademarks of The Apache Software Foundation in the United States and other |
| countries. |
| </div> |
| </div> |
| </footer> |
| </div> |
| |
| <!-- right panel --> |
| <div class="dashboard-panel is-small is-scrollable is-hidden-mobile"> |
| <p class="menu-label"> |
| <span class="icon"> |
| <i class="fa fa-bars" aria-hidden="true"></i> |
| </span> |
| 本页导航 |
| </p> |
| <ul class="menu-list"> |
| <li><a href="#pegasus-python-client">pegasus python client</a> |
| <ul> |
| <li><a href="#项目地址">项目地址</a></li> |
| <li><a href="#版本要求">版本要求</a></li> |
| <li><a href="#安装">安装</a></li> |
| <li><a href="#使用">使用</a> |
| <ul> |
| <li><a href="#示例">示例</a></li> |
| <li><a href="#log配置文件">log配置文件</a></li> |
| <li><a href="#api说明">API说明</a> |
| <ul> |
| <li><a href="#初始化">初始化</a></li> |
| <li><a href="#ttl">ttl</a></li> |
| <li><a href="#exist">exist</a></li> |
| <li><a href="#set">set</a></li> |
| <li><a href="#multi_set">multi_set</a></li> |
| <li><a href="#get">get</a></li> |
| <li><a href="#multi_get">multi_get</a></li> |
| <li><a href="#multi_get_opt">multi_get_opt</a></li> |
| <li><a href="#remove">remove</a></li> |
| <li><a href="#multi_del">multi_del</a></li> |
| <li><a href="#sort_key_count">sort_key_count</a></li> |
| <li><a href="#get_sort_keys">get_sort_keys</a></li> |
| <li><a href="#get_scanner">get_scanner</a></li> |
| <li><a href="#get_unordered_scanners">get_unordered_scanners</a></li> |
| <li><a href="#scanner对象">scanner对象</a></li> |
| <li><a href="#get_next">get_next</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| |
| </div> |
| </div> |
| |
| <script src="/assets/js/app.js" type="text/javascript"></script> |
| <script> |
| docsearch({ |
| container: '#docsearch', |
| appId: 'QRN30RBW0S', |
| indexName: 'pegasus-apache', |
| apiKey: 'd3a3252fa344359766707a106c4ed88f', |
| debug: true |
| }); |
| </script> |
| |
| </body> |
| |
| </html> |