| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <title>Pegasus | Redis</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>Redis | Pegasus</title> |
| <meta name="generator" content="Jekyll v4.3.3" /> |
| <meta property="og:title" content="Redis" /> |
| <meta property="og:locale" content="en_US" /> |
| <meta name="description" content="Redis 适配" /> |
| <meta property="og:description" content="Redis 适配" /> |
| <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="Redis" /> |
| <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":"Redis 适配","headline":"Redis","mainEntityOfPage":{"@type":"WebPage","@id":"/api/redis"},"url":"/api/redis"}</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=""> |
| 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="is-active"> |
| 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=" /api/redis"><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 "> |
| 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 is-active"> |
| 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=" /api/redis"><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">Redis 适配</p> |
| </div> |
| </section> |
| <section class="section" style="padding-top: 2rem;"> |
| <div class="content"> |
| <h1 id="redis-适配">Redis 适配</h1> |
| |
| <h2 id="架构">架构</h2> |
| |
| <p>在 Pegasus 集群中部署 Redis Proxy 组件后,用户可以通过 Redis 协议直接访问 Redis Proxy,从而间接访问 Pegasus 服务,从而实现使用 Redis 客户端访问 Pegasus 服务的目的。</p> |
| |
| <p>整体架构如下:</p> |
| |
| <p><img src="/assets/images/redis_proxy_arch.png" alt="redis_proxy_arch.png" class="img-responsive" /></p> |
| |
| <p>Redis 客户端与 Redis Proxy 之间使用<a href="https://redis.io/topics/protocol">redis协议</a>,目前 Proxy 已支持所有的 RESP2 <a href="https://redis.io/docs/reference/protocol-spec/">协议</a>数据类型(即:Simple Strings、Errors、Integers、Bulk Strings、Arrays)。</p> |
| |
| <p>Redis Proxy 与 Pegasus 集群之间使用 Pegasus 的协议,Proxy 在这里就类似一个普通的 Pegasus Client,从 Meta Server 查询路由信息、与 Replica Server 进行用户数据的读写。</p> |
| |
| <h2 id="提供服务的形式">提供服务的形式</h2> |
| |
| <p>跟 Redis 服务一样,Proxy 实例以 <code class="language-plaintext highlighter-rouge">host:port</code> 形式提供。如果服务压力大,可以提供多个 Proxy 实例,通过水平扩展的方式来提升服务吞吐量。</p> |
| |
| <p>Proxy 是无状态的,多个 Proxy 实例共享同一个后端 Pegasus 服务。可以采用round-robin, hash等方式进行负载均衡。</p> |
| |
| <blockquote> |
| <p>Proxy 的可执行文件为 <code class="language-plaintext highlighter-rouge">pegasus_rproxy</code>,由 <code class="language-plaintext highlighter-rouge">./run.sh pack_tools</code> <a href="/zh/docs/build/compile-by-docker/#编译打包">打包</a>生成。</p> |
| </blockquote> |
| |
| <h2 id="配置">配置</h2> |
| |
| <p>Redis Proxy 的配置文件规则遵循<a href="/zh/administration/config">配置说明</a>,参考<a href="https://github.com/apache/incubator-pegasus/blob/master/src/redis_protocol/proxy/config.ini">示例</a>。</p> |
| |
| <p>在 Proxy 中有几项特有的配置项需要注意:</p> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[apps.proxy] |
| name = proxy |
| type = proxy |
| ; which pegasus cluster and table dose this proxy redirect to |
| ; - 'onebox': the cluster name which will be used in the next section |
| ; - 'temp': the table name in the cluster |
| |
| arguments = onebox temp |
| ; if using GEO APIs, an extra table name which will store geo index data |
| ; should be appended, i.e. |
| ; arguments = onebox temp temp_geo |
| |
| ; port serve for redis clients |
| ports = 6379 |
| pools = THREAD_POOL_DEFAULT |
| run = true |
| |
| [pegasus.clusters] |
| ; meta serer list the proxy redirect to |
| onebox = 127.0.0.1:34601,127.0.0.1:34602,127.0.0.1:34603 |
| </code></pre></div></div> |
| |
| <h2 id="apis">APIs</h2> |
| |
| <p>Redis 的原生命令请见<a href="https://redis.io/commands">这里</a> 。</p> |
| |
| <p>以下命令都兼容 Redis 原生命令,但支持的参数可能少于 Redis。</p> |
| |
| <blockquote> |
| <p>以下文档中都给出了目前 Pegasus Redis Proxy 所支持的所有参数,未给出的目前不支持。</p> |
| </blockquote> |
| |
| <h3 id="协议">协议</h3> |
| |
| <h4 id="strings-api">Strings API</h4> |
| |
| <p>对于 Redis 的 <a href="https://redis.io/docs/data-types/strings/">strings</a> 操作,key 对应到 Pegasus 中的 hashkey,而 Pegasus 中的 sortkey 被设置为空串 <code class="language-plaintext highlighter-rouge">""</code>。</p> |
| |
| <p>支持的命令如:<code class="language-plaintext highlighter-rouge">SET</code>, <code class="language-plaintext highlighter-rouge">GET</code>, <code class="language-plaintext highlighter-rouge">TTL</code>, <code class="language-plaintext highlighter-rouge">INCR</code>等。</p> |
| |
| <h4 id="geo-api">GEO API</h4> |
| |
| <p><a href="geo">GEO命令的实现原理</a></p> |
| |
| <p>在 Redis 中,<a href="https://redis.io/docs/data-types/geospatial/">GEO</a> 命令操作的数据是通过 <a href="https://redis.io/commands/geoadd/">GEOADD</a>,即 <code class="language-plaintext highlighter-rouge">GEOADD key longitude latitude member</code>,添加到数据库中的。此处的 <code class="language-plaintext highlighter-rouge">key</code> 是一个 namespace 的概念,而不是 <code class="language-plaintext highlighter-rouge">SET</code> 操作时的 key。</p> |
| |
| <p>而在 Pegasus Proxy 中,由于底层的实现原理不同,他的 <code class="language-plaintext highlighter-rouge">GEO*</code> 命令操作的数据是通过 <code class="language-plaintext highlighter-rouge">SET</code> 命令添加到数据库中的,<code class="language-plaintext highlighter-rouge">SET</code> 的 key 对应于 <code class="language-plaintext highlighter-rouge">GEO*</code> 命令的 member,而 <code class="language-plaintext highlighter-rouge">GEO*</code> 命令的 key 则只能是空串 <code class="language-plaintext highlighter-rouge">""</code>。</p> |
| |
| <p>也就是说,在 Pegasus 的 Redis GEO 数据中,不再有 namespace 的概念,全部数据在同一空间 <code class="language-plaintext highlighter-rouge">""</code> 下。若要区分 namespace,可以在 Pegasus 中创建新的表来实现。</p> |
| |
| <p><code class="language-plaintext highlighter-rouge">SET</code> 的 value 格式参考<a href="/zh/api/geo#value-extractor">Value Extrator</a>。</p> |
| |
| <h3 id="set">SET</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>SET key value [EX seconds] |
| </code></pre></div></div> |
| |
| <h3 id="get">GET</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>GET key |
| </code></pre></div></div> |
| |
| <h3 id="del">DEL</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>DEL key |
| </code></pre></div></div> |
| |
| <p><strong>注意:</strong></p> |
| |
| <p>当一条 key 不存在时,Pegasus Proxy 的返回值和 Redis 略有不同:</p> |
| <ul> |
| <li>Redis:返回 0,表示本次没有删除有效数据</li> |
| <li>Pegasus Proxy:由于没有对不存在和删除成功做区别,都统一返回的 1</li> |
| </ul> |
| |
| <h3 id="setex">SETEX</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>SETEX key seconds value |
| </code></pre></div></div> |
| |
| <h3 id="ttl">TTL</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>TTL key |
| </code></pre></div></div> |
| |
| <h3 id="pttl">PTTL</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>PTTL key |
| </code></pre></div></div> |
| |
| <h3 id="incr">INCR</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>INCR key |
| </code></pre></div></div> |
| |
| <h3 id="incrby">INCRBY</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>INCRBY key increment |
| </code></pre></div></div> |
| |
| <h3 id="decr">DECR</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>DECR key |
| </code></pre></div></div> |
| |
| <h3 id="decrby">DECRBY</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>DECRBY key decrement |
| </code></pre></div></div> |
| |
| <h3 id="geodist">GEODIST</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>GEODIST key member1 member2 [unit] |
| </code></pre></div></div> |
| |
| <p><strong>注意:</strong></p> |
| |
| <ul> |
| <li>key 规则遵循 GEO API 的 key 规则,即 key 只能是空串 <code class="language-plaintext highlighter-rouge">""</code>,而这里 member 对应于 <code class="language-plaintext highlighter-rouge">SET</code> 操作时的 key</li> |
| </ul> |
| |
| <h3 id="georadius">GEORADIUS</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD][WITHDIST] [WITHHASH][COUNT count] [ASC|DESC] |
| </code></pre></div></div> |
| |
| <p><strong>注意:</strong></p> |
| <ul> |
| <li>key 规则遵循上述 Pegasus Proxy 的 GEO 命令的 key 规则,即 key 只能是空串 <code class="language-plaintext highlighter-rouge">""</code>,而这里 member 对应于 <code class="language-plaintext highlighter-rouge">SET</code> 操作时的 key</li> |
| <li>Pegasus 对 Redis 的 <code class="language-plaintext highlighter-rouge">WITHHASH</code> 参数进行了修改,使用它将会返回该 member 的 value 值</li> |
| </ul> |
| |
| <h3 id="georadiusbymember">GEORADIUSBYMEMBER</h3> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD][WITHDIST] [WITHHASH][COUNT count] [ASC|DESC] |
| </code></pre></div></div> |
| |
| <p><strong>注意:</strong></p> |
| <ul> |
| <li>key 规则遵循 GEO API 的 key 规则,即 key 只能是空串 <code class="language-plaintext highlighter-rouge">""</code>,而这里 member 对应于 <code class="language-plaintext highlighter-rouge">SET</code> 操作时的 key</li> |
| <li>Pegasus 对 Redis 的 <code class="language-plaintext highlighter-rouge">WITHHASH</code> 参数进行了修改,使用它将会返回该 member 的 value 值</li> |
| </ul> |
| |
| <h2 id="示例">示例</h2> |
| |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>// Strings API 使用示例 |
| 127.0.0.1:6379> SET abc 1 EX 60 |
| OK |
| |
| 127.0.0.1:6379> GET abc |
| "1" |
| |
| 127.0.0.1:6379> TTL abc |
| (integer) 52 |
| |
| 127.0.0.1:6379> INCR abc |
| (integer) 2 |
| |
| // GEO API 使用示例 |
| 127.0.0.1:6379> SET 1cc0001000010290050356f "1cc0001000010290050356f|2018-06-10 23:59:59|2018-06-11 13:00:00|wx5j5ff05|116.886447|40.269031|4.863045|20.563248|0|-1" |
| OK |
| |
| 127.0.0.1:6379> SET 2cc0001000010290050356f "2cc0001000010290050356f|2018-06-10 23:59:59|2018-06-11 13:00:00|wx5j5ff05|115.886447|41.269031|4.863045|20.563248|0|-1" |
| OK |
| |
| 127.0.0.1:6379> GEORADIUS "" 116.889137 40.261774 1000 m COUNT 100 ASC WITHDIST WITHCOORD |
| 1) 1) "1cc0001000010290050356f" |
| 2) "838.600772" |
| 3) 1) "116.886447" |
| 2) "40.269031" |
| 4) "1cc0001000010290050356f|2018-06-10 23:59:59|2018-06-11 13:00:00|wx5j5ff05|116.886447|40.269031|4.863045|20.563248|0|-1" |
| |
| 127.0.0.1:6379> GEORADIUSBYMEMBER "" 1cc0001000010290050356f 1000 m WITHCOORD WITHDIST WITHHASH |
| 1) 1) "1cc0001000010290050356f" |
| 2) "0.000000" |
| 3) 1) "116.886447" |
| 2) "40.269031" |
| 4) "1cc0001000010290050356f|2018-06-10 23:59:59|2018-06-11 13:00:00|wx5j5ff05|116.886447|40.269031|4.863045|20.563248|0|-1" |
| |
| 127.0.0.1:6379> GEODIST "" 1cc0001000010290050356f 2cc0001000010290050356f m |
| "139483.293598" |
| </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="#redis-适配">Redis 适配</a> |
| <ul> |
| <li><a href="#架构">架构</a></li> |
| <li><a href="#提供服务的形式">提供服务的形式</a></li> |
| <li><a href="#配置">配置</a></li> |
| <li><a href="#apis">APIs</a> |
| <ul> |
| <li><a href="#协议">协议</a> |
| <ul> |
| <li><a href="#strings-api">Strings API</a></li> |
| <li><a href="#geo-api">GEO API</a></li> |
| </ul> |
| </li> |
| <li><a href="#set">SET</a></li> |
| <li><a href="#get">GET</a></li> |
| <li><a href="#del">DEL</a></li> |
| <li><a href="#setex">SETEX</a></li> |
| <li><a href="#ttl">TTL</a></li> |
| <li><a href="#pttl">PTTL</a></li> |
| <li><a href="#incr">INCR</a></li> |
| <li><a href="#incrby">INCRBY</a></li> |
| <li><a href="#decr">DECR</a></li> |
| <li><a href="#decrby">DECRBY</a></li> |
| <li><a href="#geodist">GEODIST</a></li> |
| <li><a href="#georadius">GEORADIUS</a></li> |
| <li><a href="#georadiusbymember">GEORADIUSBYMEMBER</a></li> |
| </ul> |
| </li> |
| <li><a href="#示例">示例</a></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> |