{"id":107191,"date":"2026-09-19T04:21:02","date_gmt":"2026-09-18T20:21:02","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/107191.html"},"modified":"2026-09-19T04:21:02","modified_gmt":"2026-09-18T20:21:02","slug":"java-%e6%8e%a5%e5%85%a5redis-%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%8e%e5%93%88%e5%b8%8c%e7%b1%bb%e5%9e%8b%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/107191.html","title":{"rendered":"Java \u63a5\u5165Redis: \u5b57\u7b26\u4e32\u4e0e\u54c8\u5e0c\u7c7b\u578b\u64cd\u4f5c\u547d\u4ee4"},"content":{"rendered":"<h2>Redis\u547d\u4ee4: string\u4e0ehash\u7c7b\u578b\u7684\u8bfb\u5199\u3001\u8fc7\u671f\u4e0e\u6761\u4ef6\u8bbe\u7f6e<\/h2>\n<h3>\u7eb2\u8981<\/h3>\n<p>\u672c\u6587\u8fdb\u5165 Redis \u547d\u4ee4\u5b9e\u64cd\u3002Redis \u547d\u4ee4\u6309\u6570\u636e\u7c7b\u578b\u5206\u7c7b\u7ec4\u7ec7&#xff0c;\u672c\u6587\u8986\u76d6\u4f7f\u7528\u9891\u7387\u6700\u9ad8\u7684\u4e24\u7c7b&#xff1a;string \u4e0e hash\u3002<\/p>\n<ul>\n<li>\u547d\u4ee4\u4f53\u7cfb\u603b\u89c8\n<ul>\n<li>\u6309\u6570\u636e\u7c7b\u578b\u5206\u7c7b&#xff1a;string \/ hash \/ list \/ set \/ sorted set<\/li>\n<li>\u53e6\u6709\u901a\u7528\u547d\u4ee4&#xff1a;\u5bf9\u6240\u6709\u7c7b\u578b\u751f\u6548<\/li>\n<\/ul>\n<\/li>\n<li>string \u547d\u4ee4\n<ul>\n<li>SET \/ GET&#xff1a;\u57fa\u672c\u8bfb\u5199&#xff0c;\u540c key \u540e\u5199\u8986\u76d6\u524d\u5199<\/li>\n<li>SETEX&#xff1a;\u5e26\u8fc7\u671f\u65f6\u95f4\u5199\u5165&#xff0c;\u9a8c\u8bc1\u7801\u573a\u666f<\/li>\n<li>SETNX&#xff1a;key \u4e0d\u5b58\u5728\u624d\u5199\u5165&#xff0c;\u5206\u5e03\u5f0f\u9501\u5e95\u5c42<\/li>\n<\/ul>\n<\/li>\n<li>hash \u547d\u4ee4\n<ul>\n<li>HSET \/ HGET&#xff1a;\u6309 field \u8bfb\u5199<\/li>\n<li>HDEL \/ HKEYS \/ HVALS \/ HGETALL<\/li>\n<\/ul>\n<\/li>\n<li>\u5173\u952e\u8fd4\u56de\u503c\n<ul>\n<li>nil \u7b49\u4ef7\u4e8e null<\/li>\n<li>SETNX \u8fd4\u56de 1 \u6210\u529f\u30010 \u672a\u6267\u884c<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>\u547d\u4ee4\u4f53\u7cfb\u603b\u89c8<\/h3>\n<p>Redis \u901a\u8fc7\u547d\u4ee4\u64cd\u4f5c\u6570\u636e&#xff0c;\u8fd9\u4e00\u70b9\u7c7b\u4f3c\u4e8e\u7528 SQL \u64cd\u4f5c MySQL&#xff1a;<\/p>\n<table>\n<tr>\u6570\u636e\u5e93\u64cd\u4f5c\u65b9\u5f0f\u63d2\u5165\u67e5\u8be2<\/tr>\n<tbody>\n<tr>\n<td>MySQL<\/td>\n<td>SQL \u8bed\u53e5<\/td>\n<td>insert into \u8868 &#8230;<\/td>\n<td>select &#8230; from \u8868<\/td>\n<\/tr>\n<tr>\n<td>Redis<\/td>\n<td>Redis \u547d\u4ee4<\/td>\n<td>SET key value<\/td>\n<td>GET key<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7531\u4e8e Redis \u6709\u4e94\u79cd\u6570\u636e\u7c7b\u578b&#xff0c;\u547d\u4ee4\u4e5f\u6309\u7c7b\u578b\u5206\u7ec4&#xff1a;<\/p>\n<p>  #mermaid-svg-lj7YbEBdeq48DshK{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-lj7YbEBdeq48DshK .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-lj7YbEBdeq48DshK .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-lj7YbEBdeq48DshK .error-icon{fill:#552222;}#mermaid-svg-lj7YbEBdeq48DshK .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-lj7YbEBdeq48DshK .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-lj7YbEBdeq48DshK .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-lj7YbEBdeq48DshK .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-lj7YbEBdeq48DshK .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-lj7YbEBdeq48DshK .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-lj7YbEBdeq48DshK .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-lj7YbEBdeq48DshK .marker{fill:#333333;stroke:#333333;}#mermaid-svg-lj7YbEBdeq48DshK .marker.cross{stroke:#333333;}#mermaid-svg-lj7YbEBdeq48DshK svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-lj7YbEBdeq48DshK p{margin:0;}#mermaid-svg-lj7YbEBdeq48DshK .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-lj7YbEBdeq48DshK .cluster-label text{fill:#333;}#mermaid-svg-lj7YbEBdeq48DshK .cluster-label span{color:#333;}#mermaid-svg-lj7YbEBdeq48DshK .cluster-label span p{background-color:transparent;}#mermaid-svg-lj7YbEBdeq48DshK .label text,#mermaid-svg-lj7YbEBdeq48DshK span{fill:#333;color:#333;}#mermaid-svg-lj7YbEBdeq48DshK .node rect,#mermaid-svg-lj7YbEBdeq48DshK .node circle,#mermaid-svg-lj7YbEBdeq48DshK .node ellipse,#mermaid-svg-lj7YbEBdeq48DshK .node polygon,#mermaid-svg-lj7YbEBdeq48DshK .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-lj7YbEBdeq48DshK .rough-node .label text,#mermaid-svg-lj7YbEBdeq48DshK .node .label text,#mermaid-svg-lj7YbEBdeq48DshK .image-shape .label,#mermaid-svg-lj7YbEBdeq48DshK .icon-shape .label{text-anchor:middle;}#mermaid-svg-lj7YbEBdeq48DshK .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-lj7YbEBdeq48DshK .rough-node .label,#mermaid-svg-lj7YbEBdeq48DshK .node .label,#mermaid-svg-lj7YbEBdeq48DshK .image-shape .label,#mermaid-svg-lj7YbEBdeq48DshK .icon-shape .label{text-align:center;}#mermaid-svg-lj7YbEBdeq48DshK .node.clickable{cursor:pointer;}#mermaid-svg-lj7YbEBdeq48DshK .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-lj7YbEBdeq48DshK .arrowheadPath{fill:#333333;}#mermaid-svg-lj7YbEBdeq48DshK .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-lj7YbEBdeq48DshK .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-lj7YbEBdeq48DshK .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-lj7YbEBdeq48DshK .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-lj7YbEBdeq48DshK .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-lj7YbEBdeq48DshK .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-lj7YbEBdeq48DshK .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-lj7YbEBdeq48DshK .cluster text{fill:#333;}#mermaid-svg-lj7YbEBdeq48DshK .cluster span{color:#333;}#mermaid-svg-lj7YbEBdeq48DshK div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-lj7YbEBdeq48DshK .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-lj7YbEBdeq48DshK rect.text{fill:none;stroke-width:0;}#mermaid-svg-lj7YbEBdeq48DshK .icon-shape,#mermaid-svg-lj7YbEBdeq48DshK .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-lj7YbEBdeq48DshK .icon-shape p,#mermaid-svg-lj7YbEBdeq48DshK .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-lj7YbEBdeq48DshK .icon-shape .label rect,#mermaid-svg-lj7YbEBdeq48DshK .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-lj7YbEBdeq48DshK .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-lj7YbEBdeq48DshK .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-lj7YbEBdeq48DshK :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>Redis \u5e38\u7528\u547d\u4ee4<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>string \u547d\u4ee4SET \/ GET \/ SETEX \/ SETNX<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>hash \u547d\u4ee4HSET \/ HGET \/ HDEL \/ HKEYS \/ HVALS \/ HGETALL<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>list \u547d\u4ee4LPUSH \/ LRANGE \/ RPOP \/ LLEN \/ BRPOP<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>set \u547d\u4ee4SADD \/ SMEMBERS \/ SCARD \/ SINTER \/ SUNION \/ SDIFF \/ SREM<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>sorted set \u547d\u4ee4ZADD \/ ZRANGE \/ ZINCRBY \/ ZREM<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u901a\u7528\u547d\u4ee4KEYS \/ EXISTS \/ TYPE \/ TTL \/ DEL<\/p>\n<p><\/span><\/p>\n<p>\u7ec3\u4e60\u73af\u5883\u5efa\u8bae&#xff1a;\u547d\u4ee4\u5728 Windows \u4e0e Linux \u7248\u7684 Redis \u4e0a\u5b8c\u5168\u4e00\u81f4\u3002\u7ec3\u4e60\u9636\u6bb5\u63a8\u8350\u7528 Windows \u7248\u2014\u2014\u53cc\u51fb redis-server.exe \u542f\u52a8\u670d\u52a1&#xff0c;\u518d\u53cc\u51fb redis-cli.exe \u6253\u5f00\u5ba2\u6237\u7aef\u5373\u53ef&#xff0c;\u65e0\u9700\u5f00\u865a\u62df\u673a\u3002<\/p>\n<h3>string \u7c7b\u578b\u547d\u4ee4<\/h3>\n<p>string \u662f\u6700\u5e38\u7528\u7684\u7c7b\u578b&#xff0c;\u6838\u5fc3\u547d\u4ee4\u6709\u56db\u4e2a\u3002<\/p>\n<table>\n<tr>\u547d\u4ee4\u8bed\u6cd5\u4f5c\u7528<\/tr>\n<tbody>\n<tr>\n<td>SET<\/td>\n<td>SET key value<\/td>\n<td>\u8bbe\u7f6e\u6307\u5b9a key \u7684\u503c<\/td>\n<\/tr>\n<tr>\n<td>GET<\/td>\n<td>GET key<\/td>\n<td>\u83b7\u53d6\u6307\u5b9a key \u7684\u503c<\/td>\n<\/tr>\n<tr>\n<td>SETEX<\/td>\n<td>SETEX key seconds value<\/td>\n<td>\u8bbe\u7f6e\u503c\u5e76\u6307\u5b9a\u8fc7\u671f\u65f6\u95f4&#xff08;\u79d2&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>SETNX<\/td>\n<td>SETNX key value<\/td>\n<td>\u4ec5\u5f53 key \u4e0d\u5b58\u5728\u65f6\u624d\u8bbe\u7f6e\u503c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>SET \u4e0e GET<\/h4>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> SET name \u5c0f\u660e<br \/>\nOK<br \/>\n<span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> GET name<br \/>\n<span class=\"token string\">&#034;\u5c0f\u660e&#034;<\/span><\/p>\n<p>\u8fd4\u56de OK \u8868\u793a\u6267\u884c\u6210\u529f\u3002\u6ce8\u610f GET \u7684\u8fd4\u56de\u503c\u88ab\u53cc\u5f15\u53f7\u5305\u88f9&#xff0c;\u8bf4\u660e\u5b83\u662f string \u7c7b\u578b\u3002<\/p>\n<p>key \u4e0d\u5b58\u5728\u65f6&#xff1a;<\/p>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> GET age<br \/>\n<span class=\"token punctuation\">(<\/span>nil<span class=\"token punctuation\">)<\/span><\/p>\n<p>nil \u7b49\u4ef7\u4e8e Java \u4e2d\u7684 null&#xff0c;\u8868\u793a\u503c\u4e0d\u5b58\u5728\u3002\u8fd9\u662f Redis \u4e2d\u8868\u793a\u300c\u7a7a\u300d\u7684\u7edf\u4e00\u65b9\u5f0f\u3002<\/p>\n<h4>\u6570\u503c\u4e5f\u4f1a\u88ab\u5b58\u6210\u5b57\u7b26\u4e32<\/h4>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> SET age <span class=\"token number\">20<\/span><br \/>\nOK<br \/>\n<span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> GET age<br \/>\n<span class=\"token string\">&#034;20&#034;<\/span><\/p>\n<p>\u6ce8\u610f&#xff1a;\u5373\u4f7f\u5199\u5165\u65f6 20 \u6ca1\u6709\u52a0\u5f15\u53f7&#xff0c;\u53d6\u56de\u65f6\u4ecd\u5e26\u53cc\u5f15\u53f7\u3002\u53ea\u8981\u4f7f\u7528 SET \u547d\u4ee4&#xff0c;\u5b58\u5165\u7684\u6570\u636e\u6700\u7ec8\u90fd\u4f1a\u8f6c\u4e3a\u5b57\u7b26\u4e32\u5b58\u50a8\u3002<\/p>\n<h4>\u76f8\u540c key \u4f1a\u8986\u76d6<\/h4>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> SET age <span class=\"token number\">30<\/span><br \/>\nOK<br \/>\n<span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> GET age<br \/>\n<span class=\"token string\">&#034;30&#034;<\/span><\/p>\n<p>\u540e\u8bbe\u7f6e\u7684 30 \u8986\u76d6\u4e86\u5148\u524d\u7684 20\u3002\u7ed3\u8bba&#xff1a;key \u76f8\u540c\u65f6&#xff0c;\u540e\u5199\u5165\u7684\u503c\u8986\u76d6\u5148\u5199\u5165\u7684\u503c\u3002<\/p>\n<h4>SETEX \u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4<\/h4>\n<p>SETEX &#061; SET &#043; EXpire&#xff0c;\u5728\u5199\u503c\u7684\u540c\u65f6\u6307\u5b9a\u5b58\u6d3b\u79d2\u6570\u3002<\/p>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> SETEX city <span class=\"token number\">10<\/span> \u5317\u4eac<br \/>\nOK<br \/>\n<span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> GET city<br \/>\n<span class=\"token string\">&#034;\u5317\u4eac&#034;<\/span><\/p>\n<p><span class=\"token comment\"># \u7b49\u5f85 10 \u79d2\u540e<\/span><br \/>\n<span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> GET city<br \/>\n<span class=\"token punctuation\">(<\/span>nil<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u65f6\u95f4\u4e00\u5230&#xff0c;Redis \u81ea\u52a8\u6e05\u7406\u8be5\u952e\u503c\u5bf9&#xff0c;\u65e0\u9700\u4eba\u5de5\u5e72\u9884\u3002<\/p>\n<p>     Redis<\/p>\n<p>     \u5ba2\u6237\u7aef<\/p>\n<p>      Redis<\/p>\n<p>      \u5ba2\u6237\u7aef<\/p>\n<p>  #mermaid-svg-xTN04bMzlvcPpIrU{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-xTN04bMzlvcPpIrU .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-xTN04bMzlvcPpIrU .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-xTN04bMzlvcPpIrU .error-icon{fill:#552222;}#mermaid-svg-xTN04bMzlvcPpIrU .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-xTN04bMzlvcPpIrU .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-xTN04bMzlvcPpIrU .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-xTN04bMzlvcPpIrU .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-xTN04bMzlvcPpIrU .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-xTN04bMzlvcPpIrU .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-xTN04bMzlvcPpIrU .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-xTN04bMzlvcPpIrU .marker{fill:#333333;stroke:#333333;}#mermaid-svg-xTN04bMzlvcPpIrU .marker.cross{stroke:#333333;}#mermaid-svg-xTN04bMzlvcPpIrU svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-xTN04bMzlvcPpIrU p{margin:0;}#mermaid-svg-xTN04bMzlvcPpIrU .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-xTN04bMzlvcPpIrU text.actor&gt;tspan{fill:black;stroke:none;}#mermaid-svg-xTN04bMzlvcPpIrU .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-xTN04bMzlvcPpIrU .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-xTN04bMzlvcPpIrU .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-xTN04bMzlvcPpIrU .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-xTN04bMzlvcPpIrU #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-xTN04bMzlvcPpIrU .sequenceNumber{fill:white;}#mermaid-svg-xTN04bMzlvcPpIrU #sequencenumber{fill:#333;}#mermaid-svg-xTN04bMzlvcPpIrU #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-xTN04bMzlvcPpIrU .messageText{fill:#333;stroke:none;}#mermaid-svg-xTN04bMzlvcPpIrU .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-xTN04bMzlvcPpIrU .labelText,#mermaid-svg-xTN04bMzlvcPpIrU .labelText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-xTN04bMzlvcPpIrU .loopText,#mermaid-svg-xTN04bMzlvcPpIrU .loopText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-xTN04bMzlvcPpIrU .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-xTN04bMzlvcPpIrU .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-xTN04bMzlvcPpIrU .noteText,#mermaid-svg-xTN04bMzlvcPpIrU .noteText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-xTN04bMzlvcPpIrU .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-xTN04bMzlvcPpIrU .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-xTN04bMzlvcPpIrU .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-xTN04bMzlvcPpIrU .actorPopupMenu{position:absolute;}#mermaid-svg-xTN04bMzlvcPpIrU .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 \/ 0.4));}#mermaid-svg-xTN04bMzlvcPpIrU .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-xTN04bMzlvcPpIrU .actor-man circle,#mermaid-svg-xTN04bMzlvcPpIrU line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-xTN04bMzlvcPpIrU :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>     \u5012\u8ba1\u65f6\u81f3\u7b2c 10 \u79d2<\/p>\n<p>   SETEX city 10 \u5317\u4eac<\/p>\n<p>   OK<\/p>\n<p>   GET city&#xff08;\u7b2c 1 \u79d2&#xff09;<\/p>\n<p>   &#034;\u5317\u4eac&#034;<\/p>\n<p>   \u81ea\u52a8\u6e05\u7406 city<\/p>\n<p>   GET city&#xff08;\u7b2c 11 \u79d2&#xff09;<\/p>\n<p>   (nil)<\/p>\n<p>\u5178\u578b\u5e94\u7528\u2014\u2014\u624b\u673a\u9a8c\u8bc1\u7801\u767b\u5f55&#xff1a;\u670d\u52a1\u7aef\u751f\u6210\u9a8c\u8bc1\u7801\u540e\u5b58\u5165 Redis \u5e76\u8bbe\u7f6e 5 \u5206\u949f\u6709\u6548\u671f&#xff0c;\u65f6\u95f4\u5230\u81ea\u52a8\u5931\u6548\u3002\u8fd9\u6837\u65e0\u9700\u5728\u5e94\u7528\u5c42\u7ef4\u62a4\u8fc7\u671f\u903b\u8f91&#xff0c;\u4e5f\u907f\u514d\u4e86 Session \u7684\u5c40\u9650\u6027\u3002<\/p>\n<p><span class=\"token comment\"># \u9a8c\u8bc1\u7801 5 \u5206\u949f\u6709\u6548<\/span><br \/>\nSETEX code:13800138000 <span class=\"token number\">300<\/span> <span class=\"token number\">1234<\/span><\/p>\n<h4>SETNX \u6761\u4ef6\u8bbe\u7f6e<\/h4>\n<p>SETNX &#061; SET if Not eXists&#xff1a;\u53ea\u6709\u5f53 key \u4e0d\u5b58\u5728\u65f6\u624d\u8bbe\u7f6e&#xff0c;\u5df2\u5b58\u5728\u5219\u4e0d\u505a\u4efb\u4f55\u64cd\u4f5c\u3002<\/p>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> SETNX k1 value1<br \/>\n<span class=\"token punctuation\">(<\/span>integer<span class=\"token punctuation\">)<\/span> <span class=\"token number\">1<\/span><br \/>\n<span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> SETNX k1 value2<br \/>\n<span class=\"token punctuation\">(<\/span>integer<span class=\"token punctuation\">)<\/span> <span class=\"token number\">0<\/span><br \/>\n<span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> GET k1<br \/>\n<span class=\"token string\">&#034;value1&#034;<\/span><\/p>\n<table>\n<tr>\u8fd4\u56de\u503c\u542b\u4e49<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u8bbe\u7f6e\u6210\u529f&#xff08;key \u539f\u5148\u4e0d\u5b58\u5728&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>\u672a\u6267\u884c&#xff08;key \u5df2\u5b58\u5728&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7b2c\u4e8c\u6b21 SETNX k1 value2 \u8fd4\u56de 0&#xff0c;\u4e14 GET k1 \u4ecd\u4e3a value1&#xff0c;\u8bf4\u660e\u7b2c\u4e8c\u6b21\u5199\u5165\u88ab\u8df3\u8fc7\u3002<\/p>\n<p>\u5178\u578b\u5e94\u7528\u2014\u2014\u5206\u5e03\u5f0f\u9501&#xff1a;\u5206\u5e03\u5f0f\u73af\u5883\u4e0b\u7684\u5e76\u53d1\u63a7\u5236\u4f9d\u8d56\u300c\u62a2\u9501\u300d\u8fd9\u4e00\u539f\u5b50\u52a8\u4f5c&#xff0c;\u800c SETNX \u7684\u300c\u4e0d\u5b58\u5728\u624d\u8bbe\u7f6e\u300d\u8bed\u4e49\u6b63\u662f\u62a2\u9501\u7684\u5e95\u5c42\u5b9e\u73b0\u539f\u7406\u3002<\/p>\n<p>  #mermaid-svg-kW2eaQFfeFm1QPwN{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-kW2eaQFfeFm1QPwN .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-kW2eaQFfeFm1QPwN .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-kW2eaQFfeFm1QPwN .error-icon{fill:#552222;}#mermaid-svg-kW2eaQFfeFm1QPwN .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-kW2eaQFfeFm1QPwN .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-kW2eaQFfeFm1QPwN .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-kW2eaQFfeFm1QPwN .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-kW2eaQFfeFm1QPwN .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-kW2eaQFfeFm1QPwN .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-kW2eaQFfeFm1QPwN .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-kW2eaQFfeFm1QPwN .marker{fill:#333333;stroke:#333333;}#mermaid-svg-kW2eaQFfeFm1QPwN .marker.cross{stroke:#333333;}#mermaid-svg-kW2eaQFfeFm1QPwN svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-kW2eaQFfeFm1QPwN p{margin:0;}#mermaid-svg-kW2eaQFfeFm1QPwN .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-kW2eaQFfeFm1QPwN .cluster-label text{fill:#333;}#mermaid-svg-kW2eaQFfeFm1QPwN .cluster-label span{color:#333;}#mermaid-svg-kW2eaQFfeFm1QPwN .cluster-label span p{background-color:transparent;}#mermaid-svg-kW2eaQFfeFm1QPwN .label text,#mermaid-svg-kW2eaQFfeFm1QPwN span{fill:#333;color:#333;}#mermaid-svg-kW2eaQFfeFm1QPwN .node rect,#mermaid-svg-kW2eaQFfeFm1QPwN .node circle,#mermaid-svg-kW2eaQFfeFm1QPwN .node ellipse,#mermaid-svg-kW2eaQFfeFm1QPwN .node polygon,#mermaid-svg-kW2eaQFfeFm1QPwN .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-kW2eaQFfeFm1QPwN .rough-node .label text,#mermaid-svg-kW2eaQFfeFm1QPwN .node .label text,#mermaid-svg-kW2eaQFfeFm1QPwN .image-shape .label,#mermaid-svg-kW2eaQFfeFm1QPwN .icon-shape .label{text-anchor:middle;}#mermaid-svg-kW2eaQFfeFm1QPwN .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-kW2eaQFfeFm1QPwN .rough-node .label,#mermaid-svg-kW2eaQFfeFm1QPwN .node .label,#mermaid-svg-kW2eaQFfeFm1QPwN .image-shape .label,#mermaid-svg-kW2eaQFfeFm1QPwN .icon-shape .label{text-align:center;}#mermaid-svg-kW2eaQFfeFm1QPwN .node.clickable{cursor:pointer;}#mermaid-svg-kW2eaQFfeFm1QPwN .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-kW2eaQFfeFm1QPwN .arrowheadPath{fill:#333333;}#mermaid-svg-kW2eaQFfeFm1QPwN .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-kW2eaQFfeFm1QPwN .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-kW2eaQFfeFm1QPwN .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-kW2eaQFfeFm1QPwN .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-kW2eaQFfeFm1QPwN .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-kW2eaQFfeFm1QPwN .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-kW2eaQFfeFm1QPwN .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-kW2eaQFfeFm1QPwN .cluster text{fill:#333;}#mermaid-svg-kW2eaQFfeFm1QPwN .cluster span{color:#333;}#mermaid-svg-kW2eaQFfeFm1QPwN div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-kW2eaQFfeFm1QPwN .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-kW2eaQFfeFm1QPwN rect.text{fill:none;stroke-width:0;}#mermaid-svg-kW2eaQFfeFm1QPwN .icon-shape,#mermaid-svg-kW2eaQFfeFm1QPwN .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-kW2eaQFfeFm1QPwN .icon-shape p,#mermaid-svg-kW2eaQFfeFm1QPwN .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-kW2eaQFfeFm1QPwN .icon-shape .label rect,#mermaid-svg-kW2eaQFfeFm1QPwN .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-kW2eaQFfeFm1QPwN .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-kW2eaQFfeFm1QPwN .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-kW2eaQFfeFm1QPwN :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u670d\u52a1\u5b9e\u4f8b ASETNX lock 1\u8fd4\u56de 1 \u62a2\u9501\u6210\u529f<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u83b7\u5f97\u9501\u6267\u884c\u4e1a\u52a1DEL lock \u91ca\u653e<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u670d\u52a1\u5b9e\u4f8b BSETNX lock 1\u8fd4\u56de 0 \u62a2\u9501\u5931\u8d25<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>\u7b49\u5f85\u6216\u653e\u5f03<\/p>\n<p><\/span><\/p>\n<p>string \u7c7b\u578b\u7684\u5b8c\u6574\u547d\u4ee4\u8fdc\u4e0d\u6b62\u8fd9\u56db\u4e2a&#xff08;\u5b98\u65b9\u6587\u6863\u5171 20 \u4e2a&#xff09;\u3002\u5b8c\u6574\u7684\u547d\u4ee4\u6e05\u5355\u53ef\u67e5\u9605 Redis \u4e2d\u6587\u7f51 http:\/\/www.redis.net.cn \u7684\u300cRedis \u6559\u7a0b\u300d\u83dc\u5355\u3002<\/p>\n<h3>hash \u7c7b\u578b\u547d\u4ee4<\/h3>\n<p>hash \u662f\u4e00\u4e2a string \u7c7b\u578b\u7684 field \u548c value \u7684\u6620\u5c04\u8868&#xff0c;\u7279\u522b\u9002\u5408\u5b58\u50a8\u5bf9\u8c61\u3002<\/p>\n<h4>\u4e09\u5c42\u7ed3\u6784<\/h4>\n<p>  #mermaid-svg-fsWODK0uvZxwXH8T{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-fsWODK0uvZxwXH8T .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-fsWODK0uvZxwXH8T .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-fsWODK0uvZxwXH8T .error-icon{fill:#552222;}#mermaid-svg-fsWODK0uvZxwXH8T .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-fsWODK0uvZxwXH8T .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-fsWODK0uvZxwXH8T .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-fsWODK0uvZxwXH8T .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-fsWODK0uvZxwXH8T .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-fsWODK0uvZxwXH8T .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-fsWODK0uvZxwXH8T .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-fsWODK0uvZxwXH8T .marker{fill:#333333;stroke:#333333;}#mermaid-svg-fsWODK0uvZxwXH8T .marker.cross{stroke:#333333;}#mermaid-svg-fsWODK0uvZxwXH8T svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-fsWODK0uvZxwXH8T p{margin:0;}#mermaid-svg-fsWODK0uvZxwXH8T .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-fsWODK0uvZxwXH8T .cluster-label text{fill:#333;}#mermaid-svg-fsWODK0uvZxwXH8T .cluster-label span{color:#333;}#mermaid-svg-fsWODK0uvZxwXH8T .cluster-label span p{background-color:transparent;}#mermaid-svg-fsWODK0uvZxwXH8T .label text,#mermaid-svg-fsWODK0uvZxwXH8T span{fill:#333;color:#333;}#mermaid-svg-fsWODK0uvZxwXH8T .node rect,#mermaid-svg-fsWODK0uvZxwXH8T .node circle,#mermaid-svg-fsWODK0uvZxwXH8T .node ellipse,#mermaid-svg-fsWODK0uvZxwXH8T .node polygon,#mermaid-svg-fsWODK0uvZxwXH8T .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-fsWODK0uvZxwXH8T .rough-node .label text,#mermaid-svg-fsWODK0uvZxwXH8T .node .label text,#mermaid-svg-fsWODK0uvZxwXH8T .image-shape .label,#mermaid-svg-fsWODK0uvZxwXH8T .icon-shape .label{text-anchor:middle;}#mermaid-svg-fsWODK0uvZxwXH8T .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-fsWODK0uvZxwXH8T .rough-node .label,#mermaid-svg-fsWODK0uvZxwXH8T .node .label,#mermaid-svg-fsWODK0uvZxwXH8T .image-shape .label,#mermaid-svg-fsWODK0uvZxwXH8T .icon-shape .label{text-align:center;}#mermaid-svg-fsWODK0uvZxwXH8T .node.clickable{cursor:pointer;}#mermaid-svg-fsWODK0uvZxwXH8T .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-fsWODK0uvZxwXH8T .arrowheadPath{fill:#333333;}#mermaid-svg-fsWODK0uvZxwXH8T .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-fsWODK0uvZxwXH8T .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-fsWODK0uvZxwXH8T .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-fsWODK0uvZxwXH8T .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-fsWODK0uvZxwXH8T .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-fsWODK0uvZxwXH8T .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-fsWODK0uvZxwXH8T .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-fsWODK0uvZxwXH8T .cluster text{fill:#333;}#mermaid-svg-fsWODK0uvZxwXH8T .cluster span{color:#333;}#mermaid-svg-fsWODK0uvZxwXH8T div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-fsWODK0uvZxwXH8T .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-fsWODK0uvZxwXH8T rect.text{fill:none;stroke-width:0;}#mermaid-svg-fsWODK0uvZxwXH8T .icon-shape,#mermaid-svg-fsWODK0uvZxwXH8T .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-fsWODK0uvZxwXH8T .icon-shape p,#mermaid-svg-fsWODK0uvZxwXH8T .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-fsWODK0uvZxwXH8T .icon-shape .label rect,#mermaid-svg-fsWODK0uvZxwXH8T .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-fsWODK0uvZxwXH8T .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-fsWODK0uvZxwXH8T .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-fsWODK0uvZxwXH8T :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>key\u5982 001<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>value \u6574\u4f53\u4e3a hash<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>field: namevalue: \u5c0f\u660e<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>field: agevalue: 20<\/p>\n<p><\/span><\/p>\n<p>         <span class=\"nodeLabel\"><\/p>\n<p>field: phonevalue: 138***<\/p>\n<p><\/span><\/p>\n<p>\u547d\u4ee4\u53c2\u6570\u4e0e\u7ed3\u6784\u7684\u5bf9\u5e94\u5173\u7cfb&#xff1a;<\/p>\n<table>\n<tr>\u547d\u4ee4\u53c2\u6570\u5bf9\u5e94\u7ed3\u6784<\/tr>\n<tbody>\n<tr>\n<td>key<\/td>\n<td>\u6574\u4e2a Redis \u952e\u503c\u5bf9\u7684 key<\/td>\n<\/tr>\n<tr>\n<td>field<\/td>\n<td>value \u5185\u90e8\u7684\u5b57\u6bb5\u540d<\/td>\n<\/tr>\n<tr>\n<td>value<\/td>\n<td>field \u5bf9\u5e94\u7684\u503c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u91cd\u70b9&#xff1a;HDEL \u5220\u9664\u7684\u662f key \u4e0b\u7684\u67d0\u4e2a field&#xff0c;\u4e0d\u662f\u5220\u9664\u6574\u4e2a key\u3002\u8fd9\u662f\u521d\u5b66 hash \u6700\u5e38\u89c1\u7684\u8bef\u89e3\u3002<\/p>\n<table>\n<tr>\u547d\u4ee4\u8bed\u6cd5\u4f5c\u7528<\/tr>\n<tbody>\n<tr>\n<td>HSET<\/td>\n<td>HSET key field value<\/td>\n<td>\u8bbe\u7f6e key \u4e2d field \u7684\u503c<\/td>\n<\/tr>\n<tr>\n<td>HGET<\/td>\n<td>HGET key field<\/td>\n<td>\u83b7\u53d6 key \u4e2d field \u7684\u503c<\/td>\n<\/tr>\n<tr>\n<td>HDEL<\/td>\n<td>HDEL key field [field &#8230;]<\/td>\n<td>\u5220\u9664\u4e00\u4e2a\u6216\u591a\u4e2a field<\/td>\n<\/tr>\n<tr>\n<td>HKEYS<\/td>\n<td>HKEYS key<\/td>\n<td>\u8fd4\u56de\u6240\u6709 field<\/td>\n<\/tr>\n<tr>\n<td>HVALS<\/td>\n<td>HVALS key<\/td>\n<td>\u8fd4\u56de\u6240\u6709 value<\/td>\n<\/tr>\n<tr>\n<td>HGETALL<\/td>\n<td>HGETALL key<\/td>\n<td>\u8fd4\u56de\u6240\u6709 field \u4e0e value<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>HSET \u4e0e HGET<\/h4>\n<p>\u4ee5\u5b58\u50a8\u7528\u6237\u4fe1\u606f\u4e3a\u4f8b&#xff0c;\u7528\u7528\u6237 ID \u4f5c\u4e3a key&#xff0c;\u5c5e\u6027\u4f5c\u4e3a field&#xff1a;<\/p>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> HSET 001 name \u5c0f\u660e<br \/>\n<span class=\"token punctuation\">(<\/span>integer<span class=\"token punctuation\">)<\/span> <span class=\"token number\">1<\/span><br \/>\n<span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> HSET 001 age <span class=\"token number\">20<\/span><br \/>\n<span class=\"token punctuation\">(<\/span>integer<span class=\"token punctuation\">)<\/span> <span class=\"token number\">1<\/span><\/p>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> HGET 001 name<br \/>\n<span class=\"token string\">&#034;\u5c0f\u660e&#034;<\/span><br \/>\n<span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> HGET 001 age<br \/>\n<span class=\"token string\">&#034;20&#034;<\/span><\/p>\n<p>\u4e24\u4e2a HSET \u4f7f\u7528\u540c\u4e00\u4e2a key&#xff08;001&#xff09;&#xff0c;\u56e0\u6b64\u4ee3\u8868\u540c\u4e00\u4e2a\u7528\u6237\u5bf9\u8c61\u7684\u4e0d\u540c\u5c5e\u6027\u3002<\/p>\n<h4>HDEL \u5220\u9664\u5b57\u6bb5<\/h4>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> HDEL 001 age<br \/>\n<span class=\"token punctuation\">(<\/span>integer<span class=\"token punctuation\">)<\/span> <span class=\"token number\">1<\/span><\/p>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> HGET 001 age<br \/>\n<span class=\"token punctuation\">(<\/span>nil<span class=\"token punctuation\">)<\/span><\/p>\n<p>HDEL \u540e\u53ef\u63a5\u591a\u4e2a field&#xff0c;\u4e00\u6b21\u6027\u5220\u9664\u591a\u4e2a\u5b57\u6bb5\u3002\u5220\u9664\u540e\u8be5 field \u53d8\u4e3a nil\u3002<\/p>\n<h4>HKEYS \/ HVALS \/ HGETALL<\/h4>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> HKEYS 001<br \/>\n<span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token string\">&#034;name&#034;<\/span><br \/>\n<span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token string\">&#034;age&#034;<\/span><\/p>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> HVALS 001<br \/>\n<span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token string\">&#034;\u5c0f\u660e&#034;<\/span><br \/>\n<span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token string\">&#034;20&#034;<\/span><\/p>\n<p><span class=\"token number\">127.0<\/span>.0.1:637<span class=\"token operator\"><span class=\"token file-descriptor important\">9<\/span>&gt;<\/span> HGETALL 001<br \/>\n<span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token string\">&#034;name&#034;<\/span><br \/>\n<span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token string\">&#034;\u5c0f\u660e&#034;<\/span><br \/>\n<span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token string\">&#034;age&#034;<\/span><br \/>\n<span class=\"token number\">4<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token string\">&#034;20&#034;<\/span><\/p>\n<p>\u4e09\u8005\u7684\u533a\u522b&#xff1a;<\/p>\n<table>\n<tr>\u547d\u4ee4\u8fd4\u56de\u5185\u5bb9<\/tr>\n<tbody>\n<tr>\n<td>HKEYS<\/td>\n<td>\u4ec5\u6240\u6709 field<\/td>\n<\/tr>\n<tr>\n<td>HVALS<\/td>\n<td>\u4ec5\u6240\u6709 value<\/td>\n<\/tr>\n<tr>\n<td>HGETALL<\/td>\n<td>field \u4e0e value \u4ea4\u66ff\u5217\u51fa<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>HGETALL \u7684\u8f93\u51fa\u662f field\u3001value\u3001field\u3001value \u4ea4\u66ff\u6392\u5217&#xff0c;\u9700\u6210\u5bf9\u9605\u8bfb\u3002<\/p>\n<p>\u82e5 key \u672c\u8eab\u4e0d\u5b58\u5728&#xff08;\u5982 HGET 002 name&#xff09;&#xff0c;\u540c\u6837\u8fd4\u56de nil\u3002<\/p>\n<h3>\u5b8c\u6574\u53ef\u8fd0\u884c\u4ee3\u7801<\/h3>\n<h4>Java \u4e2d\u5bf9\u5e94\u7684\u64cd\u4f5c<\/h4>\n<p><span class=\"token keyword\">package<\/span> <span class=\"token namespace\">com<span class=\"token punctuation\">.<\/span>itheima<span class=\"token punctuation\">.<\/span>test<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">import<\/span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>junit<span class=\"token punctuation\">.<\/span>jupiter<span class=\"token punctuation\">.<\/span>api<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">Test<\/span><\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>beans<span class=\"token punctuation\">.<\/span>factory<span class=\"token punctuation\">.<\/span>annotation<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">Autowired<\/span><\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>boot<span class=\"token punctuation\">.<\/span>test<span class=\"token punctuation\">.<\/span>context<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">SpringBootTest<\/span><\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">.<\/span>redis<span class=\"token punctuation\">.<\/span>core<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">HashOperations<\/span><\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">.<\/span>redis<span class=\"token punctuation\">.<\/span>core<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">RedisTemplate<\/span><\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token import\"><span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">.<\/span>redis<span class=\"token punctuation\">.<\/span>core<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">ValueOperations<\/span><\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">import<\/span> <span class=\"token import\"><span class=\"token namespace\">java<span class=\"token punctuation\">.<\/span>util<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">Map<\/span><\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token import\"><span class=\"token namespace\">java<span class=\"token punctuation\">.<\/span>util<span class=\"token punctuation\">.<\/span>concurrent<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">TimeUnit<\/span><\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/**<br \/>\n * \u6f14\u793a Redis string \u4e0e hash \u7c7b\u578b\u547d\u4ee4\u5728 Java \u4e2d\u7684\u5bf9\u5e94\u64cd\u4f5c\u3002<br \/>\n *\/<\/span><br \/>\n<span class=\"token annotation punctuation\">&#064;SpringBootTest<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">RedisStringHashCommandTest<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Autowired<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">RedisTemplate<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> redisTemplate<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * \u5bf9\u5e94 SET \/ GET&#xff1a;\u57fa\u672c\u8bfb\u5199\u3002<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Test<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">testSetAndGet<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">ValueOperations<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> ops <span class=\"token operator\">&#061;<\/span> redisTemplate<span class=\"token punctuation\">.<\/span><span class=\"token function\">opsForValue<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;name&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u5c0f\u660e&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;GET name -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;name&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ key \u4e0d\u5b58\u5728\u65f6\u8fd4\u56de null&#xff0c;\u7b49\u4ef7\u4e8e\u547d\u4ee4\u884c\u4e2d\u7684 nil<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;GET notExist -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;notExist&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u76f8\u540c key \u540e\u5199\u8986\u76d6\u524d\u5199<\/span><br \/>\n        ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;age&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;20&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;age&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;30&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;GET age -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;age&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * \u5bf9\u5e94 SETEX&#xff1a;\u5199\u5165\u65f6\u6307\u5b9a\u8fc7\u671f\u65f6\u95f4\u3002<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Test<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">testSetex<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">ValueOperations<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> ops <span class=\"token operator\">&#061;<\/span> redisTemplate<span class=\"token punctuation\">.<\/span><span class=\"token function\">opsForValue<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u9a8c\u8bc1\u7801 5 \u5206\u949f\u6709\u6548<\/span><br \/>\n        ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;code:13800138000&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;1234&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">TimeUnit<\/span><span class=\"token punctuation\">.<\/span><span class=\"token constant\">MINUTES<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;GET code -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;code:13800138000&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5269\u4f59\u6709\u6548\u671f&#xff08;\u79d2&#xff09;-&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> redisTemplate<span class=\"token punctuation\">.<\/span><span class=\"token function\">getExpire<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;code:13800138000&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * \u5bf9\u5e94 SETNX&#xff1a;key \u4e0d\u5b58\u5728\u624d\u8bbe\u7f6e&#xff0c;\u53ef\u7528\u4e8e\u5206\u5e03\u5f0f\u9501\u3002<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Test<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">testSetnx<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">ValueOperations<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> ops <span class=\"token operator\">&#061;<\/span> redisTemplate<span class=\"token punctuation\">.<\/span><span class=\"token function\">opsForValue<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        redisTemplate<span class=\"token punctuation\">.<\/span><span class=\"token function\">delete<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;k1&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token class-name\">Boolean<\/span> first <span class=\"token operator\">&#061;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">setIfAbsent<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;k1&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;value1&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">Boolean<\/span> second <span class=\"token operator\">&#061;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">setIfAbsent<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;k1&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;value2&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u7b2c\u4e00\u6b21 SETNX -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> first<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u7b2c\u4e8c\u6b21 SETNX -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> second<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;GET k1 -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;k1&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * \u5bf9\u5e94 HSET \/ HGET \/ HDEL \/ HKEYS \/ HVALS \/ HGETALL\u3002<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Test<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">testHash<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">HashOperations<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> ops <span class=\"token operator\">&#061;<\/span> redisTemplate<span class=\"token punctuation\">.<\/span><span class=\"token function\">opsForHash<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">put<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;001&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;name&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u5c0f\u660e&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">put<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;001&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;age&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;20&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;HGET 001 name -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;001&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;name&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;HKEYS 001 -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">keys<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;001&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;HVALS 001 -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">values<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;001&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;HGETALL 001 -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">entries<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;001&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ HDEL \u5220\u9664\u7684\u662f field&#xff0c;\u800c\u975e\u6574\u4e2a key<\/span><br \/>\n        ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">delete<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;001&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;age&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">Map<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> after <span class=\"token operator\">&#061;<\/span> ops<span class=\"token punctuation\">.<\/span><span class=\"token function\">entries<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;001&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5220\u9664 age \u540e HGETALL -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> after<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u9a8c\u8bc1 key \u672c\u8eab\u4ecd\u7136\u5b58\u5728<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;key 001 \u662f\u5426\u5b58\u5728 -&gt; &#034;<\/span> <span class=\"token operator\">&#043;<\/span> <span class=\"token class-name\">Boolean<\/span><span class=\"token punctuation\">.<\/span><span class=\"token constant\">TRUE<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">equals<\/span><span class=\"token punctuation\">(<\/span>redisTemplate<span class=\"token punctuation\">.<\/span><span class=\"token function\">hasKey<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;001&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u5de5\u7a0b\u76ee\u5f55\u7ed3\u6784<\/h4>\n<p>springdataredis_demo\/<br \/>\n\u251c\u2500\u2500 pom.xml<br \/>\n\u2514\u2500\u2500 src\/<br \/>\n    \u251c\u2500\u2500 main\/<br \/>\n    \u2502   \u251c\u2500\u2500 java\/com\/itheima\/<br \/>\n    \u2502   \u2502   \u251c\u2500\u2500 App.java<br \/>\n    \u2502   \u2502   \u2514\u2500\u2500 config\/<br \/>\n    \u2502   \u2502       \u2514\u2500\u2500 RedisConfig.java<br \/>\n    \u2502   \u2514\u2500\u2500 resources\/<br \/>\n    \u2502       \u2514\u2500\u2500 application.yml<br \/>\n    \u2514\u2500\u2500 test\/<br \/>\n        \u2514\u2500\u2500 java\/com\/itheima\/test\/<br \/>\n            \u2514\u2500\u2500 RedisStringHashCommandTest.java<\/p>\n<h3>API \u901f\u89c8<\/h3>\n<table>\n<tr>Redis \u547d\u4ee4RedisTemplate \u5bf9\u5e94\u65b9\u6cd5\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>SET key value<\/td>\n<td>opsForValue().set(k, v)<\/td>\n<td>\u8bbe\u7f6e\u503c<\/td>\n<\/tr>\n<tr>\n<td>GET key<\/td>\n<td>opsForValue().get(k)<\/td>\n<td>\u53d6\u503c&#xff0c;\u4e0d\u5b58\u5728\u8fd4\u56de null<\/td>\n<\/tr>\n<tr>\n<td>SETEX key sec value<\/td>\n<td>opsForValue().set(k, v, timeout, unit)<\/td>\n<td>\u5e26\u8fc7\u671f\u65f6\u95f4\u5199\u5165<\/td>\n<\/tr>\n<tr>\n<td>SETNX key value<\/td>\n<td>opsForValue().setIfAbsent(k, v)<\/td>\n<td>\u4e0d\u5b58\u5728\u624d\u8bbe\u7f6e&#xff0c;\u8fd4\u56de Boolean<\/td>\n<\/tr>\n<tr>\n<td>HSET key f v<\/td>\n<td>opsForHash().put(k, f, v)<\/td>\n<td>\u8bbe\u7f6e\u5b57\u6bb5<\/td>\n<\/tr>\n<tr>\n<td>HGET key f<\/td>\n<td>opsForHash().get(k, f)<\/td>\n<td>\u53d6\u5b57\u6bb5\u503c<\/td>\n<\/tr>\n<tr>\n<td>HDEL key f<\/td>\n<td>opsForHash().delete(k, f)<\/td>\n<td>\u5220\u9664\u5b57\u6bb5<\/td>\n<\/tr>\n<tr>\n<td>HKEYS key<\/td>\n<td>opsForHash().keys(k)<\/td>\n<td>\u6240\u6709 field<\/td>\n<\/tr>\n<tr>\n<td>HVALS key<\/td>\n<td>opsForHash().values(k)<\/td>\n<td>\u6240\u6709 value<\/td>\n<\/tr>\n<tr>\n<td>HGETALL key<\/td>\n<td>opsForHash().entries(k)<\/td>\n<td>\u6240\u6709 field-value<\/td>\n<\/tr>\n<tr>\n<td>TTL key<\/td>\n<td>getExpire(k)<\/td>\n<td>\u5269\u4f59\u6709\u6548\u671f<\/td>\n<\/tr>\n<tr>\n<td>EXISTS key<\/td>\n<td>hasKey(k)<\/td>\n<td>\u952e\u662f\u5426\u5b58\u5728<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u5b98\u65b9\u6587\u6863<\/h3>\n<ul>\n<li>Redis \u547d\u4ee4\u603b\u89c8&#xff1a;https:\/\/redis.io\/commands<\/li>\n<li>String \u547d\u4ee4\u53c2\u8003&#xff1a;https:\/\/redis.io\/commands\/?group&#061;string<\/li>\n<li>Hash \u547d\u4ee4\u53c2\u8003&#xff1a;https:\/\/redis.io\/commands\/?group&#061;hash<\/li>\n<li>Redis \u4e2d\u6587\u7f51\u6559\u7a0b&#xff1a;http:\/\/www.redis.net.cn\/tutorial\/3501.html<\/li>\n<\/ul>\n<h4>\u603b\u7ed3<\/h4>\n<p>\u672c\u6587\u8986\u76d6\u4e86 string \u4e0e hash \u4e24\u7c7b\u9ad8\u9891\u547d\u4ee4\u3002string \u7684\u56db\u4e2a\u547d\u4ee4\u4f53\u73b0\u4e86\u4e09\u79cd\u5199\u5165\u8bed\u4e49&#xff1a;\u666e\u901a\u5199\u5165&#xff08;SET&#xff0c;\u540c\u952e\u8986\u76d6&#xff09;\u3001\u5e26\u8fc7\u671f\u5199\u5165&#xff08;SETEX&#xff0c;\u9a8c\u8bc1\u7801\u573a\u666f&#xff09;\u3001\u6761\u4ef6\u5199\u5165&#xff08;SETNX&#xff0c;\u8fd4\u56de 1\/0&#xff0c;\u5206\u5e03\u5f0f\u9501\u5e95\u5c42&#xff09;\u3002hash \u7684\u6838\u5fc3\u662f\u7406\u89e3 key \u2192 field \u2192 value \u4e09\u5c42\u7ed3\u6784\u2014\u2014\u547d\u4ee4\u4e2d\u7684 field \u4f4d\u4e8e value \u5185\u90e8&#xff0c;\u56e0\u6b64 HDEL \u5220\u7684\u662f\u5b57\u6bb5\u800c\u975e\u6574\u4e2a\u952e\u3002Redis \u7edf\u4e00\u7528 nil \u8868\u8fbe\u300c\u4e0d\u5b58\u5728\u300d&#xff0c;\u5bf9\u5e94 Java \u4e2d\u7684 null\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u547d\u4ee4: string\u4e0ehash\u7c7b\u578b\u7684\u8bfb\u5199\u3001\u8fc7\u671f\u4e0e\u6761\u4ef6\u8bbe\u7f6e<br \/>\n\u7eb2\u8981<br \/>\n\u672c\u6587\u8fdb\u5165 Redis \u547d\u4ee4\u5b9e\u64cd\u3002Redis \u547d\u4ee4\u6309\u6570\u636e\u7c7b\u578b\u5206\u7c7b\u7ec4\u7ec7&#xff0c;\u672c\u6587\u8986\u76d6\u4f7f\u7528\u9891\u7387\u6700\u9ad8\u7684\u4e24\u7c7b&#xff1a;string \u4e0e hash\u3002<br \/>\n\u547d\u4ee4\u4f53\u7cfb\u603b\u89c8 \u6309\u6570\u636e\u7c7b\u578b\u5206\u7c7b&#xff1a;string \/ hash \/ list \/ set \/ sorted set\u53e6\u6709\u901a\u7528\u547d\u4ee4&#xff1a;\u5bf9\u6240\u6709\u7c7b\u578b\u751f\u6548 string \u547d\u4ee4 SET \/ GET&#xff1a;\u57fa\u672c\u8bfb\u5199&#xff0c;\u540c<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,105,43],"topic":[],"class_list":["post-107191","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-redis","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java \u63a5\u5165Redis: \u5b57\u7b26\u4e32\u4e0e\u54c8\u5e0c\u7c7b\u578b\u64cd\u4f5c\u547d\u4ee4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/107191.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java \u63a5\u5165Redis: \u5b57\u7b26\u4e32\u4e0e\u54c8\u5e0c\u7c7b\u578b\u64cd\u4f5c\u547d\u4ee4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Redis\u547d\u4ee4: string\u4e0ehash\u7c7b\u578b\u7684\u8bfb\u5199\u3001\u8fc7\u671f\u4e0e\u6761\u4ef6\u8bbe\u7f6e \u7eb2\u8981 \u672c\u6587\u8fdb\u5165 Redis \u547d\u4ee4\u5b9e\u64cd\u3002Redis \u547d\u4ee4\u6309\u6570\u636e\u7c7b\u578b\u5206\u7c7b\u7ec4\u7ec7&#xff0c;\u672c\u6587\u8986\u76d6\u4f7f\u7528\u9891\u7387\u6700\u9ad8\u7684\u4e24\u7c7b&#xff1a;string \u4e0e hash\u3002 \u547d\u4ee4\u4f53\u7cfb\u603b\u89c8 \u6309\u6570\u636e\u7c7b\u578b\u5206\u7c7b&#xff1a;string \/ hash \/ list \/ set \/ sorted set\u53e6\u6709\u901a\u7528\u547d\u4ee4&#xff1a;\u5bf9\u6240\u6709\u7c7b\u578b\u751f\u6548 string \u547d\u4ee4 SET \/ GET&#xff1a;\u57fa\u672c\u8bfb\u5199&#xff0c;\u540c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/107191.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-18T20:21:02+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/107191.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/107191.html\",\"name\":\"Java \u63a5\u5165Redis: \u5b57\u7b26\u4e32\u4e0e\u54c8\u5e0c\u7c7b\u578b\u64cd\u4f5c\u547d\u4ee4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-18T20:21:02+00:00\",\"dateModified\":\"2026-09-18T20:21:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/107191.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/107191.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/107191.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java \u63a5\u5165Redis: \u5b57\u7b26\u4e32\u4e0e\u54c8\u5e0c\u7c7b\u578b\u64cd\u4f5c\u547d\u4ee4\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java \u63a5\u5165Redis: \u5b57\u7b26\u4e32\u4e0e\u54c8\u5e0c\u7c7b\u578b\u64cd\u4f5c\u547d\u4ee4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/107191.html","og_locale":"zh_CN","og_type":"article","og_title":"Java \u63a5\u5165Redis: \u5b57\u7b26\u4e32\u4e0e\u54c8\u5e0c\u7c7b\u578b\u64cd\u4f5c\u547d\u4ee4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Redis\u547d\u4ee4: string\u4e0ehash\u7c7b\u578b\u7684\u8bfb\u5199\u3001\u8fc7\u671f\u4e0e\u6761\u4ef6\u8bbe\u7f6e \u7eb2\u8981 \u672c\u6587\u8fdb\u5165 Redis \u547d\u4ee4\u5b9e\u64cd\u3002Redis \u547d\u4ee4\u6309\u6570\u636e\u7c7b\u578b\u5206\u7c7b\u7ec4\u7ec7&#xff0c;\u672c\u6587\u8986\u76d6\u4f7f\u7528\u9891\u7387\u6700\u9ad8\u7684\u4e24\u7c7b&#xff1a;string \u4e0e hash\u3002 \u547d\u4ee4\u4f53\u7cfb\u603b\u89c8 \u6309\u6570\u636e\u7c7b\u578b\u5206\u7c7b&#xff1a;string \/ hash \/ list \/ set \/ sorted set\u53e6\u6709\u901a\u7528\u547d\u4ee4&#xff1a;\u5bf9\u6240\u6709\u7c7b\u578b\u751f\u6548 string \u547d\u4ee4 SET \/ GET&#xff1a;\u57fa\u672c\u8bfb\u5199&#xff0c;\u540c","og_url":"https:\/\/www.wsisp.com\/helps\/107191.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-18T20:21:02+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"13 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/107191.html","url":"https:\/\/www.wsisp.com\/helps\/107191.html","name":"Java \u63a5\u5165Redis: \u5b57\u7b26\u4e32\u4e0e\u54c8\u5e0c\u7c7b\u578b\u64cd\u4f5c\u547d\u4ee4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-18T20:21:02+00:00","dateModified":"2026-09-18T20:21:02+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/107191.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/107191.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/107191.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Java \u63a5\u5165Redis: \u5b57\u7b26\u4e32\u4e0e\u54c8\u5e0c\u7c7b\u578b\u64cd\u4f5c\u547d\u4ee4"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/107191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=107191"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/107191\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=107191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=107191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=107191"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=107191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}