💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
# Hash ``` <pre class="calibre18">``` <span class="token">/*Hash,表结构,创建更新同操作*/</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">hset</span><span class="token3">(</span><span class="token2">'key'</span><span class="token3">,</span><span class="token2">'field'</span><span class="token3">,</span><span class="token2">'value'</span><span class="token3">)</span><span class="token3">;</span><span class="token">//增,改,将哈希表key中的域field的值设为value,不存在创建,存在就覆盖【1 | 0】</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">hget</span><span class="token3">(</span><span class="token2">'key'</span><span class="token3">,</span><span class="token2">'field'</span><span class="token3">)</span><span class="token3">;</span><span class="token">//查,取值【value|false】</span> $arr <span class="token1">=</span> <span class="token4">array</span><span class="token3">(</span><span class="token2">'one'</span><span class="token1">=</span><span class="token1">></span><span class="token6">1</span><span class="token3">,</span><span class="token6">2</span><span class="token3">,</span><span class="token6">3</span><span class="token3">,</span><span class="token2">'name'</span><span class="token1">=</span><span class="token1">></span><span class="token2">'tom'</span><span class="token3">,</span><span class="token6">4</span><span class="token3">)</span><span class="token3">;</span>$arr2 <span class="token1">=</span> <span class="token4">array</span><span class="token3">(</span><span class="token2">'one'</span><span class="token3">,</span><span class="token6">0</span><span class="token3">,</span><span class="token6">1</span><span class="token3">,</span><span class="token2">'name'</span><span class="token3">,</span><span class="token6">2</span><span class="token3">)</span><span class="token3">;</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">hMset</span><span class="token3">(</span><span class="token2">'key'</span><span class="token3">,</span>$arr<span class="token3">)</span><span class="token3">;</span><span class="token">//增,改,设置多值$arr为(索引|关联)数组,$arr[key]=field, [ true ]</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">hMget</span><span class="token3">(</span><span class="token2">'key'</span><span class="token3">,</span>$arr2<span class="token3">)</span><span class="token3">;</span><span class="token">//查,获取指定下标的field,[$arr | false] ["one"=>1,0=>2,1=>3,"name"=>"tom",2=>4]</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">hGetAll</span><span class="token3">(</span><span class="token2">'key'</span><span class="token3">)</span><span class="token3">;</span><span class="token">//查,返回哈希表key中的所有域和值。[当key不存在时,返回一个空表]</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">hKeys</span><span class="token3">(</span><span class="token2">'key'</span><span class="token3">)</span><span class="token3">;</span><span class="token">//查,返回哈希表key中的所有域。[当key不存在时,返回一个空表]</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">hVals</span><span class="token3">(</span><span class="token2">'key'</span><span class="token3">)</span><span class="token3">;</span><span class="token">//查,返回哈希表key中的所有值。[当key不存在时,返回一个空表]</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">hDel</span><span class="token3">(</span><span class="token2">'key'</span><span class="token3">,</span>$arr2<span class="token3">)</span><span class="token3">;</span><span class="token">//删,删除指定下标的field,不存在的域将被忽略,[num | false]</span> ``` ``` ``` <pre class="calibre10">``` $redis<span class="token1">-</span><span class="token1">></span><span class="token4">hExists</span><span class="token3">(</span><span class="token2">'key'</span><span class="token3">,</span><span class="token2">'field'</span><span class="token3">)</span><span class="token3">;</span><span class="token">//查看hash中是否存在field,[1 | 0]</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">hIncrBy</span><span class="token3">(</span><span class="token2">'key'</span><span class="token3">,</span><span class="token2">'field'</span><span class="token3">,</span>$int_num<span class="token3">)</span><span class="token3">;</span><span class="token">//为哈希表key中的域field的值加上量(+|-)num,[new_num | false]</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">hLen</span><span class="token3">(</span><span class="token2">'key'</span><span class="token3">)</span><span class="token3">;</span><span class="token">//返回哈希表key中域的数量。[ num | 0]</span> ``` ``` //hIncrByFloat(key field increment) - 为哈希表key中的域field加上浮点数增量increment $redis->hIncrByFloat('h','x', 1.5); [//1.5](//1.5) $redis->hIncrByFloat('h', 'x', 1.5); [//3.0](//3.0) //hSetNx(hash field value);-当且仅当第二个参数-\[域:field\]未存在于哈希表的情况下,将它的值设置为value,第一个参数hash不存在时新建 返回boolean $redis->hSetNx('h', 'key1', 'hello'); hScan(key,cursor \[,MATCH pattern\] \[,COUNT count\]);// 迭代hash键 用法和作用同scan hStrLen(key field);// 返回哈希表key中,与给定域field相关联的值的字符串长度 返回number 0表示key或者field不存在