# 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
```
```
- 简介
- 第一章 数据库
- Mysql/mariadb
- 函数
- 基础
- 增删改索引
- 标准查询
- 高级查询
- TIDB集群mysql解决方案
- Redis
- 语言基础
- 5种数据类型
- 其他类型
- Sqlite
- 语言基础
- 常用查询
- 第二章 PHP
- 语言基础
- 第一课 流程控制和运算
- 第二课 数组
- 第三课 日期时间
- 第四课 常用函数
- 第五课 字符串
- 第六课 文件操作
- 第七课 面向对象
- 第八课 正则表达式
- 第九课 图片处理生成
- 第十课 curl/memche
- 第十一课 mysql和pdo
- 第十三课 cookie和session
- 第十四课 xml操作
- 第十五课 php5.3+新特性
- 第十六课 php7+
- 第十七课 密码安全
- 废弃函数
- php命令行
- redis应用
- 算法
- 排序算法
- 基础算法
- 无限级分类
- 自定义函数Fn
- 查找算法
- 自定义函数数据函数fn
- laravel
- 路由
- 常用语句
- 数据库
- dingo/api
- Yii2
- 控制器
- 常用类
- 数据库
- redis
- thinkphp6
- TP6文档
- TP6插件
- dedecms
- 织梦标签大全
- 数据库操作
- 内置函数和定义函数
- 织梦核心改动
- 织梦插件/底层标签开发
- PHP相关工具
- composer
- php开发环境phpenv
- Phpstorm使用
- windows编译php扩展
- PHP开源库
- 开源项目管理禅道
- sns_auth
- php-casbin权限控制
- php-jwt
- 微信SDKeasywechat
- querylist采集库
- workerman
- Box/Spout处理excel和csv
- dll扩展
- redis/memche/xdebug
- redis
- Lua
- php_xlswriter
- event
- swoole
- 常用代码库
- 微擎框架
- 第一课全局变量
- 第二课常用函数
- 第三课自定义微擎独有函数
- 第四课数据库操作
- 第五课微信端回复
- 第六课微擎高级操作
- 第八课global函数列表
- mainfest.xml详解
- js方法
- 人人商城
- 第一课model解读
- 第二课常用语句解读
- 第三课常用js解读
- 第四课附录常见问题
- 第五课附录处理报表|支付
- 常用JSON状态码
- 第三章 JavaScript
- js基础
- 浏览器对象
- 语言基础
- html5接口
- ES6新语法
- vue
- 基础语法
- 京东vueUI组件
- uniapp
- 组件开发规范
- nodejs
- 基础知识
- 安装node
- nvm不同版本node切换
- js常用标准库
- zepto/jquery
- weui
- js图标库
- elementUI
- validator表单验证
- layer弹出层
- requirejs
- wow动画
- 动画animate
- swiper4
- 百度编辑器
- flyio/axios/qs
- jquery.form
- bootstrap3
- clipboard复制
- slideout侧滑
- imagehover.css图片悬停动画
- webpack打包
- Bulma UI框架
- store 客户端存储
- lottie动画创建库
- sweetalert
- js自定义函数
- 常见JSSDK
- 微信公众号JSSDK
- 腾讯地图jssdk
- 微信小程序
- 第四章 编程语言
- markdown语言
- Dart语言
- Dart语言基础
- Flutter框架
- Lua语言
- 字符串,数组,表
- 自定义方法
- go语言
- 第1.1语言基本语法
- 第1.2流程控制
- 第1.3函数
- 第1.4结构体
- 第1.5接口
- 第1.6包
- go语言框架Gin
- CSS3语言
- CSS与CSS3
- 选择符
- 属性
- css3
- loading动画
- HTML5语言
- less
- sass
- C#
- 基础知识
- 函数
- 第五章 开发工具
- git
- nginx/apache服务器
- Linux常用操作
- crontab定时任务
- 注册表与cmd
- 阿里云ECS
- frp穿透和ssl续期
- 宝塔安装
- 树莓派
- 浏览器模拟
- 火狐/chrome常用插件
- WSL安装使用
- mac brew和终端命令
- win10相关