{"id":474848,"date":"2025-09-12T21:09:10","date_gmt":"2025-09-12T21:09:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=474848"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=474848","title":{"rendered":"<span>\u041f\u043e\u0432\u044b\u0448\u0430\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c Redis: \u0441\u043e\u0432\u0435\u0442\u044b \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439 \u0428\u0438\u0442\u0438\u043a\u043e\u0432, \u044f \u2013 \u0431\u044d\u043a\u0435\u043d\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 \u041f\u0421\u0411.<\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0442\u0435\u043c \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f \u0441 Redis \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0438 \u0437\u043d\u0430\u0435\u0442 \u043e \u0435\u0433\u043e \u0442\u0438\u043f\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e \u043a\u0440\u0430\u0442\u043a\u043e <strong>\u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/strong> \u0438 \u0442\u043e, \u043a\u0430\u043a \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><strong>1. \u0421\u0442\u0440\u043e\u043a\u0430<\/strong> <br \/>      127.0.0.1:6379&gt; set k v OK 127.0.0.1:6379&gt; get k &#171;v&#187; 2. <\/p>\n<p><strong>2.<\/strong> <strong>\u0421\u043f\u0438\u0441\u043e\u043a<\/strong> <br \/>      127.0.0.1:6379&gt; rpush l a b c (integer) 3 127.0.0.1:6379&gt; lrange l 0 -1<\/p>\n<ol>\n<li>\n<p>&#171;a&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;b&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;c&#187;<\/p>\n<p><strong>3. \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e (\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a)<\/strong> <br \/>127.0.0.1:6379&gt; sadd s a a b b c c (integer) 3\u00a0127.0.0.1:6379&gt; smembers s<\/p>\n<\/li>\n<\/ol>\n<ol>\n<li>\n<p>&#171;a&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;b&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;c&#187;<\/p>\n<p><strong>4. \u0425\u0435\u0448 \u2013 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 <\/strong>127.0.0.1:6379&gt;  hset h a 3 b 2 c 1 # \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 {a:3; b:2; c:1} (integer) 3 127.0.0.1:6379&gt; hgetall h<\/p>\n<\/li>\n<\/ol>\n<ol>\n<li>\n<p>&#171;a&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;3&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;b&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;2&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;c&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;1&#187;<\/p>\n<p><strong>5. \u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440<\/strong> <br \/>127.0.0.1:6379&gt; zadd z 77 a 55 b 55 c  # &#8216;a&#8217; \u0441 \u0432\u0435\u0441\u043e\u043c 77, &#8216;b&#8217; \u0441 \u0432\u0435\u0441\u043e\u043c 55 \u0438 &#8216;c&#8217; \u0441 \u0432\u0435\u0441\u043e\u043c 55 (integer) 3 127.0.0.1:6379&gt; zrange z 0 -1<\/p>\n<\/li>\n<\/ol>\n<ol>\n<li>\n<p>&#171;b&#187;# &#8216;b&#8217; \u043f\u0435\u0440\u0432\u0430\u044f, \u0442. \u043a. \u0432\u0435\u0441 \u043d\u0438\u0436\u0435, \u0447\u0435\u043c \u0443 &#8216;a&#8217;, \u0438 \u043b\u0435\u043a\u0441\u0438\u043a\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0434\u0435\u0442 \u0434\u043e &#8216;c&#8217; (\u0432\u0435\u0441 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 &#8212; 55)<\/p>\n<\/li>\n<li>\n<p>&#171;c&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;a&#187;<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/details>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<br \/> <strong>\u041f\u0435\u0440\u0432\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u00a0\u2014 \u043f\u043e\u0438\u0441\u043a \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<br \/> <\/strong><br \/> \u0412\u00a0\u044d\u0442\u043e\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 slowlog\u00a0\u2014 \u043b\u043e\u0433 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<br \/> \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043b\u043e\u0433:<br \/><code> 127.0.0.1:6379&gt; SLOWLOG GET<\/code><\/p>\n<ol>\n<li>\n<p><code>(integer) 42# ID \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 slowlog <\/code><\/p>\n<ol>\n<li>\n<p><code>(integer) 1754771482# UNIX-\u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/code><\/p>\n<\/li>\n<li>\n<p><code>(integer) 78545# \u0412\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \u2192 78.545 \u043c\u0441)<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"lrange\"# \u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u0438 \u0435\u0451 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b: <\/code><\/p>\n<ol>\n<li>\n<p><code>\"list\"<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"0\"<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"-1\"<\/code><\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p><code>\"127.0.0.1:49578\"<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"\"<\/code><\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>\u041a\u0430\u043a\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432\u00a0slowlog? \u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0432\u00a0\u0444\u0430\u0439\u043b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 <em>\/etc\/redis\/redis.conf.<\/em><\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043b\u043e\u0433\u0430:<br \/><code> `127.0.0.1:6379&gt; CONFIG GET slowlog-*<\/code><\/p>\n<ol>\n<li>\n<p><code>\"slowlog-max-len\"<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"128\"                # \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c 128 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"slowlog-log-slower-than\"<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"10000\"              # \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435 10 000 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u043a\u0443\u043d\u0434 (10 \u043c\u0441)`<\/code><\/p>\n<\/li>\n<\/ol>\n<p>Redis \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 <strong>\u041e\u0414\u041d\u041e\u041c<\/strong> \u043f\u043e\u0442\u043e\u043a\u0435. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e\u00a0\u043f\u043e\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043b\u0433\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430, \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0436\u0434\u0443\u0442 \u0441\u0432\u043e\u0435\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.<\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0433\u043e. \u0427\u0442\u043e\u00a0\u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442? \u0412\u0441\u0435\u0433\u0434\u0430\u00a0\u043b\u0438 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e?<\/p>\n<p>\u041d\u0435\u00a0\u0432\u0441\u0435\u0433\u0434\u0430. \u0414\u043e\u043b\u0433\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043e, \u0435\u0441\u043b\u0438:<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445;<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0434\u043a\u043e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u00a0\u0444\u043e\u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445);<\/p>\n<\/li>\n<li>\n<p>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0441\u00a0\u043b\u0443\u0447\u0448\u0435\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0435\u0442.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u043e\u00a0\u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u044d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b \u043a\u00a0\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p><strong>\u0412\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f, \u043a\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f,\u00a0\u2014 \u044d\u0442\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<br \/> <\/strong><br \/> Redis \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u0433\u0434\u0435 \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0443\u043a\u0430\u0437\u0430\u043d\u044b:<\/p>\n<ul>\n<li>\n<p>\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c (Big O notation);<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u043c\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u041e (\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u00ab\u041e \u0431\u043e\u043b\u044c\u0448\u043e\u0435\u00bb ). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: O(n), O(log n), O(n\u00b2).<br \/> \u0427\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 O, \u0442\u0435\u043c \u043d\u0438\u0436\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u00a0\u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041a\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0434\u043b\u044f\u00a0\u043a\u043e\u043c\u0430\u043d\u0434\u044b INCR (\u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 1) \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 O1\u00a0(\u0441\u043c. \u0440\u0438\u0441. 1), \u0442.\u00a0\u0435. \u043e\u0447\u0435\u043d\u044c\u00a0\u0431\u044b\u0441\u0442\u0440\u043e.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f60\/79b\/7d7\/f6079b7d7ed678f9253538a131a452e7.png\" alt=\"\u0420\u0438\u0441. 1. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b INCR \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438\" title=\"\u0420\u0438\u0441. 1. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b INCR \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438\" width=\"801\" height=\"401\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/f60\/79b\/7d7\/f6079b7d7ed678f9253538a131a452e7.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f60\/79b\/7d7\/f6079b7d7ed678f9253538a131a452e7.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0420\u0438\u0441. 1. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b INCR \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/figcaption><\/div>\n<\/figure>\n<p>\u0410\u00a0\u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b KEYS (\u043d\u0430\u0439\u0442\u0438 \u043a\u043b\u044e\u0447 \u043f\u043e\u00a0\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043a\u043b\u044e\u0447\u0435\u0439) \u0443\u0436\u0435 O(n) (\u0441\u043c. \u0440\u0438\u0441. 2). \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e\u00a0\u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0438 n, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u044b\u0435. \u0415\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f 1\u00a0\u043c\u043b\u043d \u043a\u043b\u044e\u0447\u0435\u0439, \u0442\u043e \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u043f\u043e\u00a0\u0432\u0441\u0435\u043c\u0443 1\u00a0\u043c\u043b\u043d.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/214\/0ac\/9a4\/2140ac9a49560d83931721eef2aeceeb.png\" alt=\"\u0420\u0438\u0441. 2. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b KEYS \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438\" title=\"\u0420\u0438\u0441. 2. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b KEYS \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438\" width=\"801\" height=\"401\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/214\/0ac\/9a4\/2140ac9a49560d83931721eef2aeceeb.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/214\/0ac\/9a4\/2140ac9a49560d83931721eef2aeceeb.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0420\u0438\u0441. 2. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b KEYS \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/figcaption><\/div>\n<\/figure>\n<p><strong>\u0414\u043b\u044f\u00a0\u043a\u043e\u043c\u0430\u043d\u0434\u044b KEYS<\/strong> \u043f\u0440\u044f\u043c\u043e \u0432\u00a0\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e\u00a0\u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 SCAN \u0438\u043b\u0438\u00a0\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/strong>:<\/p>\n<p><em>Don&#8217;t use KEYS in your regular application code. If you&#8217;re looking for a way to find keys in a subset of your keyspace, consider using SCAN or sets.<\/em><\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0432\u00a0\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b KEYS \u0438 SCAN:<\/p>\n<p>1. \u0414\u043e\u0431\u0430\u0432\u0438\u043c 1\u00a0\u043c\u043b\u043d. \u043a\u043b\u044e\u0447\u0435\u0439<\/p>\n<p><code>$ for i in {1..1000000}; do\u00a0 \u00a0 redis-cli SET \"key:$i\" \"value-$i\" &gt; \/dev\/null; done<\/code><\/p>\n<p>2. \u041d\u0430\u0439\u0434\u0435\u043c \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0438 \u0447\u0435\u0440\u0435\u0437 KEYS \u0438 \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<p><code>$ time redis-cli KEYS \"*\" | wc -l<\/code><\/p>\n<p><code>real0m0.686s<\/code><\/p>\n<p>3. \u041d\u0430\u0439\u0434\u0435\u043c \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0438 \u0447\u0435\u0440\u0435\u0437 SCAN \u0438 \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<p><code>$ time redis-cli --scan --pattern \"*\" | wc -l<\/code><\/p>\n<p><code>real0m3.849s<\/code><\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442&#8230; \u0447\u0442\u043e\u00a0SCAN \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 5\u00a0\u0440\u0430\u0437 \u0434\u043e\u043b\u044c\u0448\u0435. \u0410\u00a0\u0432\u00a0\u0447\u0435\u043c \u0442\u043e\u0433\u0434\u0430 \u0441\u043c\u044b\u0441\u043b? \u0417\u0430\u0447\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u0441\u043e\u0432\u0435\u0442\u043e\u0432\u0430\u043b\u0438 \u0432\u043c\u0435\u0441\u0442\u043e KEYS?<\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0432\u00a0\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438: SCAN \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u00a0\u043c\u043d\u043e\u0433\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439, \u0432\u00a0\u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437\u00a0\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u043e 10\u00a0\u043a\u043b\u044e\u0447\u0435\u0439. \u041c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c\u0438 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 Redis \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<p>\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e\u00a0\u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 KEYS, \u0442\u043e \u0432\u0441\u0435 \u0432\u0430\u0448\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u00a0\u0441\u0435\u0440\u0432\u0435\u0440\u0443 Redis \u0431\u0443\u0434\u0443\u0442 \u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u043a\u0430 KEYS \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 0.686s. \u0410\u00a0SCAN \u0445\u043e\u0442\u044c \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 3.849s, \u043d\u043e\u00a0\u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0430\u0448\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0434\u0451\u043c \u0435\u0449\u0451 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0435\u0441\u044f \u043a\u00a0\u043e\u0434\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0445 \u0443\u0434\u0430\u043b\u044f\u0442\u044c. <\/p>\n<p><strong>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a:<\/strong><\/p>\n<p>1 \u0414\u043e\u0431\u0430\u0432\u0438\u043c 1\u00a0\u043c\u043b\u043d. \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432\u00a0\u0441\u043f\u0438\u0441\u043e\u043a:<\/p>\n<p><code>$ for i in {1..1000000}; do echo \"RPUSH list $i\"; done | redis-cli \u2013pipe<\/code><\/p>\n<p>2. \u0423\u0434\u0430\u043b\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 1\u00a0000\u00a0000. \u041e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0432\u00a0\u0441\u043f\u0438\u0441\u043a\u0435:<\/p>\n<p><code>127.0.0.1:6379&gt; time redis-cli LREM list 1 1000000 \/\/ 1 \u2013 \u0447\u0438\u0442\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e<\/code><\/p>\n<p><code>(integer) 1<\/code><\/p>\n<p><code>real0m0.060s<\/code><\/p>\n<p><strong>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043b\u044f\u00a0\u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e:<\/strong><\/p>\n<p>1. \u0414\u043e\u0431\u0430\u0432\u0438\u043c 1\u00a0\u043c\u043b\u043d \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432\u00a0\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e:<\/p>\n<p><code>$ for i in {1..1000000}; do \u00a0 \u00a0 echo \"SADD set $i\"; \u00a0 done | redis-cli --pipe;<\/code><\/p>\n<p>2. \u0423\u0434\u0430\u043b\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 1\u00a0000\u00a0000:<\/p>\n<p><code>127.0.0.1:6379&gt; time redis-cli SREM set 1000000<\/code><\/p>\n<p><code>(integer) 1<\/code><\/p>\n<p><code>real0m0.022s<\/code><\/p>\n<p>\u041d\u0430\u0448\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b: \u043f\u043e\u0438\u0441\u043a \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432\u00a0set \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0432 2\u00a0\u0440\u0430\u0437\u0430\u00a0\u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u0432\u00a0list. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p>\u2014 Set \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0445\u0435\u0448\u2011\u0442\u0430\u0431\u043b\u0438\u0446\u0443 (O(1) \u0434\u043b\u044f\u00a0\u043f\u043e\u0438\u0441\u043a\u0430\/\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f)<\/p>\n<p>\u2014 List \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u00a0\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 (O(N) \u0432\u00a0\u0445\u0443\u0434\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435)<\/p>\n<p>\u0412\u00a0\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e\u00a0List\u00a0\u2014 \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f: <\/p>\n<p>\u2014 \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0442\u0435\u043a\u043e\u0432 \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439;<\/p>\n<p>\u2014 \u041e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044f\u043c\u0438 \u0434\u043b\u044f\u00a0\u0444\u043e\u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>\u0410\u00a0\u0432\u043e\u0442 \u043f\u0440\u043e\u00a0Set \u044f\u0432\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f, \u0447\u0442\u043e\u00a0\u043e\u043d \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f\u00a0\u0443\u0447\u0451\u0442\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p><strong>\u0422\u0440\u0435\u0442\u044c\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u00a0\u2014<\/strong> <strong>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430<\/strong>.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u0430\u043c \u043d\u0430\u0434\u043e \u0434\u043b\u044f\u00a0\u043f\u0440\u043e\u0433\u0440\u0435\u0432\u0430 \u043a\u0435\u0448\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 SET. \u041a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043e\u043b\u0433\u0438\u0439 \u043f\u0443\u0442\u044c \u043a\u00a0\u0441\u0435\u0440\u0432\u0435\u0440\u0443 Redis \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0442\u0432\u0435\u0442.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0431\u0435\u0437\u00a0\u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430:<\/p>\n<p><code>$ redis-benchmark -c 1 -n 100000 -q -t SET,GET<\/code><\/p>\n<p><code>SET: 44444.45 requests per second, p50=0.023 msec\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><\/p>\n<p><code>GET: 39463.30 requests per second, p50=0.023 msec\u00a0\u00a0\u00a0\u00a0<\/code><\/p>\n<p>\u0412\u0438\u0434\u0438\u043c, \u0447\u0442\u043e\u00a0\u0441\u043c\u043e\u0433\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u00a0\u0441\u0440\u0435\u0434\u043d\u0435\u043c 40\u00a0\u0442\u044b\u0441. \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u00a0\u0441\u0435\u043a\u0443\u043d\u0434\u0443.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u043d\u0432\u0435\u0439e\u0440. \u0411\u0443\u0434\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u00a0\u043f\u043e\u00a0\u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0432\u00a0Redis, \u0430\u00a0\u0446\u0435\u043b\u044b\u0435 \u043f\u0430\u0447\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434. \u041f\u043e 10\u00a0\u0437\u0430\u00a0\u043e\u0434\u0438\u043d \u0440\u0430\u0437 (\u2011P 10): <\/p>\n<p><code>$ redis-benchmark -c 1 -n 100000 -q -t SET,GET -P 10<\/code><\/p>\n<p><code>SET: 595238.12 requests per second, p50=0.015 msec\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><\/p>\n<p><code>GET: 363636.34 requests per second, p50=0.023 msec\u00a0\u00a0<\/code><\/p>\n<p>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0437\u043a\u043e \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0432 10\u00a0\u0440\u0430\u0437!<\/p>\n<p>\u041c\u043e\u0436\u0435\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u00a0\u0440\u0430\u0437 \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u043c\u0430\u043d\u0434. \u0412\u043e\u0437\u044c\u043c\u0435\u043c 100\u00a0(\u2011P 100):<\/p>\n<p><code>redis-benchmark -c 1 -n 100000 -q -t SET,GET -P 100<\/code><\/p>\n<p><code>SET: 1785714.25 requests per second, p50=0.039 msec\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><\/p>\n<p><code>GET: 2500000.00 requests per second, p50=0.031 msec<\/code><\/p>\n<p>\u0420\u043e\u0441\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439, \u043d\u043e\u00a0\u0443\u0436\u0435 \u043d\u0435\u00a0\u043d\u0430\u00a0\u043f\u043e\u0440\u044f\u0434\u043e\u043a.<\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c 100\u00a0\u0442\u044b\u0441. \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<p>1. \u043f\u043e\u00a0\u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438\u00a0\u2014 \u043c\u0435\u0442\u043e\u0434 setCache<\/p>\n<p>2. \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0432\u0435\u0439e\u0440\u00a0\u2014 \u043c\u0435\u0442\u043e\u0434 setCacheWithPipeline<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><code>package main<\/code><\/p>\n<p><code>import (<\/code><\/p>\n<p><code>\"context\"<\/code><\/p>\n<p><code>\"fmt\"<\/code><\/p>\n<p><code>\"math\/rand\"<\/code><\/p>\n<p><code>\"time\"<\/code><\/p>\n<p><code>\"github.com\/redis\/go-redis\/v9\"<\/code><\/p>\n<p><code>)<\/code><\/p>\n<p><code>func main() {<\/code><\/p>\n<p><code>setCache(context.Background())<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>func setCache(ctx context.Context) {<\/code><\/p>\n<p><code>client := redis.NewClient(&amp;redis.Options{<\/code><\/p>\n<p><code>Addr: \"127.0.0.1:6379\",<\/code><\/p>\n<p><code>})<\/code><\/p>\n<p><code>key := <\/code><a href=\"http:\/\/rand.Int\" rel=\"noopener noreferrer nofollow\"><code>rand.Int<\/code><\/a><code>()<\/code><\/p>\n<p><code>for i := 0; i &lt; 100_000; i++ {<\/code><\/p>\n<p><code>_, err := client.Set(ctx, fmt.Sprintf(\"key:%d:%d\", key, i), <\/code><a href=\"http:\/\/time.Now\" rel=\"noopener noreferrer nofollow\"><code>time.Now<\/code><\/a><code>(), 0).Result()<\/code><\/p>\n<p><code>if err != nil {<\/code><\/p>\n<p><code>panic(\"Unable to set key: \" + err.Error())<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>func setCacheWithPipeline(ctx context.Context) {<\/code><\/p>\n<p><code>client := redis.NewClient(&amp;redis.Options{<\/code><\/p>\n<p><code>Addr: \"127.0.0.1:6379\",<\/code><\/p>\n<p><code>})<\/code><\/p>\n<p><code>key := <\/code><a href=\"http:\/\/rand.Int\" rel=\"noopener noreferrer nofollow\"><code>rand.Int<\/code><\/a><code>()<\/code><\/p>\n<p><code>pipeline := client.Pipeline()<\/code><\/p>\n<p><code>for i := 0; i &lt; 100_000; i++ {<\/code><\/p>\n<p><code>pipeline.Set(ctx, fmt.Sprintf(\"key:%d:%d\", key, i), <\/code><a href=\"http:\/\/time.Now\" rel=\"noopener noreferrer nofollow\"><code>time.Now<\/code><\/a><code>(), 0)<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>_, err := pipeline.Exec(ctx)<\/code><\/p>\n<p><code>if err != nil {<\/code><\/p>\n<p><code>panic(\"Unable to set key: \" + err.Error())<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>}<\/code><\/p>\n<\/div>\n<\/details>\n<p>\u0418 \u0442\u0435\u0441\u0442\u044b \u043d\u0430\u00a0\u044d\u0442\u0438 2\u00a0\u043c\u0435\u0442\u043e\u0434\u0430<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><code>package main<\/code><\/p>\n<p><code>import (<\/code><\/p>\n<p><code>\"context\"<\/code><\/p>\n<p><code>\"testing\"<\/code><\/p>\n<p><code>)<\/code><\/p>\n<p><code>func BenchmarkSetCache(b *testing.B) {<\/code><\/p>\n<p><code>for i := 0; i &lt; b.N; i++ {<\/code><\/p>\n<p><code>setCache(context.Background())<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>func BenchmarkSetCacheWithPipeline(b *testing.B) {<\/code><\/p>\n<p><code>for i := 0; i &lt; b.N; i++ {<\/code><\/p>\n<p><code>setCacheWithPipeline(context.Background())<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>}<\/code><\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0442\u0435\u0441\u0442\u044b:<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><code>$ go test -bench=. -benchmem -benchtime=10s<\/code><\/p>\n<p><code>...<\/code><\/p>\n<p><code>BenchmarkSetCache-22 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 4\u00a0 \u00a0 \u00a0 \u00a0 3056136444 ns\/op\u00a0 \u00a0 \u00a0 \u00a0 32849686 B\/op\u00a0 \u00a0 1199939 allocs\/op<\/code><\/p>\n<p><code>BenchmarkSetCacheWithPipeline-22\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 92 \u00a0 \u00a0 \u00a0 \u00a0 122466863 ns\/op\u00a0 \u00a0 \u00a0 \u00a0 37149145 B\/op \u00a0 \u00a0 799906 allocs\/op<\/code><\/p>\n<\/div>\n<\/details>\n<p>\u0421\u00a0\u043a\u043e\u043d\u0432\u0435\u0439e\u0440\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u0432 25\u00a0\u0440\u0430\u0437.<\/p>\n<p><strong>\u0427\u0435\u0442\u0432\u0451\u0440\u0442\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u00a0\u2014 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/strong><\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0\u043e\u0447\u0435\u0440\u0435\u0434\u044c\u044e (\u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430) \u0432\u00a0Redis:<\/p>\n<p>\u2014 \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u00a0\u043a\u043e\u043d\u0435\u0446 \u043e\u0447\u0435\u0440\u0435\u0434\u0438:<\/p>\n<p><code>127.0.0.1:6379&gt; rpush queue 1 2 3 4 5<\/code><\/p>\n<p><code>(integer) 5<\/code><\/p>\n<p>\u2014 \u0412\u0442\u043e\u0440\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0432\u00a0\u0446\u0438\u043a\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437\u00a0\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438:<\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>\"1\"<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>\"2\"<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>\"3\"<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>\"4\"<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>\"5\"<\/code><\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043a\u043e\u0433\u0434\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0443\u0441\u0442\u0430, \u043d\u043e\u00a0\u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0435\u0451:<\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>(nil)<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>(nil)<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>(nil)<\/code><\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a\u00a0\u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043d\u0430\u00a0Redis.<\/p>\n<p>\u042d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0436\u0434\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f\u00a0\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e.<\/p>\n<p>\u0414\u043b\u044f\u00a0\u043c\u043d\u043e\u0433\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u00a0\u043d\u0430\u0447\u0430\u043b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f &#171;b&#187;.<\/p>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0440:<\/em> \u0416\u0434\u0435\u043c 30\u00a0\u0441\u0435\u043a\u0443\u043d\u0434, \u043f\u043e\u043a\u0430 \u0432\u00a0\u0441\u043f\u0438\u0441\u043a\u0435 queue \u043d\u0435\u00a0\u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041a\u0430\u043a\u00a0\u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f, \u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f. <\/p>\n<p><code>127.0.0.1:6379&gt; blpop queue 30<\/code><\/p>\n<p>\u0418 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0435\u00a0\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0432\u0435\u0441\u044c Redis. \u0414\u0440\u0443\u0433\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<p>\u041d\u043e\u00a0\u0435\u0441\u0442\u044c \u043d\u044e\u0430\u043d\u0441. \u0411\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u0435\u0440\u0436\u0438\u0442 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\ufffd\ufffd \u0441\u00a0\u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c Redis. \u041d\u0430\u0434\u043e \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 (maxclients):<\/p>\n<p><code>$ redis-cli INFO clients<\/code><\/p>\n<p><code># Clients<\/code><\/p>\n<p><code>connected_clients:2<\/code><\/p>\n<p><code>cluster_connections:0<\/code><\/p>\n<p><code>maxclients:10000<\/code><\/p>\n<p><code>client_recent_max_input_buffer:20523<\/code><\/p>\n<p><code>client_recent_max_output_buffer:0<\/code><\/p>\n<p><code><strong>blocked_clients<\/strong>:1<\/code><\/p>\n<p><strong>\u041f\u044f\u0442\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u00a0\u2014 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440.<\/strong><\/p>\n<p>\u041c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0434\u044b \u0434\u043b\u044f\u00a0\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442:<\/p>\n<p>1. \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c \u0447\u0442\u0435\u043d\u0438\u044f (GET, LRANGE \u0438\u00a0\u0442.\u00a0\u0434.)<\/p>\n<p>\u2014 \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u043f\u043b\u0438\u043a (read replicas) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0447\u0442\u0435\u043d\u0438\u044f.<\/p>\n<p>2. \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c \u0437\u0430\u043f\u0438\u0441\u0438 (SET, LPUSH \u0438\u00a0\u0442.\u00a0\u0434.)<\/p>\n<p>\u2014 \u0428\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 (\u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u00a0\u0443\u0437\u043b\u0430\u043c) \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043e\u0431\u0449\u0443\u044e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0443\u044e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c:<\/p>\n<p>\u2014 \u041c\u0430\u0441\u0442\u0435\u0440\u2011\u043d\u043e\u0434\u044b. \u0412\u00a0\u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u2014 \u0420\u0435\u043f\u043b\u0438\u043a\u0438. \u041a\u043e\u043f\u0438\u0440\u0443\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437\u00a0\u043c\u0430\u0441\u0442\u0435\u0440\u0430.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0443\u043c 3\u00a0\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 6\u00a0\u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 Redis, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u043d\u0430\u00a0\u043d\u0438\u0445\u00a0\u2014 \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u00a0\u0434\u0432\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043d\u0430\u00a0\u0441\u0435\u0440\u0432\u0435\u0440 (\u0440\u0438\u0441. 3).<\/p>\n<p>\u0422\u0440\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0431\u0443\u0434\u0443\u0442 \u043c\u0430\u0441\u0442\u0435\u0440\u0430\u043c\u0438, \u0430\u00a0\u0435\u0449\u0435 \u0442\u0440\u0438\u00a0\u2014 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u043e\u0434\u0447\u0438\u043d\u0435\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0430\u0441\u0442\u0435\u0440\u0430. \u0412\u0430\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0447\u0438\u043d\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f\u00a0\u0441\u0432\u043e\u0435\u0433\u043e \u043c\u0430\u0441\u0442\u0435\u0440\u0430 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u0441\u044f \u043d\u0430\u00a0\u0434\u0440\u0443\u0433\u043e\u043c \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/498\/cbb\/82e\/498cbb82e1ec4883c5a13150510b5acc.png\" alt=\"\u0420\u0438\u0441. 3. \u041e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\" title=\"\u0420\u0438\u0441. 3. \u041e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\" width=\"801\" height=\"401\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/498\/cbb\/82e\/498cbb82e1ec4883c5a13150510b5acc.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/498\/cbb\/82e\/498cbb82e1ec4883c5a13150510b5acc.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0420\u0438\u0441. 3. \u041e\u0442\u043a\u0430\u0437\u043e\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440 Redis:<\/p>\n<p>1. \u0423\u00a0\u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 6\u00a0\u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u0432\u00a0\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0434\u0441\u0435\u0442\u0438:<\/p>\n<p>172.28.2.11, 172.28.2.12, 172.28.2.13, 172.28.2.14, 172.28.2.15, 172.28.2.16<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0438\u0445 \u0447\u0435\u0440\u0435\u0437 docker. \u041f\u0440\u0438\u043c\u0435\u0440 docker\u2011compose.yml<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><code>version: '3.8'<\/code><\/p>\n<p><code>services:<\/code><\/p>\n<p><code>\u00a0\u00a0redis-node-1:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0image: redis:7.2<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0container_name: redis-node-1<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0volumes:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- .\/redis.conf:\/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- redis-data-1:\/data<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0command: redis-server \/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0ports:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- \"7001:6379\"<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0networks:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0redis-cluster-net:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ipv4_address: 172.28.2.11<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0healthcheck:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0test: [\"CMD\", \"redis-cli\", \"ping\"]<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0interval: 1s<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0timeout: 3s<\/code><\/p>\n<p><code>\u00a0\u00a0redis-node-2:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0image: redis:7.2<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0container_name: redis-node-2<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0volumes:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- .\/redis.conf:\/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- redis-data-2:\/data<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0command: redis-server \/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0ports:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- \"7002:6379\"<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0networks:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0redis-cluster-net:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ipv4_address: 172.28.2.12<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0healthcheck:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0test: [\"CMD\", \"redis-cli\", \"ping\"]<\/code><\/p>\n<p><code>\u00a0\u00a0redis-node-3:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0image: redis:7.2<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0container_name: redis-node-3<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0volumes:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- .\/redis.conf:\/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- redis-data-3:\/data<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0command: redis-server \/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0ports:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- \"7003:6379\"<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0networks:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0redis-cluster-net:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ipv4_address: 172.28.2.13<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0healthcheck:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0test: [\"CMD\", \"redis-cli\", \"ping\"]<\/code><\/p>\n<p><code>\u00a0\u00a0redis-node-4:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0image: redis:7.2<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0container_name: redis-node-4<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0volumes:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- .\/redis.conf:\/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- redis-data-4:\/data<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0command: redis-server \/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0ports:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- \"7004:6379\"<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0networks:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0redis-cluster-net:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ipv4_address: 172.28.2.14<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0healthcheck:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0test: [\"CMD\", \"redis-cli\", \"ping\"]<\/code><\/p>\n<p><code>\u00a0\u00a0redis-node-5:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0image: redis:7.2<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0container_name: redis-node-5<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0volumes:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- .\/redis.conf:\/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- redis-data-5:\/data<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0command: redis-server \/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0ports:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- \"7005:6379\"<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0networks:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0redis-cluster-net:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ipv4_address: 172.28.2.15<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0healthcheck:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0test: [\"CMD\", \"redis-cli\", \"ping\"]<\/code><\/p>\n<p><code>\u00a0\u00a0redis-node-6:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0image: redis:7.2<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0container_name: redis-node-6<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0volumes:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- .\/redis.conf:\/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- redis-data-6:\/data<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0command: redis-server \/usr\/local\/etc\/redis\/redis.conf<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0ports:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- \"7006:6379\"<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0networks:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0redis-cluster-net:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ipv4_address: 172.28.2.16<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0healthcheck:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0test: [\"CMD\", \"redis-cli\", \"ping\"]<\/code><\/p>\n<p><code>networks:<\/code><\/p>\n<p><code>\u00a0\u00a0redis-cluster-net:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0driver: bridge<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0ipam:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0config:<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- subnet: 172.28.2.0\/24<\/code><\/p>\n<p><code>volumes:<\/code><\/p>\n<p><code>\u00a0\u00a0redis-data-1:<\/code><\/p>\n<p><code>\u00a0\u00a0redis-data-2:<\/code><\/p>\n<p><code>\u00a0\u00a0redis-data-3:<\/code><\/p>\n<p><code>\u00a0\u00a0redis-data-4:<\/code><\/p>\n<p><code>\u00a0\u00a0redis-data-5:<\/code><\/p>\n<p><code>\u00a0\u00a0redis-data-6:<\/code><\/p>\n<\/div>\n<\/details>\n<p>2. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 redis.conf (\u0444\u0430\u0439\u043b \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0440\u044f\u0434\u043e\u043c \u0441\u00a0docker\u2011compose.yml), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440:<\/p>\n<p><code>port 6379<\/code><\/p>\n<p><code>bind 0.0.0.0<\/code><\/p>\n<p><code>cluster-enabled yes<\/code><\/p>\n<p><code>cluster-config-file \/data\/nodes.conf<\/code><\/p>\n<p><code>cluster-node-timeout 5000<\/code><\/p>\n<p><strong>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/strong><\/p>\n<p><strong>port<\/strong>\u00a0\u2014 \u043f\u043e\u0440\u0442, \u043d\u0430\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c Redis \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f;<\/p>\n<p><strong>bind 0.0.0.0<\/strong>\u00a0\u2014 \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u0441\u00a0\u043b\u044e\u0431\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. <strong>\u041e\u043f\u0430\u0441\u043d\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430! \u041f\u043e\u2011\u0445\u043e\u0440\u043e\u0448\u0435\u043c\u0443 \u043d\u0430\u0434\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u044b\u0435 ip<\/strong>;<\/p>\n<p><strong>cluster\u2011enabled<\/strong>\u00a0\u2014 \u0440\u0435\u0436\u0438\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430;<\/p>\n<p><strong>cluster\u2011config\u2011file<\/strong>\u00a0\u2014 Redis \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0441\u044e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u00a0\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435;<\/p>\n<p><strong>cluster\u2011node\u2011timeout<\/strong>\u00a0\u2014 \u0432\u0440\u0435\u043c\u044f (\u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445), \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u0437\u0435\u043b \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c.<\/p>\n<p>3. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a\u00a0\u043b\u044e\u0431\u043e\u0439 \u043d\u043e\u0434\u0435 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 (\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0432\u0441\u0435 6\u00a0\u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430). \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2011cluster\u2011replicas 1\u00a0\u0441\u043e\u0437\u0434\u0430\u0441\u0442 3\u00a0\u043c\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 3\u00a0\u0440\u0435\u043f\u043b\u0438\u043a\u0438 (\u043f\u043e 1\u00a0\u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0430\u0441\u0442\u0435\u0440):<br \/><code># redis-cli --cluster create 172.28.2.11:6379 172.28.2.12:6379 172.28.2.13:6379 172.28.2.14:6379 172.28.2.15:6379 172.28.2.16:6379 --cluster-replicas 1<\/code><\/p>\n<p>Redis \u0441\u0430\u043c \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u0442 \u043d\u0430\u0441 \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u0442\u044c\u0441\u044f \u0441\u00a0\u044d\u0442\u0438\u043c.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><code>&gt;&gt;&gt; Performing hash slots allocation on 6 nodes...<\/code><\/p>\n<p><code>Master[0] -&gt; Slots 0 - 5460<\/code><\/p>\n<p><code>Master[1] -&gt; Slots 5461 - 10922<\/code><\/p>\n<p><code>Master[2] -&gt; Slots 10923 - 16383<\/code><\/p>\n<p><code>Adding replica 172.28.2.15:6379 to 172.28.2.11:6379<\/code><\/p>\n<p><code>Adding replica 172.28.2.16:6379 to 172.28.2.12:6379<\/code><\/p>\n<p><code>Adding replica 172.28.2.14:6379 to 172.28.2.13:6379<\/code><\/p>\n<p><code>M: 682a377f37d1fcae4a88187adc885396884639b5 172.28.2.11:6379<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0slots:[0-5460] (5461 slots) master<\/code><\/p>\n<p><code>M: c66c78becf2ed82bce0bb31557426138246cec66 172.28.2.12:6379<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0slots:[5461-10922] (5462 slots) master<\/code><\/p>\n<p><code>M: b7670e33abd7fa8150d732c6579ebc14d241bf09 172.28.2.13:6379<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0slots:[10923-16383] (5461 slots) master<\/code><\/p>\n<p><code>S: 972163dcf808fa97a66303e8659c2ea34883e867 172.28.2.14:6379<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0replicates b7670e33abd7fa8150d732c6579ebc14d241bf09<\/code><\/p>\n<p><code>S: 05a6f904987d06a1e6330fcdc9dbea9417806014 172.28.2.15:6379<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0replicates 682a377f37d1fcae4a88187adc885396884639b5<\/code><\/p>\n<p><code>S: dd7de192219903c5639cea47043b922e6ebeecff 172.28.2.16:6379<\/code><\/p>\n<p><code>\u00a0\u00a0\u00a0replicates c66c78becf2ed82bce0bb31557426138246cec66<\/code><\/p>\n<p><code>Can I set the above configuration? (type 'yes' to accept): yes<\/code><\/p>\n<p><code>&gt;&gt;&gt; Nodes configuration updated<\/code><\/p>\n<p><code>&gt;&gt;&gt; Assign a different config epoch to each node<\/code><\/p>\n<p><code>&gt;&gt;&gt; Sending CLUSTER MEET messages to join the cluster<\/code><\/p>\n<p><code>Waiting for the cluster to join<\/code><\/p>\n<\/div>\n<\/details>\n<p>\u0412\u0441\u0451! \u041a\u043b\u0430\u0441\u0442\u0435\u0440 \u043f\u043e\u0434\u043d\u044f\u0442! \u041d\u0430\u00a0\u0440\u0438\u0441. 4\u00a0\u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/be6\/e3b\/1b0\/be6e3b1b0863a12a24e431504b4d2b5e.png\" alt=\"\u0420\u0438\u0441. 4. \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u043d\u0430 6 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445\" title=\"\u0420\u0438\u0441. 4. \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u043d\u0430 6 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445\" width=\"801\" height=\"401\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/be6\/e3b\/1b0\/be6e3b1b0863a12a24e431504b4d2b5e.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/be6\/e3b\/1b0\/be6e3b1b0863a12a24e431504b4d2b5e.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0420\u0438\u0441. 4. \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u043d\u0430 6 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u00a0\u043a\u043b\u044e\u0447 &#8216;x&#8217; \u044f\u0432\u043d\u043e \u0432\u00a0\u043c\u0430\u0441\u0442\u0435\u0440 172.28.2.11. \u041f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<p><code># redis-cli -h 172.28.2.11 set x 5<\/code><\/p>\n<p><code>(error) MOVED 16287 172.28.2.13:6379<\/code><\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0432\u00a0\u043c\u0430\u0441\u0442\u0435\u0440 \u043d\u0430 172.28.2.13. \u0422\u0443\u0442 \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e:<\/p>\n<p><code># redis-cli -h 172.28.2.13 set x 5<\/code><\/p>\n<p><code>OK<\/code><\/p>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442?<\/p>\n<p>\u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441\u00a0\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u043e\u0442\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u043c\u0430\u0441\u0442\u0435\u0440\u0430\u043c\u0438. \u0412\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043e\u0442\u00a0Redis:<\/p>\n<p><code>Master[0] -&gt; Slots 0 - 5460<\/code><\/p>\n<p><code>Master[1] -&gt; Slots 5461 - 10922<\/code><\/p>\n<p><code>Master[2] -&gt; Slots 10923 - 16383<\/code><\/p>\n<p>\u0412\u0441\u0435\u0433\u043e 16\u00a0384\u00a0\u0441\u043b\u043e\u0442\u043e\u0432. <\/p>\n<p>\u041a\u043b\u044e\u0447 &#8216;x&#8217; \u0438\u043c\u0435\u0435\u0442 \u0445\u0435\u0448\u2011\u0441\u043b\u043e\u0442 16287. \u041e\u043d \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a\u00a0Master[2] \u0447\u0442\u043e\u00a0\u0432\u00a0\u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 172.28.2.13.<\/p>\n<p>\u041a\u043b\u044e\u0447 <strong>\u2011c<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u00a0\u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0447\u0435\u0440\u0435\u0437 \u043b\u044e\u0431\u0443\u044e \u043d\u043e\u0434\u0443:<\/p>\n<p><code># redis-cli -c -h 172.28.2.11 set x 5<\/code><\/p>\n<p><code>OK<\/code><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#8216;x&#8217; \u0438\u0437\u00a0\u043c\u0430\u0441\u0442\u0435\u0440\u0430 172.28.2.13. \u0412\u0441\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:<\/p>\n<p><code>root@e25869d27fdd:\/data# redis-cli -h 172.28.2.13 get x\u00a0<\/code><\/p>\n<p><code>\"5\"<\/code><\/p>\n<p>\u0415\u0433\u043e \u0440\u0435\u043f\u043b\u0438\u043a\u0430 \u043f\u043e\u00a0\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u00a0Redis\u00a0\u2014 172.28.2.14. \u0412\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0432\u044b\u0448\u0435:<br \/>Adding replica 172.28.2.14:6379\u00a0to 172.28.2.13:6379<\/p>\n<p>\u0412\u0441\u0435 \u0447\u0442\u043e\u00a0\u043f\u0438\u0448\u0435\u043c \u0432\u00a0\u043c\u0430\u0441\u0442\u0435\u0440, \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432\u00a0\u0440\u0435\u043f\u043b\u0438\u043a\u0443. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0437\u00a0\u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<p><code>root@e25869d27fdd:\/data# redis-cli -h 172.28.2.14 get x\u00a0<\/code><\/p>\n<p><code>(error) MOVED 16287 172.28.2.13:6379<\/code><\/p>\n<p>\u041d\u0435\u00a0\u0441\u043c\u043e\u0433\u043b\u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u0432\u00a0\u0440\u0435\u043f\u043b\u0438\u043a\u0443 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u00a0\u043c\u0430\u0441\u0442\u0435\u0440\u0430. \u0418 \u043f\u043e\u00a0\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0447\u0442\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u043e. \u041c\u043e\u0436\u0435\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0437\u00a0\u0440\u0435\u043f\u043b\u0438\u043a\u0438. \u041d\u041e! \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e\u00a0\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432\u00a0\u0440\u0435\u043f\u043b\u0438\u043a\u0443 \u043d\u0435\u00a0\u043c\u043e\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u043e. \u0442.\u00a0\u0435. \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442\u00a0\u0431\u044b\u0442\u044c \u0432\u00a0\u043c\u0430\u0441\u0442\u0435\u0440\u0435, \u043d\u043e\u00a0\u0435\u0449\u0451 \u043d\u0435\u00a0\u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432\u00a0\u0440\u0435\u043f\u043b\u0438\u043a\u0443. <\/p>\n<p>\u0412\u043a\u043b\u044e\u0447\u0438\u043c \u0447\u0442\u0435\u043d\u0438\u0435 \u0432\u00a0\u0440\u0435\u043f\u043b\u0438\u043a\u0435 \u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u00a0\u043a\u043b\u044e\u0447\u0443:<\/p>\n<p><code>root@e25869d27fdd:\/data# redis-cli -h 172.28.2.14<\/code><\/p>\n<p><code>172.28.2.14:6379&gt; READONLY<\/code><\/p>\n<p><code>OK<\/code><\/p>\n<p><code>172.28.2.14:6379&gt; GET x<\/code><\/p>\n<p><code>\"5\"<\/code><\/p>\n<p>\u0412\u0443\u0430\u043b\u044f! \u0412\u043e\u0442 \u0442\u0430\u043a\u0438\u043c\u0438 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u044f\u043c\u0438 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0441\u0432\u043e\u0439 Redis. \u0420\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0439\u0442\u0435 \u0432\u00a0\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043e\u00a0\u0441\u0432\u043e\u0451\u043c \u043e\u043f\u044b\u0442\u0435 \u0438 \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0441\u0432\u043e\u0438\u043c\u0438 \u0441\u043e\u0432\u0435\u0442\u0430\u043c\u0438, \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c \u0434\u043e\u0447\u0438\u0442\u0430\u0432\u0448\u0438\u043c, \u0443\u0434\u0430\u0447\u0438 \u0432\u00a0\u0440\u0430\u0431\u043e\u0442\u0435!<\/p>\n<p><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/944890\/\"> https:\/\/habr.com\/ru\/articles\/944890\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439 \u0428\u0438\u0442\u0438\u043a\u043e\u0432, \u044f \u2013 \u0431\u044d\u043a\u0435\u043d\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 \u041f\u0421\u0411.<\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0442\u0435\u043c \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f \u0441 Redis \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0438 \u0437\u043d\u0430\u0435\u0442 \u043e \u0435\u0433\u043e \u0442\u0438\u043f\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e \u043a\u0440\u0430\u0442\u043a\u043e <strong>\u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/strong> \u0438 \u0442\u043e, \u043a\u0430\u043a \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><strong>1. \u0421\u0442\u0440\u043e\u043a\u0430<\/strong> <br \/>      127.0.0.1:6379&gt; set k v OK 127.0.0.1:6379&gt; get k &#171;v&#187; 2. <\/p>\n<p><strong>2.<\/strong> <strong>\u0421\u043f\u0438\u0441\u043e\u043a<\/strong> <br \/>      127.0.0.1:6379&gt; rpush l a b c (integer) 3 127.0.0.1:6379&gt; lrange l 0 -1<\/p>\n<ol>\n<li>\n<p>&#171;a&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;b&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;c&#187;<\/p>\n<p><strong>3. \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e (\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a)<\/strong> <br \/>127.0.0.1:6379&gt; sadd s a a b b c c (integer) 3\u00a0127.0.0.1:6379&gt; smembers s<\/p>\n<\/li>\n<\/ol>\n<ol>\n<li>\n<p>&#171;a&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;b&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;c&#187;<\/p>\n<p><strong>4. \u0425\u0435\u0448 \u2013 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 <\/strong>127.0.0.1:6379&gt;  hset h a 3 b 2 c 1 # \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 {a:3; b:2; c:1} (integer) 3 127.0.0.1:6379&gt; hgetall h<\/p>\n<\/li>\n<\/ol>\n<ol>\n<li>\n<p>&#171;a&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;3&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;b&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;2&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;c&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;1&#187;<\/p>\n<p><strong>5. \u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440<\/strong> <br \/>127.0.0.1:6379&gt; zadd z 77 a 55 b 55 c  # &#8216;a&#8217; \u0441 \u0432\u0435\u0441\u043e\u043c 77, &#8216;b&#8217; \u0441 \u0432\u0435\u0441\u043e\u043c 55 \u0438 &#8216;c&#8217; \u0441 \u0432\u0435\u0441\u043e\u043c 55 (integer) 3 127.0.0.1:6379&gt; zrange z 0 -1<\/p>\n<\/li>\n<\/ol>\n<ol>\n<li>\n<p>&#171;b&#187;# &#8216;b&#8217; \u043f\u0435\u0440\u0432\u0430\u044f, \u0442. \u043a. \u0432\u0435\u0441 \u043d\u0438\u0436\u0435, \u0447\u0435\u043c \u0443 &#8216;a&#8217;, \u0438 \u043b\u0435\u043a\u0441\u0438\u043a\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0434\u0435\u0442 \u0434\u043e &#8216;c&#8217; (\u0432\u0435\u0441 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 &#8212; 55)<\/p>\n<\/li>\n<li>\n<p>&#171;c&#187;<\/p>\n<\/li>\n<li>\n<p>&#171;a&#187;<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/details>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<br \/> <strong>\u041f\u0435\u0440\u0432\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u00a0\u2014 \u043f\u043e\u0438\u0441\u043a \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<br \/> <\/strong><br \/> \u0412\u00a0\u044d\u0442\u043e\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 slowlog\u00a0\u2014 \u043b\u043e\u0433 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<br \/> \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043b\u043e\u0433:<br \/><code> 127.0.0.1:6379&gt; SLOWLOG GET<\/code><\/p>\n<ol>\n<li>\n<p><code>(integer) 42# ID \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 slowlog <\/code><\/p>\n<ol>\n<li>\n<p><code>(integer) 1754771482# UNIX-\u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/code><\/p>\n<\/li>\n<li>\n<p><code>(integer) 78545# \u0412\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \u2192 78.545 \u043c\u0441)<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"lrange\"# \u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u0438 \u0435\u0451 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b: <\/code><\/p>\n<ol>\n<li>\n<p><code>\"list\"<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"0\"<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"-1\"<\/code><\/p>\n<\/li>\n<\/ol>\n<\/li>\n<li>\n<p><code>\"127.0.0.1:49578\"<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"\"<\/code><\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>\u041a\u0430\u043a\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432\u00a0slowlog? \u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0432\u00a0\u0444\u0430\u0439\u043b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 <em>\/etc\/redis\/redis.conf.<\/em><\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043b\u043e\u0433\u0430:<br \/><code> `127.0.0.1:6379&gt; CONFIG GET slowlog-*<\/code><\/p>\n<ol>\n<li>\n<p><code>\"slowlog-max-len\"<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"128\"                # \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c 128 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"slowlog-log-slower-than\"<\/code><\/p>\n<\/li>\n<li>\n<p><code>\"10000\"              # \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435 10 000 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u043a\u0443\u043d\u0434 (10 \u043c\u0441)`<\/code><\/p>\n<\/li>\n<\/ol>\n<p>Redis \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 <strong>\u041e\u0414\u041d\u041e\u041c<\/strong> \u043f\u043e\u0442\u043e\u043a\u0435. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e\u00a0\u043f\u043e\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043b\u0433\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430, \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0436\u0434\u0443\u0442 \u0441\u0432\u043e\u0435\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.<\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0433\u043e. \u0427\u0442\u043e\u00a0\u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442? \u0412\u0441\u0435\u0433\u0434\u0430\u00a0\u043b\u0438 \u044d\u0442\u043e \u043f\u043b\u043e\u0445\u043e?<\/p>\n<p>\u041d\u0435\u00a0\u0432\u0441\u0435\u0433\u0434\u0430. \u0414\u043e\u043b\u0433\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u043d\u043e, \u0435\u0441\u043b\u0438:<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445;<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0434\u043a\u043e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u00a0\u0444\u043e\u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445);<\/p>\n<\/li>\n<li>\n<p>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0441\u00a0\u043b\u0443\u0447\u0448\u0435\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0435\u0442.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u043e\u00a0\u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u044d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b \u043a\u00a0\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p><strong>\u0412\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f, \u043a\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f,\u00a0\u2014 \u044d\u0442\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<br \/> <\/strong><br \/> Redis \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u0433\u0434\u0435 \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0443\u043a\u0430\u0437\u0430\u043d\u044b:<\/p>\n<ul>\n<li>\n<p>\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c (Big O notation);<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u043c\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u041e (\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u00ab\u041e \u0431\u043e\u043b\u044c\u0448\u043e\u0435\u00bb ). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: O(n), O(log n), O(n\u00b2).<br \/> \u0427\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 O, \u0442\u0435\u043c \u043d\u0438\u0436\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u00a0\u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041a\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0434\u043b\u044f\u00a0\u043a\u043e\u043c\u0430\u043d\u0434\u044b INCR (\u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 1) \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 O1\u00a0(\u0441\u043c. \u0440\u0438\u0441. 1), \u0442.\u00a0\u0435. \u043e\u0447\u0435\u043d\u044c\u00a0\u0431\u044b\u0441\u0442\u0440\u043e.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0420\u0438\u0441. 1. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b INCR \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/figcaption><\/div>\n<\/figure>\n<p>\u0410\u00a0\u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b KEYS (\u043d\u0430\u0439\u0442\u0438 \u043a\u043b\u044e\u0447 \u043f\u043e\u00a0\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043a\u043b\u044e\u0447\u0435\u0439) \u0443\u0436\u0435 O(n) (\u0441\u043c. \u0440\u0438\u0441. 2). \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e\u00a0\u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0438 n, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u044b\u0435. \u0415\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f 1\u00a0\u043c\u043b\u043d \u043a\u043b\u044e\u0447\u0435\u0439, \u0442\u043e \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u043f\u043e\u00a0\u0432\u0441\u0435\u043c\u0443 1\u00a0\u043c\u043b\u043d.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0420\u0438\u0441. 2. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b KEYS \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/figcaption><\/div>\n<\/figure>\n<p><strong>\u0414\u043b\u044f\u00a0\u043a\u043e\u043c\u0430\u043d\u0434\u044b KEYS<\/strong> \u043f\u0440\u044f\u043c\u043e \u0432\u00a0\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e\u00a0\u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>\u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 SCAN \u0438\u043b\u0438\u00a0\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/strong>:<\/p>\n<p><em>Don&#8217;t use KEYS in your regular application code. If you&#8217;re looking for a way to find keys in a subset of your keyspace, consider using SCAN or sets.<\/em><\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0432\u00a0\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b KEYS \u0438 SCAN:<\/p>\n<p>1. \u0414\u043e\u0431\u0430\u0432\u0438\u043c 1\u00a0\u043c\u043b\u043d. \u043a\u043b\u044e\u0447\u0435\u0439<\/p>\n<p><code>$ for i in {1..1000000}; do\u00a0 \u00a0 redis-cli SET \"key:$i\" \"value-$i\" &gt; \/dev\/null; done<\/code><\/p>\n<p>2. \u041d\u0430\u0439\u0434\u0435\u043c \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0438 \u0447\u0435\u0440\u0435\u0437 KEYS \u0438 \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<p><code>$ time redis-cli KEYS \"*\" | wc -l<\/code><\/p>\n<p><code>real0m0.686s<\/code><\/p>\n<p>3. \u041d\u0430\u0439\u0434\u0435\u043c \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0438 \u0447\u0435\u0440\u0435\u0437 SCAN \u0438 \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<p><code>$ time redis-cli --scan --pattern \"*\" | wc -l<\/code><\/p>\n<p><code>real0m3.849s<\/code><\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442&#8230; \u0447\u0442\u043e\u00a0SCAN \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 5\u00a0\u0440\u0430\u0437 \u0434\u043e\u043b\u044c\u0448\u0435. \u0410\u00a0\u0432\u00a0\u0447\u0435\u043c \u0442\u043e\u0433\u0434\u0430 \u0441\u043c\u044b\u0441\u043b? \u0417\u0430\u0447\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u0441\u043e\u0432\u0435\u0442\u043e\u0432\u0430\u043b\u0438 \u0432\u043c\u0435\u0441\u0442\u043e KEYS?<\/p>\n<p>\u041e\u0442\u0432\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u0432\u00a0\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438: SCAN \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u00a0\u043c\u043d\u043e\u0433\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439, \u0432\u00a0\u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437\u00a0\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u043e 10\u00a0\u043a\u043b\u044e\u0447\u0435\u0439. \u041c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c\u0438 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 Redis \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<p>\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e\u00a0\u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 KEYS, \u0442\u043e \u0432\u0441\u0435 \u0432\u0430\u0448\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u00a0\u0441\u0435\u0440\u0432\u0435\u0440\u0443 Redis \u0431\u0443\u0434\u0443\u0442 \u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u043a\u0430 KEYS \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 0.686s. \u0410\u00a0SCAN \u0445\u043e\u0442\u044c \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 3.849s, \u043d\u043e\u00a0\u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0430\u0448\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0434\u0451\u043c \u0435\u0449\u0451 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0435\u0441\u044f \u043a\u00a0\u043e\u0434\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0445 \u0443\u0434\u0430\u043b\u044f\u0442\u044c. <\/p>\n<p><strong>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a:<\/strong><\/p>\n<p>1 \u0414\u043e\u0431\u0430\u0432\u0438\u043c 1\u00a0\u043c\u043b\u043d. \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432\u00a0\u0441\u043f\u0438\u0441\u043e\u043a:<\/p>\n<p><code>$ for i in {1..1000000}; do echo \"RPUSH list $i\"; done | redis-cli \u2013pipe<\/code><\/p>\n<p>2. \u0423\u0434\u0430\u043b\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 1\u00a0000\u00a0000. \u041e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0432\u00a0\u0441\u043f\u0438\u0441\u043a\u0435:<\/p>\n<p><code>127.0.0.1:6379&gt; time redis-cli LREM list 1 1000000 \/\/ 1 \u2013 \u0447\u0438\u0442\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e<\/code><\/p>\n<p><code>(integer) 1<\/code><\/p>\n<p><code>real0m0.060s<\/code><\/p>\n<p><strong>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043b\u044f\u00a0\u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e:<\/strong><\/p>\n<p>1. \u0414\u043e\u0431\u0430\u0432\u0438\u043c 1\u00a0\u043c\u043b\u043d \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432\u00a0\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e:<\/p>\n<p><code>$ for i in {1..1000000}; do \u00a0 \u00a0 echo \"SADD set $i\"; \u00a0 done | redis-cli --pipe;<\/code><\/p>\n<p>2. \u0423\u0434\u0430\u043b\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 1\u00a0000\u00a0000:<\/p>\n<p><code>127.0.0.1:6379&gt; time redis-cli SREM set 1000000<\/code><\/p>\n<p><code>(integer) 1<\/code><\/p>\n<p><code>real0m0.022s<\/code><\/p>\n<p>\u041d\u0430\u0448\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b: \u043f\u043e\u0438\u0441\u043a \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432\u00a0set \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0432 2\u00a0\u0440\u0430\u0437\u0430\u00a0\u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u0432\u00a0list. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p>\u2014 Set \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0445\u0435\u0448\u2011\u0442\u0430\u0431\u043b\u0438\u0446\u0443 (O(1) \u0434\u043b\u044f\u00a0\u043f\u043e\u0438\u0441\u043a\u0430\/\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f)<\/p>\n<p>\u2014 List \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u00a0\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 (O(N) \u0432\u00a0\u0445\u0443\u0434\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435)<\/p>\n<p>\u0412\u00a0\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0443\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e\u00a0List\u00a0\u2014 \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f: <\/p>\n<p>\u2014 \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0442\u0435\u043a\u043e\u0432 \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439;<\/p>\n<p>\u2014 \u041e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044f\u043c\u0438 \u0434\u043b\u044f\u00a0\u0444\u043e\u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>\u0410\u00a0\u0432\u043e\u0442 \u043f\u0440\u043e\u00a0Set \u044f\u0432\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f, \u0447\u0442\u043e\u00a0\u043e\u043d \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f\u00a0\u0443\u0447\u0451\u0442\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p><strong>\u0422\u0440\u0435\u0442\u044c\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u00a0\u2014<\/strong> <strong>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430<\/strong>.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u0430\u043c \u043d\u0430\u0434\u043e \u0434\u043b\u044f\u00a0\u043f\u0440\u043e\u0433\u0440\u0435\u0432\u0430 \u043a\u0435\u0448\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 SET. \u041a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043e\u043b\u0433\u0438\u0439 \u043f\u0443\u0442\u044c \u043a\u00a0\u0441\u0435\u0440\u0432\u0435\u0440\u0443 Redis \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0442\u0432\u0435\u0442.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0431\u0435\u0437\u00a0\u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430:<\/p>\n<p><code>$ redis-benchmark -c 1 -n 100000 -q -t SET,GET<\/code><\/p>\n<p><code>SET: 44444.45 requests per second, p50=0.023 msec\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><\/p>\n<p><code>GET: 39463.30 requests per second, p50=0.023 msec\u00a0\u00a0\u00a0\u00a0<\/code><\/p>\n<p>\u0412\u0438\u0434\u0438\u043c, \u0447\u0442\u043e\u00a0\u0441\u043c\u043e\u0433\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u00a0\u0441\u0440\u0435\u0434\u043d\u0435\u043c 40\u00a0\u0442\u044b\u0441. \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432\u00a0\u0441\u0435\u043a\u0443\u043d\u0434\u0443.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u043d\u0432\u0435\u0439e\u0440. \u0411\u0443\u0434\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u00a0\u043f\u043e\u00a0\u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0432\u00a0Redis, \u0430\u00a0\u0446\u0435\u043b\u044b\u0435 \u043f\u0430\u0447\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434. \u041f\u043e 10\u00a0\u0437\u0430\u00a0\u043e\u0434\u0438\u043d \u0440\u0430\u0437 (\u2011P 10): <\/p>\n<p><code>$ redis-benchmark -c 1 -n 100000 -q -t SET,GET -P 10<\/code><\/p>\n<p><code>SET: 595238.12 requests per second, p50=0.015 msec\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><\/p>\n<p><code>GET: 363636.34 requests per second, p50=0.023 msec\u00a0\u00a0<\/code><\/p>\n<p>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0437\u043a\u043e \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0432 10\u00a0\u0440\u0430\u0437!<\/p>\n<p>\u041c\u043e\u0436\u0435\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u00a0\u0440\u0430\u0437 \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u043c\u0430\u043d\u0434. \u0412\u043e\u0437\u044c\u043c\u0435\u043c 100\u00a0(\u2011P 100):<\/p>\n<p><code>redis-benchmark -c 1 -n 100000 -q -t SET,GET -P 100<\/code><\/p>\n<p><code>SET: 1785714.25 requests per second, p50=0.039 msec\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><\/p>\n<p><code>GET: 2500000.00 requests per second, p50=0.031 msec<\/code><\/p>\n<p>\u0420\u043e\u0441\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439, \u043d\u043e\u00a0\u0443\u0436\u0435 \u043d\u0435\u00a0\u043d\u0430\u00a0\u043f\u043e\u0440\u044f\u0434\u043e\u043a.<\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c 100\u00a0\u0442\u044b\u0441. \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<p>1. \u043f\u043e\u00a0\u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438\u00a0\u2014 \u043c\u0435\u0442\u043e\u0434 setCache<\/p>\n<p>2. \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0432\u0435\u0439e\u0440\u00a0\u2014 \u043c\u0435\u0442\u043e\u0434 setCacheWithPipeline<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><code>package main<\/code><\/p>\n<p><code>import (<\/code><\/p>\n<p><code>\"context\"<\/code><\/p>\n<p><code>\"fmt\"<\/code><\/p>\n<p><code>\"math\/rand\"<\/code><\/p>\n<p><code>\"time\"<\/code><\/p>\n<p><code>\"github.com\/redis\/go-redis\/v9\"<\/code><\/p>\n<p><code>)<\/code><\/p>\n<p><code>func main() {<\/code><\/p>\n<p><code>setCache(context.Background())<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>func setCache(ctx context.Context) {<\/code><\/p>\n<p><code>client := redis.NewClient(&amp;redis.Options{<\/code><\/p>\n<p><code>Addr: \"127.0.0.1:6379\",<\/code><\/p>\n<p><code>})<\/code><\/p>\n<p><code>key := <\/code><a href=\"http:\/\/rand.Int\" rel=\"noopener noreferrer nofollow\"><code>rand.Int<\/code><\/a><code>()<\/code><\/p>\n<p><code>for i := 0; i &lt; 100_000; i++ {<\/code><\/p>\n<p><code>_, err := client.Set(ctx, fmt.Sprintf(\"key:%d:%d\", key, i), <\/code><a href=\"http:\/\/time.Now\" rel=\"noopener noreferrer nofollow\"><code>time.Now<\/code><\/a><code>(), 0).Result()<\/code><\/p>\n<p><code>if err != nil {<\/code><\/p>\n<p><code>panic(\"Unable to set key: \" + err.Error())<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>func setCacheWithPipeline(ctx context.Context) {<\/code><\/p>\n<p><code>client := redis.NewClient(&amp;redis.Options{<\/code><\/p>\n<p><code>Addr: \"127.0.0.1:6379\",<\/code><\/p>\n<p><code>})<\/code><\/p>\n<p><code>key := <\/code><a href=\"http:\/\/rand.Int\" rel=\"noopener noreferrer nofollow\"><code>rand.Int<\/code><\/a><code>()<\/code><\/p>\n<p><code>pipeline := client.Pipeline()<\/code><\/p>\n<p><code>for i := 0; i &lt; 100_000; i++ {<\/code><\/p>\n<p><code>pipeline.Set(ctx, fmt.Sprintf(\"key:%d:%d\", key, i), <\/code><a href=\"http:\/\/time.Now\" rel=\"noopener noreferrer nofollow\"><code>time.Now<\/code><\/a><code>(), 0)<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>_, err := pipeline.Exec(ctx)<\/code><\/p>\n<p><code>if err != nil {<\/code><\/p>\n<p><code>panic(\"Unable to set key: \" + err.Error())<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>}<\/code><\/p>\n<\/div>\n<\/details>\n<p>\u0418 \u0442\u0435\u0441\u0442\u044b \u043d\u0430\u00a0\u044d\u0442\u0438 2\u00a0\u043c\u0435\u0442\u043e\u0434\u0430<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><code>package main<\/code><\/p>\n<p><code>import (<\/code><\/p>\n<p><code>\"context\"<\/code><\/p>\n<p><code>\"testing\"<\/code><\/p>\n<p><code>)<\/code><\/p>\n<p><code>func BenchmarkSetCache(b *testing.B) {<\/code><\/p>\n<p><code>for i := 0; i &lt; b.N; i++ {<\/code><\/p>\n<p><code>setCache(context.Background())<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>func BenchmarkSetCacheWithPipeline(b *testing.B) {<\/code><\/p>\n<p><code>for i := 0; i &lt; b.N; i++ {<\/code><\/p>\n<p><code>setCacheWithPipeline(context.Background())<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>}<\/code><\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0442\u0435\u0441\u0442\u044b:<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><code>$ go test -bench=. -benchmem -benchtime=10s<\/code><\/p>\n<p><code>...<\/code><\/p>\n<p><code>BenchmarkSetCache-22 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 4\u00a0 \u00a0 \u00a0 \u00a0 3056136444 ns\/op\u00a0 \u00a0 \u00a0 \u00a0 32849686 B\/op\u00a0 \u00a0 1199939 allocs\/op<\/code><\/p>\n<p><code>BenchmarkSetCacheWithPipeline-22\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 92 \u00a0 \u00a0 \u00a0 \u00a0 122466863 ns\/op\u00a0 \u00a0 \u00a0 \u00a0 37149145 B\/op \u00a0 \u00a0 799906 allocs\/op<\/code><\/p>\n<\/div>\n<\/details>\n<p>\u0421\u00a0\u043a\u043e\u043d\u0432\u0435\u0439e\u0440\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u0432 25\u00a0\u0440\u0430\u0437.<\/p>\n<p><strong>\u0427\u0435\u0442\u0432\u0451\u0440\u0442\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u00a0\u2014 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/strong><\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0\u043e\u0447\u0435\u0440\u0435\u0434\u044c\u044e (\u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430) \u0432\u00a0Redis:<\/p>\n<p>\u2014 \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u00a0\u043a\u043e\u043d\u0435\u0446 \u043e\u0447\u0435\u0440\u0435\u0434\u0438:<\/p>\n<p><code>127.0.0.1:6379&gt; rpush queue 1 2 3 4 5<\/code><\/p>\n<p><code>(integer) 5<\/code><\/p>\n<p>\u2014 \u0412\u0442\u043e\u0440\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0432\u00a0\u0446\u0438\u043a\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437\u00a0\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438:<\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>\"1\"<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>\"2\"<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>\"3\"<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>\"4\"<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>\"5\"<\/code><\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043a\u043e\u0433\u0434\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0443\u0441\u0442\u0430, \u043d\u043e\u00a0\u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0435\u0451:<\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>(nil)<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>(nil)<\/code><\/p>\n<p><code>127.0.0.1:6379&gt; lpop queue<\/code><\/p>\n<p><code>(nil)<\/code><\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a\u00a0\u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043d\u0430\u00a0Redis.<\/p>\n<p>\u042d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0436\u0434\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f\u00a0\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e.<\/p>\n<p>\u0414\u043b\u044f\u00a0\u043c\u043d\u043e\u0433\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u00a0\u043d\u0430\u0447\u0430\u043b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f &#171;b&#187;.<\/p>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0440:<\/em> \u0416\u0434\u0435\u043c 30\u00a0\u0441\u0435\u043a\u0443\u043d\u0434, \u043f\u043e\u043a\u0430 \u0432\u00a0\u0441\u043f\u0438\u0441\u043a\u0435 queue \u043d\u0435\u00a0\u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041a\u0430\u043a\u00a0\u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f, \u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f. <\/p>\n<p><code>127.0.0.1:6379&gt; blpop queue 30<\/code><\/p>\n<p>\u0418 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0435\u00a0\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0432\u0435\u0441\u044c Redis. \u0414\u0440\u0443\u0433\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<p>\u041d\u043e\u00a0\u0435\u0441\u0442\u044c \u043d\u044e\u0430\u043d\u0441. \u0411\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u0435\u0440\u0436\u0438\u0442 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\ufffd\ufffd \u0441\u00a0\u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c Redis. \u041d\u0430\u0434\u043e \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 (maxclients):<\/p>\n<p><code>$ redis-cli INFO clients<\/code><\/p>\n<p><code># Clients<\/code><\/p>\n<p><code>connected_clients:2<\/code><\/p>\n<p><code>cluster_connections:0<\/code><\/p>\n<p><code>maxclients:10000<\/code><\/p>\n<p><code>client_recent_max_input_buffer:20523<\/code><\/p>\n<p><code>client_recent_max_output_buffer:0<\/code><\/p>\n<p><code><strong>blocked_clients<\/strong>:1<\/code><\/p>\n<p><strong>\u041f\u044f\u0442\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u00a0\u2014 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440.<\/strong><\/p>\n<p>\u041c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0434\u044b \u0434\u043b\u044f\u00a0\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442:<\/p>\n<p>1. \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c \u0447\u0442\u0435\u043d\u0438\u044f (GET, LRANGE \u0438\u00a0\u0442.\u00a0\u0434.)<\/p>\n<p>\u2014 \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u043f\u043b\u0438\u043a (read replicas) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0447\u0442\u0435\u043d\u0438\u044f.<\/p>\n<p>2. \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c \u0437\u0430\u043f\u0438\u0441\u0438 (SET, LPUSH \u0438\u00a0\u0442.\u00a0\u0434.)<\/p>\n<p>\u2014 \u0428\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 (\u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u00a0\u0443\u0437\u043b\u0430\u043c) \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043e\u0431\u0449\u0443\u044e \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0443\u044e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c:<\/p>\n<p>\u2014 \u041c\u0430\u0441\u0442\u0435\u0440\u2011\u043d\u043e\u0434\u044b. \u0412\u00a0\u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u2014 \u0420\u0435\u043f\u043b\u0438\u043a\u0438. \u041a\u043e\u043f\u0438\u0440\u0443\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437\u00a0\u043c\u0430\u0441\u0442\u0435\u0440\u0430.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-474848","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/474848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=474848"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/474848\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}