php使用redis内存不足怎么办

php使用redis内存不足的解决办法:1、通过配置文件或者命令设置Redis最大占用内存大小为100M;2、获取当前内存淘汰策略;3、通过“config set maxmemory-policy allkeys-lru”命令修改淘汰策略即可。

千万级数据并发如何处理?进入学习

.css-1yuhvjn{margin-top:16px;}

.css-3jt6os .FileLinkCard{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;background-color:rgba(246,246,246,0.88);border-radius:12px;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;margin:1em auto;max-width:100%;overflow:hidden;padding:12px;position:relative;width:390px;}.css-3jt6os .FileLinkCard-icon{-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;height:30px;width:30px;}.css-3jt6os .FileLinkCard-info{margin-left:12px;}.css-3jt6os .FileLinkCard-name{color:#121212;font-size:15px;font-weight:500;line-height:21px;display:-webkit-box;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:2;}.css-3jt6os .FileLinkCard-meta{color:#999999;font-size:12px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;line-height:14px;margin-top:5px;}.css-3jt6os .FileLinkCard-source{white-space:pre;}.css-1wr1m8 .LinkCard.new{position:relative;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;box-sizing:border-box;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;width:390px;min-height:84px;border-radius:8px;max-width:100%;overflow:hidden;margin:16px auto;padding:12px 12px 9px 12px;background-color:#F6F6F6;}.css-1wr1m8 .LinkCard.new,.css-1wr1m8 .LinkCard.new:hover{-webkit-text-decoration:none;text-decoration:none;border:none !important;color:inherit !important;}.css-1wr1m8 .LinkCard.new .LinkCard-contents{display:block;-webkit-flex:1 1 auto;-ms-flex:1 1 auto;flex:1 1 auto;position:relative;}.css-1wr1m8 .LinkCard.new .LinkCard-contents .loading{height:14px;background:#EBEBEB;border-radius:7px;}.css-1wr1m8 .LinkCard.new .LinkCard-contents.withTitle{margin-bottom:3px;}.css-1wr1m8 .LinkCard.new .LinkCard-title{display:-webkit-box;font-size:15px;font-weight:500;line-height:1.4;margin-bottom:2px;color:#121212;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;}.css-1wr1m8 .LinkCard.new .LinkCard-title.two-line{line-height:20px;display:-webkit-box;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:2;}.css-1wr1m8 .LinkCard.new .LinkCard-title.loading{margin-bottom:8px;width:80%;}.css-1wr1m8 .LinkCard.new .LinkCard-title.loading.withTitle{margin-bottom:6px;}.css-1wr1m8 .LinkCard.new .LinkCard-title.loadingTitle{margin-bottom:5px;}.css-1wr1m8 .LinkCard.new .LinkCard-excerpt{display:-webkit-box;text-overflow:ellipsis;font-size:13px;line-height:18px;color:#999999;margin-bottom:4px;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;}.css-1wr1m8 .LinkCard.new .LinkCard-excerpt .LinkCard-author{color:#444444;}.css-1wr1m8 .LinkCard.new .LinkCard-desc{display:-webkit-box;font-size:13px;height:18px;line-height:18px;color:#999999;word-break:break-all;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;}.css-1wr1m8 .LinkCard.new .LinkCard-desc .LinkCard-tag,.css-1wr1m8 .LinkCard.new .LinkCard-desc .tag{display:inline-block;font-size:11px;margin-left:8px;padding:0 4px;border-radius:3px;background:rgba(211,211,211,0.3);}.css-1wr1m8 .LinkCard.new .LinkCard-desc.loading{width:40%;}.css-1wr1m8 .LinkCard.new .LinkCard-desc svg{margin-right:2px;}.css-1wr1m8 .LinkCard.new .LinkCard-image{-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;background-color:#EBEBEB;background-size:cover;background-position:center;position:relative;display:block;width:60px;height:60px;margin-left:20px;object-fit:cover;border-radius:inherit;overflow:hidden;}.css-1wr1m8 .LinkCard.new .LinkCard-image.LinkCard-image–default{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;background-color:#EBEBEB;color:#D3D3D3;}.css-1wr1m8 .LinkCard.new .LinkCard-image.LinkCard-image–default svg{color:#999999;}.css-1wr1m8 .LinkCard.new .LinkCard-image img{width:100%;height:100%;object-fit:cover;}.css-1wr1m8 .LinkCard.new .LinkCard-image .LinkCard-image–video{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;position:absolute;top:50%;left:50%;-webkit-transform:translateX(-50%) translateY(-50%);-ms-transform:translateX(-50%) translateY(-50%);transform:translateX(-50%) translateY(-50%);width:24px;height:24px;border-radius:12px;background:rgba(255,255,255,0.9);pointer-events:none;}.css-1wr1m8 .LinkCard.new .LinkCard-image .LinkCard-image–video svg{color:#444444;}.css-1wr1m8 .LinkCard.new .LinkCard-richText .text{color:#444444;}.css-1wr1m8 .LinkCard.new .LinkCard-richText .bold{font-weight:600;}.css-1wr1m8 .LinkCard.new .LinkCard-richText .tag{margin-left:4px;}.css-1wr1m8 .LinkCard.old{position:relative;display:block;margin:1em auto;width:390px;box-sizing:border-box;border-radius:12px;max-width:100%;overflow:hidden;}.css-1wr1m8 .LinkCard.old,.css-1wr1m8 .LinkCard.old:hover{-webkit-text-decoration:none;text-decoration:none;border:none !important;color:inherit !important;}.css-1wr1m8 .LinkCard-ecommerceLoadingCard{position:relative;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;padding:12px;border-radius:inherit;height:80px;box-sizing:border-box;background:rgba(246,246,246,0.88);color:#D3D3D3;}.css-1wr1m8 .LinkCard-ecommerceLoadingCardAvatarWrapper{width:60px;height:60px;background:#EBEBEB;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;border-radius:6px;margin-right:10px;}.css-1wr1m8 .LinkCard-ecommerceLoadingCardNetwork{width:20px;height:20px;}.css-1wr1m8 .LinkCard-ecommerceLoadingCardLoadingbar{height:60px;-webkit-flex:1;-ms-flex:1;flex:1;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}.css-1wr1m8 .LinkCard-ecommerceLoadingCardLoadingbar span{height:16px;display:inline-block;background:#EBEBEB;}.css-1wr1m8 .LinkCard-ecommerceLoadingCardLoadingbar span:nth-of-type(1){width:60px;margin-bottom:4px;}.css-1wr1m8 .LinkCard-ecommerceLoadingCardLoadingbar span:nth-of-type(2){width:127px;}.css-hypxot .LinkCard.old{position:relative;display:block;margin:1em auto;width:390px;box-sizing:border-box;border-radius:12px;max-width:100%;overflow:hidden;}.css-hypxot .LinkCard.old,.css-hypxot .LinkCard.old:hover{-webkit-text-decoration:none;text-decoration:none;border:none !important;color:inherit !important;}.css-hypxot .LinkCard-ecommerceLoadingCard{position:relative;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;padding:12px;border-radius:inherit;height:80px;box-sizing:border-box;background:rgba(246,246,246,0.88);color:#D3D3D3;}.css-hypxot .LinkCard-ecommerceLoadingCardAvatarWrapper{width:60px;height:60px;background:#EBEBEB;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;border-radius:6px;margin-right:10px;}.css-hypxot .LinkCard-ecommerceLoadingCardNetwork{width:20px;height:20px;}.css-hypxot .LinkCard-ecommerceLoadingCardLoadingbar{height:60px;-webkit-flex:1;-ms-flex:1;flex:1;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}.css-hypxot .LinkCard-ecommerceLoadingCardLoadingbar span{height:16px;display:inline-block;background:#EBEBEB;}.css-hypxot .LinkCard-ecommerceLoadingCardLoadingbar span:nth-of-type(1){width:60px;margin-bottom:4px;}.css-hypxot .LinkCard-ecommerceLoadingCardLoadingbar span:nth-of-type(2){width:127px;}.css-hypxot .LinkCard.new{position:relative;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;box-sizing:border-box;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;width:390px;min-height:84px;border-radius:8px;max-width:100%;overflow:hidden;margin:16px auto;padding:12px 12px 9px 12px;background-color:#F6F6F6;}.css-hypxot .LinkCard.new,.css-hypxot .LinkCard.new:hover{-webkit-text-decoration:none;text-decoration:none;border:none !important;color:inherit !important;}.css-hypxot .LinkCard.new .LinkCard-contents{display:block;-webkit-flex:1 1 auto;-ms-flex:1 1 auto;flex:1 1 auto;position:relative;}.css-hypxot .LinkCard.new .LinkCard-contents .loading{height:14px;background:#EBEBEB;border-radius:7px;}.css-hypxot .LinkCard.new .LinkCard-contents.withTitle{margin-bottom:3px;}.css-hypxot .LinkCard.new .LinkCard-title{display:-webkit-box;font-size:15px;font-weight:500;line-height:1.4;margin-bottom:2px;color:#121212;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;}.css-hypxot .LinkCard.new .LinkCard-title.two-line{line-height:20px;display:-webkit-box;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:2;}.css-hypxot .LinkCard.new .LinkCard-title.loading{margin-bottom:8px;width:80%;}.css-hypxot .LinkCard.new .LinkCard-title.loading.withTitle{margin-bottom:6px;}.css-hypxot .LinkCard.new .LinkCard-title.loadingTitle{margin-bottom:5px;}.css-hypxot .LinkCard.new .LinkCard-excerpt{display:-webkit-box;text-overflow:ellipsis;font-size:13px;line-height:18px;color:#999999;margin-bottom:4px;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;}.css-hypxot .LinkCard.new .LinkCard-excerpt .LinkCard-author{color:#444444;}.css-hypxot .LinkCard.new .LinkCard-desc{display:-webkit-box;font-size:13px;height:18px;line-height:18px;color:#999999;word-break:break-all;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;}.css-hypxot .LinkCard.new .LinkCard-desc .LinkCard-tag,.css-hypxot .LinkCard.new .LinkCard-desc .tag{display:inline-block;font-size:11px;margin-left:8px;padding:0 4px;border-radius:3px;background:rgba(211,211,211,0.3);}.css-hypxot .LinkCard.new .LinkCard-desc.loading{width:40%;}.css-hypxot .LinkCard.new .LinkCard-desc svg{margin-right:2px;}.css-hypxot .LinkCard.new .LinkCard-image{-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;background-color:#EBEBEB;background-size:cover;background-position:center;position:relative;display:block;width:60px;height:60px;margin-left:20px;object-fit:cover;border-radius:inherit;overflow:hidden;}.css-hypxot .LinkCard.new .LinkCard-image.LinkCard-image–default{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;background-color:#EBEBEB;color:#D3D3D3;}.css-hypxot .LinkCard.new .LinkCard-image.LinkCard-image–default svg{color:#999999;}.css-hypxot .LinkCard.new .LinkCard-image img{width:100%;height:100%;object-fit:cover;}.css-hypxot .LinkCard.new .LinkCard-image .LinkCard-image–video{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;position:absolute;top:50%;left:50%;-webkit-transform:translateX(-50%) translateY(-50%);-ms-transform:translateX(-50%) translateY(-50%);transform:translateX(-50%) translateY(-50%);width:24px;height:24px;border-radius:12px;background:rgba(255,255,255,0.9);pointer-events:none;}.css-hypxot .LinkCard.new .LinkCard-image .LinkCard-image–video svg{color:#444444;}.css-hypxot .LinkCard.new .LinkCard-richText .text{color:#444444;}.css-hypxot .LinkCard.new .LinkCard-richText .bold{font-weight:600;}.css-hypxot .LinkCard.new .LinkCard-richText .tag{margin-left:4px;}.css-hypxot .FileLinkCard{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;background-color:rgba(246,246,246,0.88);border-radius:12px;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;margin:1em auto;max-width:100%;overflow:hidden;padding:12px;position:relative;width:390px;}.css-hypxot .FileLinkCard-icon{-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;height:30px;width:30px;}.css-hypxot .FileLinkCard-info{margin-left:12px;}.css-hypxot .FileLinkCard-name{color:#121212;font-size:15px;font-weight:500;line-height:21px;display:-webkit-box;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:2;}.css-hypxot .FileLinkCard-meta{color:#999999;font-size:12px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;line-height:14px;margin-top:5px;}.css-hypxot .FileLinkCard-source{white-space:pre;}.css-4em6pe{word-break:break-word;line-height:1.6;}.css-4em6pe > [data-first-child]{margin-top:0;}.css-4em6pe > :last-child{margin-bottom:0;}.css-4em6pe h1,.css-4em6pe h2{clear:left;margin-top:calc((1.4em * 2) / 1.2);margin-bottom:calc(1.4em / 1.2);font-size:1.2em;line-height:1.5;font-weight:600;}.css-4em6pe h3,.css-4em6pe h4,.css-4em6pe h5,.css-4em6pe h6{clear:left;margin-top:calc((1.4em * 1.5) / 1.1);margin-bottom:calc(1.4em / 1.1);font-size:1.1em;line-height:1.5;font-weight:600;}.css-4em6pe u{-webkit-text-decoration:none;text-decoration:none;border-bottom:1px solid #444444;}.css-4em6pe b{font-weight:600;}.css-4em6pe sup{font-size:0.8em;}.css-4em6pe sup[data-draft-type=”reference”]{color:#175199;}.css-4em6pe a:focus{outline:none;-webkit-transition:box-shadow 0.3s;transition:box-shadow 0.3s;}html[data-focus-visible] .css-4em6pe a:focus{box-shadow:0 0 0 2px #FFFFFF,0 0 0 4px rgba(5,109,232,0.3);}.css-4em6pe a.ztext-link,.css-4em6pe a.internal,.css-4em6pe a.external{-webkit-text-decoration:none;text-decoration:none;cursor:pointer;border-bottom:1px solid #808080;}.css-4em6pe a.ztext-link:hover,.css-4em6pe a.internal:hover,.css-4em6pe a.external:hover{color:#175199;border-bottom:1px solid #175199;}.css-4em6pe a.ztext-link > .ellipsis::after,.css-4em6pe a.internal > .ellipsis::after,.css-4em6pe a.external > .ellipsis::after{content:”…”;}.css-4em6pe a.ztext-link > .invisible,.css-4em6pe a.internal > .invisible,.css-4em6pe a.external > .invisible{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;}.css-4em6pe a.ztext-link u,.css-4em6pe a.internal u,.css-4em6pe a.external u{border:none;}.css-4em6pe a.member_mention{color:#175199;}.css-4em6pe a.member_mention:hover{border-bottom:1px solid #175199;}.css-4em6pe a.UserLink-link{color:#175199;}.css-4em6pe a.UserLink-link:hover{border-bottom:1px solid #175199;}.css-4em6pe p{margin:1.4em 0;}.css-4em6pe p.ztext-empty-paragraph{margin:calc((2.8em- (1.4em * 2 + 1.6em)) / 2) 0;}.css-4em6pe p.ztext-empty-paragraph + .ztext-empty-paragraph{margin:1.4em 0;}.css-4em6pe hr{margin:4em auto;width:240px;max-width:100%;border:none;border-top:1px solid #D3D3D3;}.css-4em6pe img[eeimg]{max-width:100%;vertical-align:middle;}.css-4em6pe img[eeimg=”1″]{margin:0 3px;max-width:calc(100% – 6px);display:inline-block;}.css-4em6pe img[eeimg=”2″]{margin:1.4em auto;display:block;}.css-4em6pe blockquote{margin:1.4em 0;padding-left:1em;color:#646464;border-left:3px solid #D3D3D3;}.css-4em6pe ol,.css-4em6pe ul{margin:1.4em 0;padding:0;width:100%;}.css-4em6pe ol ol,.css-4em6pe ul ol,.css-4em6pe ol ul,.css-4em6pe ul ul{margin:0;}.css-4em6pe ol li::before,.css-4em6pe ul li::before{width:1em;}.css-4em6pe ol > ol,.css-4em6pe ul > ol,.css-4em6pe ol > ul,.css-4em6pe ul > ul{display:table-row;}.css-4em6pe ol > ol::before,.css-4em6pe ul > ol::before,.css-4em6pe ol > ul::before,.css-4em6pe ul > ul::before{display:table-cell;content:””;}.css-4em6pe ul{display:table;}.css-4em6pe ul>li{display:table-row;list-style:none;}.css-4em6pe ul>li::before{display:table-cell;content:”• “;white-space:pre;}.css-4em6pe ol{display:table;counter-reset:ol;}.css-4em6pe ol > li{display:table-row;list-style:none;}.css-4em6pe ol > li::before{display:table-cell;text-align:right;counter-increment:ol;content:counter(ol) “. “;white-space:pre;}.css-4em6pe ol ol{counter-reset:ol2;}.css-4em6pe ol ol li::before{counter-increment:ol2;content:counter(ol2) “. “;}.css-4em6pe ol ol ol{counter-reset:ol3;}.css-4em6pe ol ol ol li::before{counter-increment:ol3;content:counter(ol3) “. “;}.css-4em6pe ol ol ol ol{counter-reset:ol4;}.css-4em6pe ol ol ol ol li::before{counter-increment:ol4;content:counter(ol4) “. “;}.css-4em6pe figure{margin:1.4em 0;}.css-4em6pe figure .content_image,.css-4em6pe figure .origin_image{margin:0 auto;}.css-4em6pe figure figcaption{margin-top:calc(0.6em / 0.9);padding:0 1em;font-size:0.9em;line-height:1.5;text-align:center;color:#999999;}.css-4em6pe figure + figure{margin-top:calc(1.4em * 1.6);}.css-4em6pe figure[data-size=”small”],.css-4em6pe figure:not([data-size]) > [data-size=”small”]{clear:both;}.css-4em6pe figure[data-size=”left”],.css-4em6pe figure:not([data-size]) > [data-size=”left”]{float:left;margin:0 20px 20px 0;max-width:33%;}.css-4em6pe figure[data-size=”right”],.css-4em6pe figure:not([data-size]) > [data-size=”right”]{float:right;margin:0 0 20px 20px;max-width:33%;}.css-4em6pe figure[data-size=”collapse”]{margin-bottom:0;}.css-4em6pe figure[data-size=”collapse”] + figure{margin-top:0;}.css-4em6pe .content_image,.css-4em6pe .origin_image{display:block;max-width:100%;height:auto;margin:1.4em auto;}.css-4em6pe .content_image[data-size=”small”],.css-4em6pe .origin_image[data-size=”small”]{max-width:40%;}.css-4em6pe .content_image.zh-lightbox-thumb,.css-4em6pe .origin_image.zh-lightbox-thumb{cursor:-webkit-zoom-in;cursor:-moz-zoom-in;cursor:zoom-in;}.css-4em6pe code{margin:0 2px;padding:3px 4px;border-radius:3px;font-family:Menlo,Monaco,Consolas,”Andale Mono”,”lucida console”,”Courier New”,monospace;font-size:0.9em;background-color:#F6F6F6;}.css-4em6pe pre{margin:1.4em 0;padding:calc(0.8em / 0.9);font-size:0.9em;word-break:initial;word-wrap:initial;white-space:pre;overflow:auto;-webkit-overflow-scrolling:touch;background:#F6F6F6;border-radius:4px;}.css-4em6pe pre code{margin:0;padding:0;font-size:inherit;border-radius:0;background-color:inherit;}.css-4em6pe li pre{white-space:pre-wrap;}.css-4em6pe table[data-draft-type=”table”]{border-collapse:collapse;font-size:15px;margin:1.4em auto;max-width:100%;table-layout:fixed;text-align:left;width:100%;}.css-4em6pe table[data-draft-type=”table”][data-size=”small”]{min-width:260px;width:40%;}.css-4em6pe table[data-draft-type=”table”][data-row-style=”striped”] tr:nth-of-type(2n + 1){background:#F6F6F6;}.css-4em6pe table[data-draft-type=”table”] td,.css-4em6pe table[data-draft-type=”table”] th{border:1px solid #D3D3D3;line-height:24px;height:24px;padding:3px 12px;}.css-4em6pe table[data-draft-type=”table”] th{background:#EBEBEB;color:#121212;font-weight:500;}.css-4em6pe .video-box,.css-4em6pe .link-box{position:relative;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;margin:1.4em 0;overflow:auto;white-space:normal;cursor:pointer;border:solid 1px #EBEBEB;border-radius:4px;}.css-4em6pe .lazy[src-status]{background-color:#F6F6F6;}.css-4em6pe .lazy[src-status=”ok”]{background-color:transparent;-webkit-animation:animation-1yvu044 0.5s ease-in;animation:animation-1yvu044 0.5s ease-in;}.css-4em6pe .highlight{margin:1em 0;}.css-4em6pe .highlight pre{margin:0;}.css-4em6pe .highlight .hll{background-color:#FDFDFD;}.css-4em6pe .highlight .c{font-style:italic;color:#999999;}.css-4em6pe .highlight .err{color:#F1403C;}.css-4em6pe .highlight .k{font-weight:600;}.css-4em6pe .highlight .o{font-weight:600;}.css-4em6pe .highlight .cm{font-style:italic;color:#999999;}.css-4em6pe .highlight .cp{font-weight:600;color:#999999;}.css-4em6pe .highlight .c1{font-style:italic;color:#999999;}.css-4em6pe .highlight .cs{font-style:italic;font-weight:600;color:#999999;}.css-4em6pe .highlight .gd{color:#FF3366;}.css-4em6pe .highlight .ge{font-style:italic;}.css-4em6pe .highlight .gr{color:#F1403C;}.css-4em6pe .highlight .gh{color:#999999;}.css-4em6pe .highlight .gi{color:#12b370;}.css-4em6pe .highlight .go{color:#808080;}.css-4em6pe .highlight .gp{color:#646464;}.css-4em6pe .highlight .gs{font-weight:600;}.css-4em6pe .highlight .gu{color:#999999;}.css-4em6pe .highlight .gt{color:#F1403C;}.css-4em6pe .highlight .kc{font-weight:600;}.css-4em6pe .highlight .kd{font-weight:600;}.css-4em6pe .highlight .kn{font-weight:600;}.css-4em6pe .highlight .kp{font-weight:600;}.css-4em6pe .highlight .kr{font-weight:600;}.css-4em6pe .highlight .kt{font-weight:600;color:#175199;}.css-4em6pe .highlight .m{color:#056DE8;}.css-4em6pe .highlight .s{color:#F1403C;}.css-4em6pe .highlight .na{color:#056DE8;}.css-4em6pe .highlight .nb{color:#056DE8;}.css-4em6pe .highlight .nc{font-weight:600;color:#175199;}.css-4em6pe .highlight .no{color:#056DE8;}.css-4em6pe .highlight .ni{color:#5555DD;}.css-4em6pe .highlight .ne{font-weight:600;color:#F1403C;}.css-4em6pe .highlight .nf{font-weight:600;color:#F1403C;}.css-4em6pe .highlight .nn{color:#646464;}.css-4em6pe .highlight .nt{color:#175199;}.css-4em6pe .highlight .nv{color:#056DE8;}.css-4em6pe .highlight .ow{font-weight:600;}.css-4em6pe .highlight .w{color:#BFBFBF;}.css-4em6pe .highlight .mf{color:#056DE8;}.css-4em6pe .highlight .mh{color:#056DE8;}.css-4em6pe .highlight .mi{color:#056DE8;}.css-4em6pe .highlight .mo{color:#056DE8;}.css-4em6pe .highlight .sb{color:#F1403C;}.css-4em6pe .highlight .sc{color:#F1403C;}.css-4em6pe .highlight .sd{color:#F1403C;}.css-4em6pe .highlight .s2{color:#F1403C;}.css-4em6pe .highlight .se{color:#F1403C;}.css-4em6pe .highlight .sh{color:#F1403C;}.css-4em6pe .highlight .si{color:#F1403C;}.css-4em6pe .highlight .sx{color:#F1403C;}.css-4em6pe .highlight .sr{color:#A5542F;}.css-4em6pe .highlight .s1{color:#F1403C;}.css-4em6pe .highlight .ss{color:#F1403C;}.css-4em6pe .highlight .bp{color:#999999;}.css-4em6pe .highlight .vc{color:#056DE8;}.css-4em6pe .highlight .vg{color:#056DE8;}.css-4em6pe .highlight .vi{color:#056DE8;}.css-4em6pe .highlight .il{color:#056DE8;}.css-4em6pe .highlight::-webkit-scrollbar{width:6px;height:6px;}.css-4em6pe .highlight::-webkit-scrollbar-thumb:horizontal{background-color:rgba(18,18,18,0.5);border-radius:6px;}.css-4em6pe .highlight::-webkit-scrollbar-thumb:horizontal:hover{background-color:rgba(18,18,18,0.6);}.css-4em6pe .LinkCard.old{position:relative;display:block;margin:1em auto;width:390px;box-sizing:border-box;border-radius:12px;max-width:100%;overflow:hidden;}.css-4em6pe .LinkCard.old,.css-4em6pe .LinkCard.old:hover{-webkit-text-decoration:none;text-decoration:none;border:none !important;color:inherit !important;}.css-4em6pe .LinkCard-ecommerceLoadingCard{position:relative;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;padding:12px;border-radius:inherit;height:80px;box-sizing:border-box;background:rgba(246,246,246,0.88);color:#D3D3D3;}.css-4em6pe .LinkCard-ecommerceLoadingCardAvatarWrapper{width:60px;height:60px;background:#EBEBEB;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;border-radius:6px;margin-right:10px;}.css-4em6pe .LinkCard-ecommerceLoadingCardNetwork{width:20px;height:20px;}.css-4em6pe .LinkCard-ecommerceLoadingCardLoadingbar{height:60px;-webkit-flex:1;-ms-flex:1;flex:1;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}.css-4em6pe .LinkCard-ecommerceLoadingCardLoadingbar span{height:16px;display:inline-block;background:#EBEBEB;}.css-4em6pe .LinkCard-ecommerceLoadingCardLoadingbar span:nth-of-type(1){width:60px;margin-bottom:4px;}.css-4em6pe .LinkCard-ecommerceLoadingCardLoadingbar span:nth-of-type(2){width:127px;}.css-4em6pe .LinkCard.new{position:relative;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;box-sizing:border-box;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;width:390px;min-height:84px;border-radius:8px;max-width:100%;overflow:hidden;margin:16px auto;padding:12px 12px 9px 12px;background-color:#F6F6F6;}.css-4em6pe .LinkCard.new,.css-4em6pe .LinkCard.new:hover{-webkit-text-decoration:none;text-decoration:none;border:none !important;color:inherit !important;}.css-4em6pe .LinkCard.new .LinkCard-contents{display:block;-webkit-flex:1 1 auto;-ms-flex:1 1 auto;flex:1 1 auto;position:relative;}.css-4em6pe .LinkCard.new .LinkCard-contents .loading{height:14px;background:#EBEBEB;border-radius:7px;}.css-4em6pe .LinkCard.new .LinkCard-contents.withTitle{margin-bottom:3px;}.css-4em6pe .LinkCard.new .LinkCard-title{display:-webkit-box;font-size:15px;font-weight:500;line-height:1.4;margin-bottom:2px;color:#121212;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;}.css-4em6pe .LinkCard.new .LinkCard-title.two-line{line-height:20px;display:-webkit-box;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:2;}.css-4em6pe .LinkCard.new .LinkCard-title.loading{margin-bottom:8px;width:80%;}.css-4em6pe .LinkCard.new .LinkCard-title.loading.withTitle{margin-bottom:6px;}.css-4em6pe .LinkCard.new .LinkCard-title.loadingTitle{margin-bottom:5px;}.css-4em6pe .LinkCard.new .LinkCard-excerpt{display:-webkit-box;text-overflow:ellipsis;font-size:13px;line-height:18px;color:#999999;margin-bottom:4px;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;}.css-4em6pe .LinkCard.new .LinkCard-excerpt .LinkCard-author{color:#444444;}.css-4em6pe .LinkCard.new .LinkCard-desc{display:-webkit-box;font-size:13px;height:18px;line-height:18px;color:#999999;word-break:break-all;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:1;}.css-4em6pe .LinkCard.new .LinkCard-desc .LinkCard-tag,.css-4em6pe .LinkCard.new .LinkCard-desc .tag{display:inline-block;font-size:11px;margin-left:8px;padding:0 4px;border-radius:3px;background:rgba(211,211,211,0.3);}.css-4em6pe .LinkCard.new .LinkCard-desc.loading{width:40%;}.css-4em6pe .LinkCard.new .LinkCard-desc svg{margin-right:2px;}.css-4em6pe .LinkCard.new .LinkCard-image{-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;background-color:#EBEBEB;background-size:cover;background-position:center;position:relative;display:block;width:60px;height:60px;margin-left:20px;object-fit:cover;border-radius:inherit;overflow:hidden;}.css-4em6pe .LinkCard.new .LinkCard-image.LinkCard-image–default{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;background-color:#EBEBEB;color:#D3D3D3;}.css-4em6pe .LinkCard.new .LinkCard-image.LinkCard-image–default svg{color:#999999;}.css-4em6pe .LinkCard.new .LinkCard-image img{width:100%;height:100%;object-fit:cover;}.css-4em6pe .LinkCard.new .LinkCard-image .LinkCard-image–video{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;position:absolute;top:50%;left:50%;-webkit-transform:translateX(-50%) translateY(-50%);-ms-transform:translateX(-50%) translateY(-50%);transform:translateX(-50%) translateY(-50%);width:24px;height:24px;border-radius:12px;background:rgba(255,255,255,0.9);pointer-events:none;}.css-4em6pe .LinkCard.new .LinkCard-image .LinkCard-image–video svg{color:#444444;}.css-4em6pe .LinkCard.new .LinkCard-richText .text{color:#444444;}.css-4em6pe .LinkCard.new .LinkCard-richText .bold{font-weight:600;}.css-4em6pe .LinkCard.new .LinkCard-richText .tag{margin-left:4px;}.css-4em6pe .FileLinkCard{-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;background-color:rgba(246,246,246,0.88);border-radius:12px;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;margin:1em auto;max-width:100%;overflow:hidden;padding:12px;position:relative;width:390px;}.css-4em6pe .FileLinkCard-icon{-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;height:30px;width:30px;}.css-4em6pe .FileLinkCard-info{margin-left:12px;}.css-4em6pe .FileLinkCard-name{color:#121212;font-size:15px;font-weight:500;line-height:21px;display:-webkit-box;text-overflow:ellipsis;overflow:hidden;-webkit-box-orient:vertical;-webkit-line-clamp:2;}.css-4em6pe .FileLinkCard-meta{color:#999999;font-size:12px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;line-height:14px;margin-top:5px;}.css-4em6pe .FileLinkCard-source{white-space:pre;}@-webkit-keyframes animation-1yvu044{from{opacity:0;}to{opacity:1;}}@keyframes animation-1yvu044{from{opacity:0;}to{opacity:1;}}

本教程操作环境:windows7系统、PHP8.1版、Dell G3电脑。

Redis占用内存大小

我们知道Redis是基于内存的key-value数据库,因为系统的内存大小有限,所以我们在使用Redis的时候可以配置Redis能使用的最大的内存大小。

1、通过配置文件配置

通过在Redis安装目录下面的redis.conf配置文件中添加以下配置设置内存大小

//设置Redis最大占用内存大小为100M maxmemory 100mb

redis的配置文件不一定使用的是安装目录下面的redis.conf文件,启动redis服务的时候是可以传一个参数指定redis的配置文件的

2、通过命令修改

Redis支持运行时通过命令动态修改内存大小

//设置Redis最大占用内存大小为100M 127.0.0.1:6379> config set maxmemory 100mb //获取设置的Redis能使用的最大内存大小 127.0.0.1:6379> config get maxmemory

如果不设置最大内存大小或者设置最大内存大小为0,在64位操作系统下不限制内存大小,在32位操作系统下最多使用3GB内存

Redis的内存淘汰

既然可以设置Redis最大占用内存大小,那么配置的内存就有用完的时候。那在内存用完的时候,还继续往Redis里面添加数据不就没内存可用了吗?实际上Redis定义了几种策略用来处理这种情况:noeviction(默认策略):对于写请求不再提供服务,直接返回错误(DEL请求和部分特殊请求除外)allkeys-lru:从所有key中使用LRU算法进行淘汰volatile-lru:从设置了过期时间的key中使用LRU算法进行淘汰allkeys-random:从所有key中随机淘汰数据volatile-random:从设置了过期时间的key中随机淘汰volatile-ttl:在设置了过期时间的key中,根据key的过期时间进行淘汰,越早过期的越优先被淘汰

当使用 volatile-lruvolatile-randomvolatile-ttl这三种策略时,如果没有key可以被淘汰,则和 noeviction一样返回错误

如何获取及设置内存淘汰策略

获取当前内存淘汰策略:

127.0.0.1:6379> config get maxmemory-policy

通过配置文件设置淘汰策略(修改redis.conf文件):

maxmemory-policy allkeys-lru

通过命令修改淘汰策略:

127.0.0.1:6379> config set maxmemory-policy allkeys-lru

LRU算法

什么是LRU?

上面说到了Redis可使用最大内存使用完了,是可以使用LRU算法进行内存淘汰的,那么什么是LRU算法呢?

LRU(Least Recently Used),即最近最少使用,是一种缓存置换算法。在使用内存作为缓存的时候,缓存的大小一般是固定的。当缓存被占满,这个时候继续往缓存里面添加数据,就需要淘汰一部分老的数据,释放内存空间用来存储新的数据。这个时候就可以使用LRU算法了。其核心思想是:如果一个数据在最近一段时间没有被用到,那么将来被使用到的可能性也很小,所以就可以被淘汰掉。

LRU在Redis中的实现

近似LRU算法

Redis使用的是近似LRU算法,它跟常规的LRU算法还不太一样。近似LRU算法通过随机采样法淘汰数据,每次随机出5(默认)个key,从里面淘汰掉最近最少使用的key。

可以通过maxmemory-samples参数修改采样数量:例:maxmemory-samples 10 maxmenory-samples配置的越大,淘汰的结果越接近于严格的LRU算法

Redis为了实现近似LRU算法,给每个key增加了一个额外增加了一个24bit的字段,用来存储该key最后一次被访问的时间。

推荐学习:《PHP视频教程》

hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » php使用redis内存不足怎么办