{"id":201182,"date":"2025-05-10T09:22:20","date_gmt":"2025-05-10T01:22:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201182\/"},"modified":"2025-05-10T09:22:20","modified_gmt":"2025-05-10T01:22:20","slug":"windows%e4%b8%8bredis%e7%9a%84%e5%ae%89%e8%a3%85%e4%bd%bf%e7%94%a8%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201182\/","title":{"rendered":"Windows\u4e0bRedis\u7684\u5b89\u88c5\u4f7f\u7528\u6559\u7a0b"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Windows\u4e0bRedis\u7684\u5b89\u88c5\u4f7f\u7528\u6559\u7a0b<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300aWindows\u4e0bRedis\u7684\u5b89\u88c5\u4f7f\u7528\u6559\u7a0b\u300b\uff0c\u4e3b\u8981\u5305\u62ecWindowsRedis\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<p>\u672c\u6587\u4e3b\u8981\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u7f13\u5b58\u6280\u672f\u4e2d\u7684\u4e00\u79cdRedis\u7684\u5b89\u88c5\u548c\u4f7f\u7528\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\uff0c\u5177\u4f53\u5185\u5bb9\u5982\u4e0b<\/p>\n<p><strong>\u4e00\u3001\u4e0b\u8f7dRedis for windows<\/strong><\/p>\n<p style=\"text-align: left\">\u5728\u7f51\u7edc\u4e2d\u641c\u7d22Redis fow windows,\u5c31\u53ef\u4ee5\u4e0b\u8f7dRedis\u7684\u538b\u7f29\u5305\u3002\u89e3\u538b\u5305\u3002<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221231\/167244931063af8d1e9d95c.png\" class=\"aligncenter\"><\/p>\n<p>\u4f1a\u53d1\u73b0\u5176\u4e2d\u670932\u4f4d\u548c64\u4f4d\u7684\u4e0d\u540c\u7248\u672c\u7684\u5305\uff0c\u6839\u636e\u9700\u8981\uff0c\u4f7f\u7528\u5bf9\u5e94\u7684\u538b\u7f29\u5305\u5373\u53ef\u3002<\/p>\n<p><strong>\u4e8c\u3001\u89e3\u538b<\/strong><\/p>\n<p style=\"text-align: left\">\u6211\u4f7f\u7528\u7684\u662fredisbin_x64.zip\u7684\u538b\u7f29\u5305\uff0c\u5c06\u5176\u89e3\u538b\u5230redis\u7684\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221231\/167244931163af8d1f2d107.png\" class=\"aligncenter\"><\/p>\n<p>\u89e3\u538b\u4e4b\u540e\uff0c\u4f1a\u53d1\u73b0\u5185\u5bb9\u53ea\u6709\u4e00\u4e9b<strong>.exe<\/strong>\u7684\u6587\u4ef6\u3002\u5230\u8fd9\u91cc\uff0credis\u5c31\u7b97\u505a\u597d\u4e86\u4e00\u534a\u4e86\u3002<\/p>\n<p><strong>\u4e09\u3001\u914d\u7f6e<\/strong><\/p>\n<p>\u5728redis\u4e0b\u65b0\u5efa\u4e00\u4e2aconf\u7684\u6587\u4ef6\u5939\uff0c\u5e76\u521b\u5efa redis.conf \u6587\u672c\u6587\u4ef6\u3002\u5c06\u4e00\u4e0b\u5185\u5bb9\u590d\u5236\u5230\u914d\u7f6e\u6587\u4ef6\u4e2d\u3002<\/p>\n<pre>\n# Redis configuration file example \n \n# By default Redis does not run as a daemon. Use 'yes' if you need it. \n# Note that Redis will write a pid file in \/var\/run\/redis.pid when daemonized. \n# \u662f\u5426\u4ee5\u540e\u53f0\u8fdb\u7a0b\u7684\u5f62\u5f0f\u8fd0\u884c\uff0c\u9ed8\u8ba4\u4e3ano \ndaemonize no \n \n# When run as a daemon, Redis write a pid file in \/var\/run\/redis.pid by default. \n# You can specify a custom pid file location here. \n# \u5982\u679c\u6307\u5b9a\u4ee5\u540e\u53f0\u5f62\u5f0f\u6267\u884c\uff0c\u5219\u9700\u8981\u6307\u5b9a\u4e00\u4e2apid\u6587\u4ef6 \npidfile \/var\/run\/redis.pid \n \n# Accept connections on the specified port, default is 6379 \n#\u76d1\u542c\u7aef\u53e3\u53f7 \nport 6379 \n \n# If you want you can bind a single interface, if the bind option is not \n# specified all the interfaces will listen for connections. \n# \u7ed1\u5b9a\u4e3b\u673aIP \n# bind 127.0.0.1 \n \n# Close the connection after a client is idle for N seconds (0 to disable) \n# \u5ba2\u6237\u7aef\u7a7a\u95f2\u8d85\u65f6\u65f6\u95f4\uff0c\u8bbe\u7f6e\u4e3a0\uff0c\u5219\u6ca1\u6709\u8d85\u65f6\u3002\u8fc7\u4e86\u7a7a\u95f2\u65f6\u95f4\uff0c\u5219\u4f1a\u5c06\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u5173\u95ed \ntimeout 300 \n \n# Set server verbosity to 'debug' \n# it can be one of: \n# debug (a lot of information, useful for development\/testing) \n# notice (moderately verbose, what you want in production probably) \n# warning (only very important \/ critical messages are logged) \n# \u65e5\u5fd7\u8bb0\u5f55\u7b49\u7ea7 \nloglevel debug \n \n# Specify the log file name. Also 'stdout' can be used to force \n# the demon to log on the standard output. Note that if you use standard \n# output for logging but daemonize, logs will be sent to \/dev\/null \n# \u65e5\u5fd7\u8bb0\u5f55\u65b9\u5f0f \nlogfile stdout \n \n# Set the number of databases. The default database is DB 0, you can select \n# a different one on a per-connection basis using SELECT \n   \n     where \n# dbid is a number between 0 and 'databases'-1 \n# \u53ef\u7528\u6570\u636e\u5e93\u6570\u76ee \ndatabases 16 \n \n################################ SNAPSHOTTING ################################# \n# \n# Save the DB on disk: \n# \n# save \n    \n     \n       # # Will save the DB if both the given number of seconds and the given # number of write operations against the DB occurred. # # In the example below the behaviour will be to save: # after 900 sec (15 min) if at least 1 key changed # after 300 sec (5 min) if at least 10 keys changed # after 60 sec if at least 10000 keys changed save 900 1 save 300 10 save 60 10000 # Compress string objects using LZF when dump .rdb databases? # For default that's set to 'yes' as it's almost always a win. # If you want to save some CPU in the saving child set it to 'no' but # the dataset will likely be bigger if you have compressible values or keys. # \u5b58\u50a8\u5230\u672c\u5730\u6570\u636e\u5e93\u65f6\uff0c\u662f\u5426\u9700\u8981\u538b\u7f29\u6570\u636e rdbcompression yes # The filename where to dump the DB #\u672c\u5730\u6570\u636e\u540d\u79f0 dbfilename dump.rdb # For default save\/load DB in\/from the working directory # Note that you must specify a directory not a file name. # \u672c\u5730\u6570\u636e\u5e93\u5b58\u653e\u8def\u5f84 dir .\/ ################################# REPLICATION ################################# # Master-Slave replication. Use slaveof to make a Redis instance a copy of # another Redis server. Note that the configuration is local to the slave # so for example it is possible to configure the slave to save the DB with a # different interval, or to listen to another port, and so on. # \u5f53\u8be5\u670d\u52a1\u4e3a\u4ece\u670d\u52a1\u65f6\uff0c\u8bbe\u7f6e\u4e3b\u670d\u52a1\u7684ip\u5730\u5740\u548c\u7aef\u53e3\u53f7 # # slaveof \n      \n       \n         # If the master is password protected (using the \"requirepass\" configuration # directive below) it is possible to tell the slave to authenticate before # starting the replication synchronization process, otherwise the master will # refuse the slave request. # \u5f53\u8be5\u670d\u52a1\u4e3a\u4ece\u670d\u52a1\u65f6\uff0c\u8bbe\u7f6e\u4e3b\u670d\u52a1\u7684\u8fde\u63a5\u5bc6\u7801 # # masterauth \n        \n          ################################## SECURITY ################################### # Require clients to issue AUTH \n         \n           before processing any other # commands. This might be useful in environments in which you do not trust # others with access to the host running redis-server. # # This should stay commented out for backward compatibility and because most # people do not need auth (e.g. they run their own servers). # \u8fde\u63a5\u5bc6\u7801 # # requirepass foobared ################################### LIMITS #################################### # Set the max number of connected clients at the same time. By default there # is no limit, and it's up to the number of file descriptors the Redis process # is able to open. The special value '0' means no limts. # Once the limit is reached Redis will close all the new connections sending # an error 'max number of clients reached'. # \u6700\u5927\u5ba2\u6237\u7aef\u8fde\u63a5\u6570\uff0c\u9ed8\u8ba4\u4e0d\u8bbe\u7f6e # # maxclients 128 # Don't use more memory than the specified amount of bytes. # When the memory limit is reached Redis will try to remove keys with an # EXPIRE set. It will try to start freeing keys that are going to expire # in little time and preserve keys with a longer time to live. # Redis will also try to remove objects from free lists if possible. # # If all this fails, Redis will start to reply with errors to commands # that will use more memory, like SET, LPUSH, and so on, and will continue # to reply to most read-only commands like GET. # # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a # 'state' server or cache, not as a real DB. When Redis is used as a real # database the memory usage will grow over the weeks, it will be obvious if # it is going to use too much memory in the long run, and you'll have the time # to upgrade. With maxmemory after the limit is reached you'll start to get # errors for write operations, and this may even lead to DB inconsistency. # \u8bbe\u7f6e\u6700\u5927\u5185\u5b58\uff0c\u8fbe\u5230\u6700\u5927\u5185\u5b58\u8bbe\u7f6e\u540e\uff0cRedis\u7ebf\u5c1d\u8bd5\u6e05\u695a\u5df2\u5230\u671f\u6216\u5373\u5c06\u5230\u671f\u7684key,\u5f53\u6b64\u65b9\u6cd5\u5904\u7406\u540e\uff0c\u8fbe\u5230\u6700\u5927\u5185\u5b58\u8bbe\u7f6e\uff0c\u5c06\u4e0d\u80fd\u5728\u8fdb\u884c\u5199\u5165\u64cd\u4f5c\u3002 # # maxmemory \n          \n            ############################## APPEND ONLY MODE ############################### # By default Redis asynchronously dumps the dataset on disk. If you can live # with the idea that the latest records will be lost if something like a crash # happens this is the preferred way to run Redis. If instead you care a lot # about your data and don't want to that a single record can get lost you should # enable the append only mode: when this mode is enabled Redis will append # every write operation received in the file appendonly.log. This file will # be read on startup in order to rebuild the full dataset in memory. # # Note that you can have both the async dumps and the append only file if you # like (you have to comment the \"save\" statements above to disable the dumps). # Still if append only mode is enabled Redis will load the data from the # log file at startup ignoring the dump.rdb file. # # The name of the append only file is \"appendonly.log\" # # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append # log file in background when it gets too big. # \u8bbe\u7f6eRedis\u670d\u52a1\u5668\u5728\u6bcf\u6b21\u64cd\u4f5c\u5b8c\u6210\u540e\uff0c\u662f\u5426\u66f4\u65b0\u65e5\u5fd7\u64cd\u4f5c\uff0c\u5982\u679c\u5173\u95ed\uff0c\u53ef\u80fd\u4f1a\u5728\u65ad\u7535\u65f6\u5bfc\u81f4\u4e00\u6bb5\u65f6\u95f4\u5185\u7684\u6570\u636e\u4e22\u5931\uff0c # \u56e0\u4e3aRedis\u672c\u8eab\u540c\u6b65\u6570\u636e\u6587\u4ef6\u662f\u6309\u7167\u4e0a\u9762\u7684save\u6761\u4ef6\u6765\u540c\u6b65\u7684\uff0c\u6240\u4ee5\u6709\u7684\u6570\u636e\u4f1a\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u5b58\u50a8\u4e8e\u5185\u5b58\u4e2d\u3002 appendonly no # \u66f4\u65b0\u65e5\u5fd7\u6587\u4ef6\u540d # appendfilename appendonly.aof # The fsync() call tells the Operating System to actually write data on disk # instead to wait for more data in the output buffer. Some OS will really flush # data on disk, some other OS will just try to do it ASAP. # # Redis supports three different modes: # # no: don't fsync, just let the OS flush the data when it wants. Faster. # always: fsync after every write to the append only log . Slow, Safest. # everysec: fsync only if one second passed since the last fsync. Compromise. # # The default is \"always\" that's the safer of the options. It's up to you to # understand if you can relax this to \"everysec\" that will fsync every second # or to \"no\" that will let the operating system flush the output buffer when # it want, for better performances (but if you can live with the idea of # some data loss consider the default persistence mode that's snapshotting). # \u66f4\u65b0\u65e5\u5fd7\u6761\u4ef6,\u6709\u4e09\u4e2a\u53ef\u9009\u503c: appendfsync always # appendfsync everysec # appendfsync no ############################### ADVANCED CONFIG ############################### # Glue small output buffers together in order to send small replies in a # single TCP packet. Uses a bit more CPU but most of the times it is a win # in terms of number of queries per second. Use 'yes' if unsure. #glueoutputbuf yes # Use object sharing. Can save a lot of memory if you have many common # string in your dataset, but performs lookups against the shared objects # pool so it uses more CPU and can be a bit slower. Usually it's a good # idea. # # When object sharing is enabled (shareobjects yes) you can use # shareobjectspoolsize to control the size of the pool used in order to try # object sharing. A bigger pool size will lead to better sharing capabilities. # In general you want this value to be at least the double of the number of # very common strings you have in your dataset. # # WARNING: object sharing is experimental, don't enable this feature # in production before of Redis 1.0-stable. Still please try this feature in # your development environment so that we can test it better. # shareobjects no # shareobjectspoolsize 1024 # \u662f\u5426\u4f7f\u7528\u865a\u62df\u5185\u5b58 #vm-enabled no; # \u865a\u62df\u5185\u5b58\u6587\u4ef6\u8def\u5f84,\u4e0d\u80fd\u591a\u4e2aredis\u5171\u4eab # vm-swap-file \/tmp\/redis.swap # \u5c06\u6240\u6709\u5927\u4e8evm-max-memory \u7684\u6570\u636e\u5b58\u5165\u865a\u62df\u5185\u5b58\u3002\u65e0\u8bbavm-max-memory\u503c\u5927\u5c0f\uff0c\u6240\u6709\u7684\u7d22\u5f15\u6570\u636e\u90fd\u662f\u5185\u5b58\u6570\u636e\u3002 # \u5982\u679c\u5c06vm-max-memory\u8bbe\u7f6e\u4e3a0\uff0c\u5219\u6240\u6709\u7684\u6570\u636e\u90fd\u5b58\u653e\u5728\u78c1\u76d8\u3002 # vm-max-memory 0 \n          \n         \n        \n       \n      \n     \n    \n   <\/pre>\n<p><strong>\u56db\u3001\u542f\u52a8redis\u670d\u52a1\u5668<\/strong><\/p>\n<p>\u4f7f\u7528\u4e00\u4e0b\u547d\u4ee4\u542f\u52a8 redis\u670d\u52a1\u5668\u3002<\/p>\n<p><span style=\"color: #800000\">redis-server.exe conf\/redis.conf<\/span><\/p>\n<p>\u542f\u52a8\u6210\u529f\u4e4b\u540e\uff0c\u4f60\u4f1a\u770b\u5230\u5982\u4e0b\u7684\u63d0\u793a:<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221231\/167244931263af8d2005da3.png\" class=\"aligncenter\"><\/p>\n<p><strong>\u4e94\u3001\u8fde\u63a5redis\u670d\u52a1\u5668<\/strong><\/p>\n<p>\u4f7f\u7528redis\u81ea\u5e26\u7684\u547d\u4ee4\uff0c\u80fd\u591f\u8fde\u63a5\u670d\u52a1\u5668\u3002<\/p>\n<p><span style=\"color: #800000\">redis-cli.exe -h localhost -p 6379<\/span><\/p>\n<p>\u8fde\u63a5\u6210\u529f\u4e4b\u540e\uff0c\u4f1a\u63d0\u793a\u4ee5\u4e0b\u5185\u5bb9:<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221231\/167244931263af8d2062240.png\" class=\"aligncenter\"><\/p>\n<p style=\"text-align: left\">\u8fd9\u4e2a\u65f6\u5019\uff0c\u4f60\u5c31\u80fd\u591f\u4f7f\u7528redis\u7684\u4e00\u4e0b\u6307\u4ee4\u64cd\u4f5c\u6570\u636e\u3002\u5176\u4ed6\u6307\u4ee4\uff0c\u8bf7\u5728\u7f51\u4e0a\u5177\u4f53\u67e5\u770b\u4e00\u4e0b\u3002<\/p>\n<p style=\"text-align: left\">\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Windows\u4e0bRedis\u7684\u5b89\u88c5&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201182","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201182"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201182\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}