{"id":105237,"date":"2024-09-14T06:52:10","date_gmt":"2024-09-13T22:52:10","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=105237"},"modified":"2024-09-14T06:52:10","modified_gmt":"2024-09-13T22:52:10","slug":"redis-read-write","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/redis-read-write.html","title":{"rendered":"Redis\u6570\u636e\u5e93\u5982\u4f55\u5b9e\u73b0\u8bfb\u5199\u5206\u79bb"},"content":{"rendered":"
Redis\u662f\u4e00\u79cdNoSQL\u7684\u6587\u6863\u6570\u636e\u5e93\uff0c\u901a\u8fc7key-value\u7684\u7ed3\u6784\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0cRedis\u8bfb\u7684\u901f\u5ea6\u662f110000\u6b21\/s\uff0c\u5199\u7684\u901f\u5ea6\u662f81000\u6b21\/s\uff0c\u6027\u80fd\u5f88\u9ad8\uff0c\u4f7f\u7528\u8303\u56f4\u4e5f\u5f88\u5e7f\u3002<\/p>\n
\u4e0b\u9762\u7528\u4e00\u4e2a\u5b9e\u4f8b\u5b9e\u73b0redis\u7684\u8bfb\u5199\u5206\u79bb\uff0c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n
\u7b2c\u4e00\u6b65\uff1a\u4e0b\u8f7dredis<\/p>\n
\u5b98\u7f51\u4e0b\u8f7d\u5730\u5740\uff1a\u00a0https:\/\/redis.io\/download<\/p>\n
\u4e0b\u8f7d\u6700\u65b0\u7684\u7a33\u5b9a\u7248\uff0c\u89e3\u538b\u62f7\u8d1d\u5230 \uff5e\/redis \u4e2d<\/p>\n
<\/p>\n
\u7f16\u8bd1\u4ee3\u7801\uff1a<\/p>\n
$ make\r\n$ test<\/pre>\n\u7b2c\u4e8c\u6b65\uff1a\u914d\u7f6eredis<\/p>\n
\u7f16\u8f91redis.conf\u6587\u4ef6<\/p>\n
bind 127.0.0.1\r\nport 6379<\/pre>\n\u62f7\u8d1dredis.conf\u6587\u4ef6\uff0c\u6539\u540d\u4e3aslave.conf\uff0c\u6253\u5f00\u7f16\u8f91<\/p>\n
bind 127.0.0.1\r\nport 6380\r\nslaveof 127.0.0.1 6379<\/pre>\n\u7b2c\u4e09\u6b65\uff1a\u8fd0\u884c\u670d\u52a1<\/p>\n
\u5f00\u542f\u3010\u4e3b\u670d\u52a1\u3011<\/p>\n
$ src\/redis-server<\/pre>\n\u5f00\u542f\u3010\u4ece\u670d\u52a1\u3011<\/p>\n
$ src\/redis-server slave.conf<\/pre>\n\u8fd0\u884c\u3010\u4e3b\u670d\u52a1\u3011\u7684\u5ba2\u6237\u7aef<\/p>\n
$ src\/redis-cli<\/pre>\n\u8fd0\u884c\u3010\u4ece\u670d\u52a1\u3011\u7684\u5ba2\u6237\u7aef<\/p>\n
$ src\/redis-cli -h 127.0.0.1 -p 6380<\/pre>\n\u67e5\u770b\u4e3b\u4ece\u670d\u52a1\u7684\u5173\u7cfb<\/p>\n
$ src\/redis-cli info replication<\/pre>\n<\/p>\n
\u7b2c\u56db\u6b65\uff1a\u6d4b\u8bd5\u670d\u52a1\u5668<\/p>\n
\u4e0b\u9762\u5b9e\u4f8b\u6f14\u793a\uff1a\u5728\u4e3b\u670d\u52a1\u5668\u4e2d\u5b58\u50a8\u4e00\u4e9b\u6570\u636e\uff0c\u7136\u540e\u5728\u4ece\u670d\u52a1\u5668\u4e2d\u67e5\u8be2\u51fa\u6765<\/p>\n
<\/p>\n
<\/p>\n
\u53ef\u4ee5\u770b\u51fa\uff0c\u4ece\u670d\u52a1\u5668\u6210\u529f\u7684\u83b7\u53d6\u5230\u4e86\u4e3b\u670d\u52a1\u5668\u7684\u5907\u4efd\u6570\u636e\u3002<\/p>\n
\u5047\u5982\u6211\u4eec\u5728\u4ece\u670d\u52a1\u5668\u4e2d\u4fdd\u5b58\u6570\u636e\uff0c\u770b\u7ed3\u679c\u5982\u4f55\uff1f<\/p>\n
<\/p>\n
\u63d0\u793a\u9519\u8bef\uff1a<\/p>\n
(error) READONLY You can't write against a read only slave.<\/pre>\n\u8bf4\u660e\u4ece\u670d\u52a1\u5668\u53ea\u80fd\u8bfb\u6570\u636e\uff0c\u800c\u4e0d\u80fd\u5199\u5165\u6570\u636e\u3002<\/p>\n
\u6570\u636e\u5728\u3010\u4ece\u670d\u52a1\u5668\u3011\u91cc\u3010\u8bfb\u3011\uff0c\u5728\u3010\u4e3b\u670d\u52a1\u5668\u3011\u91cc\u3010\u5199\u3011\u3002<\/p>\n
\u8fd9\u6837\u5c31\u5b9e\u73b0\u4e86redis\u6570\u636e\u5e93\u7684\u8bfb\u5199\u5206\u79bb\u529f\u80fd\u3002<\/p>\n
\n\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.linuxsir.org\/linuxsjk\/14484.html<\/a><\/p>\n