多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# redis - 通用命令执行 ``` <pre class="calibre14">``` $redis<span class="token">-</span><span class="token">></span><span class="token1">rawCommand</span><span class="token2">(</span><span class="token4">"zadd"</span><span class="token2">,</span><span class="token4">'id'</span><span class="token2">,</span><span class="token3">10</span> <span class="token2">,</span><span class="token4">'tom'</span> <span class="token2">,</span><span class="token3">20</span> <span class="token2">,</span><span class="token4">'ma'</span> <span class="token2">,</span><span class="token3">90</span><span class="token2">,</span> <span class="token4">"liu"</span><span class="token2">)</span> ``` ``` ``` <pre class="calibre16">``` $redis <span class="token">=</span> <span class="token5">new</span> <span class="token1">Redis</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">connect</span><span class="token2">(</span><span class="token4">'127.0.0.1'</span><span class="token2">,</span><span class="token3">6379</span><span class="token2">,</span><span class="token3">1</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//短链接 $redis->pconnect('127.0.0.1',6379,1);长连接</span> <span class="token6">//$redis->auth('password'); //登录密码</span> <span class="token6">//$redis->select(0);//选择数据库0-15</span> <span class="token6">//$redis->close();</span> <span class="token6">//$redis->ttl('key');//查看失效时间,-1是永久 $redis->pttl('key');毫秒</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">persist</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">)</span><span class="token2">;</span>删除失效时间 $redis<span class="token">-</span><span class="token">></span><span class="token1">ping</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//成功返回+PONG,检查链接</span> $key <span class="token">=</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">randomKey</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//返回随机key</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">select</span><span class="token2">(</span><span class="token3">0</span><span class="token2">)</span> 选择一个数据库<span class="token3">0</span><span class="token">-</span><span class="token3">15</span> 正常返回<span class="token3">true</span>失败<span class="token3">false</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">move</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span><span class="token3">1</span><span class="token2">)</span>移动数据key到数据库<span class="token3">1</span><span class="token2">,</span>成功<span class="token3">true</span><span class="token2">,</span>失败<span class="token3">false</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">rename</span><span class="token2">(</span><span class="token4">'x'</span><span class="token2">,</span> <span class="token4">'y'</span><span class="token2">)</span><span class="token2">;</span>重命名$redis<span class="token">-</span><span class="token">></span><span class="token1">renameNx</span><span class="token2">(</span><span class="token4">'x'</span><span class="token2">,</span> <span class="token4">'y'</span><span class="token2">)</span><span class="token2">;</span>功能一样 $redis<span class="token">-</span><span class="token">></span><span class="token1">expire</span><span class="token2">(</span><span class="token4">'x'</span><span class="token2">,</span> <span class="token3">3</span><span class="token2">)</span><span class="token2">;</span> 过期时间<span class="token3">3</span>秒 $redis<span class="token">-</span><span class="token">></span><span class="token1">expire</span><span class="token2">(</span><span class="token4">'x'</span><span class="token2">,</span> <span class="token3">3000</span><span class="token2">)</span><span class="token2">;</span>过期时间<span class="token3">3</span>秒<span class="token2">,</span>单位毫秒 $redis<span class="token">-</span><span class="token">></span><span class="token1">expireAt</span><span class="token2">(</span><span class="token4">'x'</span><span class="token2">,</span> $now <span class="token">+</span> <span class="token3">3</span><span class="token2">)</span><span class="token2">;</span>过期时间戳 $redis<span class="token">-</span><span class="token">></span><span class="token1">expireAt</span><span class="token2">(</span><span class="token4">'x'</span><span class="token2">,</span> $now <span class="token">+</span> <span class="token3">3000</span><span class="token2">)</span><span class="token2">;</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">keys</span><span class="token2">(</span><span class="token4">'*'</span><span class="token2">)</span> 获取全部键 也支持user<span class="token">*</span>模糊查询 $redis<span class="token">-</span><span class="token">></span><span class="token1">dbSize</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> 数据key数量 $redis<span class="token">-</span><span class="token">></span><span class="token1">bgrewriteaof</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>AOF持久化 $redis<span class="token">-</span><span class="token">></span><span class="token1">save</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>同步 RDB持久化保存 $redis<span class="token">-</span><span class="token">></span><span class="token1">bgSave</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>异步 $redis<span class="token">-</span><span class="token">></span><span class="token1">type</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">)</span><span class="token2">;</span>返回类型<span class="token3">5</span>hash <span class="token3">4</span>zset <span class="token3">2</span>set <span class="token3">3</span>list <span class="token3">1</span>string $redis<span class="token">-</span><span class="token">></span><span class="token1">flushDB</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> 删除当前所有key<span class="token2">,</span>慎用 $redis<span class="token">-</span><span class="token">></span><span class="token1">flushAll</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>全部删除<span class="token2">,</span>非常危险<span class="token2">,</span>生产环境禁用 $redis<span class="token">-</span><span class="token">></span><span class="token1">sort</span><span class="token2">(</span><span class="token4">'s'</span><span class="token2">,</span><span class="token2">[</span><span class="token4">'sort'</span><span class="token">=</span><span class="token">></span><span class="token4">"desc"</span><span class="token2">,</span><span class="token4">'store'</span><span class="token">=</span><span class="token">></span><span class="token4">'k1'</span><span class="token2">,</span><span class="token4">'limit'</span><span class="token">=</span><span class="token">></span><span class="token2">[</span><span class="token3">0</span><span class="token2">,</span><span class="token3">1</span><span class="token2">]</span><span class="token2">]</span><span class="token2">)</span> 刷选 $redis<span class="token">-</span><span class="token">></span><span class="token1">info</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> 返回数组redis所有信息 $redis<span class="token">-</span><span class="token">></span><span class="token1">time</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>返回时间数组 <span class="token2">[</span><span class="token3">0</span><span class="token2">]</span>是时间戳 <span class="token6">//字符串 string</span> <span class="token6">//$redis->set('key',1);//返回true</span> <span class="token6">//$redis->get('key');//获取,不存在返回false</span> <span class="token6">//$redis->setex('key', 3600, 'value');//设置过期时间1小时,单位秒 true</span> <span class="token6">//$redis->psetex('key1', 1000, 'value');//毫秒 true</span> <span class="token6">//$redis->setnx('key1', 'value');//设置key,存在返回flase,不存在才添加返回true</span> <span class="token6">//$redis->delete(['id1','id2']);//删除,返回删除数量</span> <span class="token6">//$redis->delete('id1','id2');</span> <span class="token6">//$old_value = $redis->getSet('key', 'lol');//返回以前值,并设置新值,如果不存在key则创建</span> <span class="token6">//$arr=$redis->multi()->set('key','33')->get('key')->set('key1','2')->get('key1')->exec();//事务处理 discard()取消事务 返回数组[]</span> <span class="token6">//$is = $redis->exists('key8');//检测key是否存在 返回0 1</span> <span class="token6">//$redis->incr('key8');//自动+1,不存在key返回1 存在返回添加后的值</span> <span class="token6">//$redis->incrBy('key', 10);//自动加10,不存在创建,返回增加后值</span> <span class="token6">//$redis->incrByFloat('key1', 1.5);//浮点数 支持正负数</span> <span class="token6">//$redis->decr('key1');//自减1</span> <span class="token6">//$redis->decrBy('key1', 10);//减10</span> <span class="token6">//$c = $redis->mGet(['id','id1']);//返回多个值数组,不存在键返回 [flase,'1']</span> <span class="token6">//$redis->append('id', 'value2');//追加字符,返回字符长度</span> <span class="token6">//$redis->getRange('key', 0, 5);//返回字符串一部分,从0开始,右边-1</span> <span class="token6">//$redis->setRange('key', 6, "redis");//从位置替换 返回长度</span> <span class="token6">//$c= $redis->strlen('id');//返回长度中文3 数字字母1</span> <span class="token6">//$c = $redis->mset(['key0' => 'value0', 'key1' => 'value1']);//设置多个key,成功返回true</span> <span class="token6">//列表 list</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">lPush</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'C'</span><span class="token2">)</span><span class="token2">;</span> 左边插入<span class="token2">,</span>成功返回元素数量<span class="token2">,</span>失败<span class="token3">false</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">rPush</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'C'</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//右边插入</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">lPushx</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'A'</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//左边插入,key1不存在不能插入,返回false,成功返回元素数量</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">rPushx</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'A'</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//右边插入</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">lPop</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">)</span><span class="token2">;</span> <span class="token6">//左边删除一个并显示,失败返回false</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">rPop</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//右边删除</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">brPop</span><span class="token2">(</span><span class="token1">array</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'key2'</span><span class="token2">)</span><span class="token2">,</span> <span class="token3">10</span><span class="token2">)</span><span class="token2">;</span> 阻塞模式用于消息队列 $redis<span class="token">-</span><span class="token">></span><span class="token1">lSize</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">)</span><span class="token2">;</span> 返回元素数量<span class="token2">,</span>失败为<span class="token3">0</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">lGet</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//取出一个元素,0第一个,-1最后一个,失败返回false</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">lSet</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token4">'X'</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//更新值 0是索引位置 成功返回1失败false</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">lRange</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token">-</span><span class="token3">1</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//取得范围内元素,返回数组</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">lTrim</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token3">1</span><span class="token2">)</span><span class="token2">;</span>截取以后变成新的key1 $redis<span class="token">-</span><span class="token">></span><span class="token1">lRem</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'A'</span><span class="token2">,</span> <span class="token3">2</span><span class="token2">)</span><span class="token2">;</span> 从左到右删除<span class="token3">2</span>个A 负数表示从右到左<span class="token2">,</span>成功返回元素个数<span class="token2">,</span>失败返回<span class="token3">0</span><span class="token2">,</span>第三个参数<span class="token3">0</span>表示全部删除 $redis<span class="token">-</span><span class="token">></span><span class="token1">lInsert</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> Redis<span class="token2">:</span><span class="token2">:</span>AFTER<span class="token2">,</span> <span class="token4">'A'</span><span class="token2">,</span> <span class="token4">'X'</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//A之后插入X,不存在返回-1</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">lInsert</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> Redis<span class="token2">:</span><span class="token2">:</span>BEFORE<span class="token2">,</span> <span class="token4">'A'</span><span class="token2">,</span> <span class="token4">'X'</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//之前插入,返回元素数量,不存在-1</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">rpoplpush</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'key2'</span><span class="token2">)</span><span class="token2">;</span> 从key1尾部取出一个插入到key2头部<span class="token2">,</span>返回元素值<span class="token2">,</span>不存在返回<span class="token3">false</span> <span class="token">-</span> hash哈希<span class="token2">(</span>散列<span class="token2">)</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">hSet</span><span class="token2">(</span><span class="token4">'id'</span><span class="token2">,</span> <span class="token4">'key2'</span><span class="token2">,</span> <span class="token4">'hello'</span><span class="token2">)</span><span class="token2">;</span> 插入值<span class="token2">,</span>成功返回<span class="token3">1</span><span class="token2">,</span>失败或已存在key2返回<span class="token3">0</span><span class="token2">,</span>相当于修改 $redis<span class="token">-</span><span class="token">></span><span class="token1">hSetnx</span><span class="token2">(</span><span class="token4">'id'</span><span class="token2">,</span> <span class="token4">'key2'</span><span class="token2">,</span> <span class="token4">'hello'</span><span class="token2">)</span><span class="token2">;</span>已存在不会修改<span class="token2">,</span>返回<span class="token3">false</span><span class="token2">,</span>不存在会创建 $redis<span class="token">-</span><span class="token">></span><span class="token1">hGet</span><span class="token2">(</span><span class="token4">'h'</span><span class="token2">,</span> <span class="token4">'key1'</span><span class="token2">)</span><span class="token2">;</span>获取 $redis<span class="token">-</span><span class="token">></span><span class="token1">hLen</span><span class="token2">(</span><span class="token4">'h'</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//元素数量</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">hdel</span><span class="token2">(</span><span class="token4">'id'</span><span class="token2">,</span><span class="token4">'key2'</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//删除成功返回1 失败0</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">hKeys</span><span class="token2">(</span><span class="token4">'id'</span><span class="token2">)</span> 返回keys组成的数组 $redis<span class="token">-</span><span class="token">></span><span class="token1">hvals</span><span class="token2">(</span><span class="token4">'h'</span><span class="token2">)</span> 返回值数组 $redis<span class="token">-</span><span class="token">></span><span class="token1">hGetAll</span><span class="token2">(</span><span class="token4">'h'</span><span class="token2">)</span> 返回键值对数组 $redis<span class="token">-</span><span class="token">></span><span class="token1">hExists</span><span class="token2">(</span><span class="token4">'h'</span><span class="token2">,</span> <span class="token4">'a'</span><span class="token2">)</span><span class="token2">;</span>判断是否存在key成功<span class="token3">1</span>失败<span class="token3">0</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">hIncrBy</span><span class="token2">(</span><span class="token4">'h'</span><span class="token2">,</span> <span class="token4">'a'</span><span class="token2">,</span> <span class="token3">2</span><span class="token2">)</span> a增加<span class="token3">2</span><span class="token2">,</span>只有数字才起作用<span class="token2">,</span>不存在创建 失败<span class="token3">false</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">hIncrByFloat</span><span class="token2">(</span><span class="token4">'h'</span><span class="token2">,</span><span class="token4">'x'</span><span class="token2">,</span> <span class="token3">1.5</span><span class="token2">)</span><span class="token2">;</span> 浮点 $redis<span class="token">-</span><span class="token">></span><span class="token1">hmset</span><span class="token2">(</span><span class="token4">'h'</span><span class="token2">,</span> <span class="token2">[</span><span class="token4">'a'</span><span class="token">=</span><span class="token">></span><span class="token3">1</span><span class="token2">,</span><span class="token4">'b'</span><span class="token">=</span><span class="token">></span><span class="token3">2</span><span class="token2">]</span><span class="token2">)</span> 批量插入返回<span class="token2">,</span><span class="token3">1</span><span class="token2">,</span>存在会修改值 $redis<span class="token">-</span><span class="token">></span><span class="token1">hmGet</span><span class="token2">(</span><span class="token4">'h'</span><span class="token2">,</span><span class="token2">[</span><span class="token4">'a'</span><span class="token2">,</span><span class="token4">'b'</span><span class="token2">]</span><span class="token2">)</span> 返回键值数组 <span class="token">-</span> set集合<span class="token2">,</span>无顺序<span class="token2">,</span>不重复 $redis<span class="token">-</span><span class="token">></span><span class="token1">sAdd</span><span class="token2">(</span><span class="token4">'key1'</span> <span class="token2">,</span> <span class="token4">'member1'</span><span class="token2">)</span><span class="token2">;</span> 添加元素成功返回<span class="token3">1</span>失败<span class="token3">0</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">srem</span><span class="token2">(</span><span class="token4">'key1'</span> <span class="token2">,</span> <span class="token4">'member1'</span><span class="token2">)</span><span class="token2">;</span> 删除指定值 成功返回<span class="token3">1</span>失败<span class="token3">0</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">sMove</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'key2'</span><span class="token2">,</span> <span class="token4">'member13'</span><span class="token2">)</span><span class="token2">;</span>从key1中取出值放到key2 成功返回<span class="token3">1</span>失败<span class="token3">0</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">sIsMember</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'member1'</span><span class="token2">)</span><span class="token2">;</span>判断是否在key1是返回<span class="token3">1</span>失败<span class="token3">0</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">sCard</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">)</span><span class="token2">;</span>计算元素数量 $redis<span class="token">-</span><span class="token">></span><span class="token1">sPop</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">)</span><span class="token2">;</span>随机取出一个元素<span class="token2">,</span>并删除 $redis<span class="token">-</span><span class="token">></span><span class="token1">sRandMember</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">)</span><span class="token2">;</span>随机取出一个元素<span class="token2">,</span>不删除 $redis<span class="token">-</span><span class="token">></span><span class="token1">sInter</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'key2'</span><span class="token2">,</span> <span class="token4">'key3'</span><span class="token2">)</span>返回集合交集<span class="token2">,</span>没有为<span class="token2">[</span><span class="token2">]</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">sInterStore</span><span class="token2">(</span><span class="token4">'output'</span><span class="token2">,</span> <span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'key2'</span><span class="token2">,</span> <span class="token4">'key3'</span><span class="token2">)</span>返回交集存储 $redis<span class="token">-</span><span class="token">></span><span class="token1">sUnion</span><span class="token2">(</span><span class="token4">'s0'</span><span class="token2">,</span> <span class="token4">'s1'</span><span class="token2">,</span> <span class="token4">'s2'</span><span class="token2">)</span>并集 $redis<span class="token">-</span><span class="token">></span><span class="token1">sUnionStore</span><span class="token2">(</span><span class="token4">'dst'</span><span class="token2">,</span> <span class="token4">'s0'</span><span class="token2">,</span> <span class="token4">'s1'</span><span class="token2">,</span> <span class="token4">'s2'</span><span class="token2">)</span>并集存储 返回元素数量 $redis<span class="token">-</span><span class="token">></span><span class="token1">sMembers</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">)</span> 返回全部元素数组 <span class="token">-</span> zset有序集合 $redis<span class="token">-</span><span class="token">></span><span class="token1">zAdd</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">,</span> <span class="token3">1</span><span class="token2">,</span> <span class="token4">'val1'</span><span class="token2">)</span><span class="token2">;</span> 添加元素第二个参数是分数<span class="token2">,</span>成功返回<span class="token3">1</span><span class="token2">,</span>失败或修改返回<span class="token3">0</span><span class="token2">,</span>分数可以是小数<span class="token2">,</span>字符串是<span class="token3">0</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">zRange</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token">-</span><span class="token3">1</span><span class="token2">)</span><span class="token2">;</span>返回元素key数组<span class="token2">,</span>$redis<span class="token">-</span><span class="token">></span><span class="token1">zRange</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token">-</span><span class="token3">1</span><span class="token2">,</span><span class="token3">true</span><span class="token2">)</span><span class="token2">;</span>返回键值 $redis<span class="token">-</span><span class="token">></span><span class="token1">zRevRange</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token">-</span><span class="token3">1</span><span class="token2">)</span><span class="token2">;</span>返回指定元素<span class="token2">,</span>分数高到低<span class="token2">,</span>$redis<span class="token">-</span><span class="token">></span><span class="token1">zRevRange</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token">-</span><span class="token3">1</span><span class="token2">,</span> <span class="token3">true</span><span class="token2">)</span><span class="token2">;</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">zDelete</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">,</span> <span class="token4">'val2'</span><span class="token2">)</span><span class="token2">;</span>删除指定元素 $redis<span class="token">-</span><span class="token">></span><span class="token1">zRangeByScore</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token3">3</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">'withscores'</span> <span class="token">=</span><span class="token">></span> TRUE<span class="token2">,</span> <span class="token4">'limit'</span> <span class="token">=</span><span class="token">></span> <span class="token1">array</span><span class="token2">(</span><span class="token3">1</span><span class="token2">,</span> <span class="token3">1</span><span class="token2">)</span><span class="token2">)</span><span class="token2">;</span>返回<span class="token3">0</span><span class="token">-</span><span class="token3">3</span>索引<span class="token2">,</span><span class="token3">true</span>返回分数 $redis<span class="token">-</span><span class="token">></span><span class="token1">zCount</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token3">3</span><span class="token2">)</span><span class="token2">;</span>之间元素数量 $redis<span class="token">-</span><span class="token">></span><span class="token1">zRemRangeByScore</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token3">3</span><span class="token2">)</span><span class="token2">;</span>移除分数<span class="token3">0</span><span class="token">-</span><span class="token3">3</span>之间元素<span class="token2">,</span> <span class="token6">//移除有序集中的一个或多个成员,忽略不存在的成员。返回删除的元素个数。</span> $ret <span class="token">=</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">zRem</span><span class="token2">(</span><span class="token4">'scores'</span><span class="token2">,</span> <span class="token4">'chemistry'</span><span class="token2">,</span> <span class="token4">'English'</span><span class="token2">)</span><span class="token2">;</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">zRemRangeByRank</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">,</span> <span class="token3">0</span><span class="token2">,</span> <span class="token3">1</span><span class="token2">)</span><span class="token2">;</span>移除索引<span class="token3">0</span><span class="token">-</span><span class="token3">1</span>元素返回元素个数 $redis<span class="token">-</span><span class="token">></span><span class="token1">zSize</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">)</span><span class="token2">;</span>返回元素数量 $redis<span class="token">-</span><span class="token">></span><span class="token1">zScore</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'val2'</span><span class="token2">)</span>返回分数 没有返回<span class="token3">false</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">zrank</span><span class="token2">(</span><span class="token4">'key1'</span><span class="token2">,</span> <span class="token4">'val2'</span><span class="token2">)</span>返回值的索引<span class="token2">,</span>从<span class="token3">0</span>开始<span class="token2">,</span>分数从低到高 $redis<span class="token">-</span><span class="token">></span><span class="token1">zRevRank</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">,</span> <span class="token4">'two'</span><span class="token2">)</span><span class="token2">;</span><span class="token6">//分数从高到低</span> $redis<span class="token">-</span><span class="token">></span><span class="token1">zIncrBy</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">,</span> <span class="token3">2.5</span><span class="token2">,</span> <span class="token4">'member1'</span><span class="token2">)</span><span class="token2">;</span>增加<span class="token3">2.5</span>分支持负数<span class="token2">,</span>不存在创建<span class="token2">,</span>返回分数 $redis<span class="token">-</span><span class="token">></span><span class="token1">zUnion</span><span class="token2">(</span><span class="token4">'ko1'</span><span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">'k1'</span><span class="token2">,</span> <span class="token4">'k2'</span><span class="token2">)</span><span class="token2">)</span><span class="token2">;</span>求并集存储在ko1 ``` ```