1、Redis windows 测试redis持久化功能Redis windows 测试redis持久化功能还需要在redis根目录增加一个redis的配置文件redis.conf,文件具体内容有:1.# Redis configuration file example2. 3.# By default Redis does not run as a daemon. Use yes if you need it.4.# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.5.daemonize no
2、6. 7.# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.8.# You can specify a custom pid file location here.9.pidfile /var/run/redis.pid10. 11.# Accept connections on the specified port, default is 637912.port 637913. 14.# If you want you can bind a single interface, if
3、the bind option is not15.# specified all the interfaces will listen for connections.16.#17.# bind 127.0.0.118. 19.# Close the connection after a client is idle for N seconds (0 to disable)20.timeout 30021. 22.# Set server verbosity to debug23.# it can be one of:24.# debug (a lot of information, usef
4、ul for development/testing)25.# notice (moderately verbose, what you want in production probably)26.# warning (only very important / critical messages are logged)27.loglevel debug28. 29.# Specify the log file name. Also stdout can be used to force30.# the demon to log on the standard output. Note th
5、at if you use standard31.# output for logging but daemonize, logs will be sent to /dev/null32.logfile stdout33. 34.# Set the number of databases. The default database is DB 0, you can select35.# a different one on a per-connection basis using SELECT where36.# dbid is a number between 0 and databases
6、-137.databases 1638. 39.# SNAPSHOTTING #40.#41.# Save the DB on disk:42.#43.# save 44.#45.# Will save the DB if both the given number of seconds and the given46.# number of write operations against the DB occurred.47.#48.# In the example below the behaviour will be to save:49.# after 900 sec (15 min
7、) if at least 1 key changed50.# after 300 sec (5 min) if at least 10 keys changed51.# after 60 sec if at least 10000 keys changed52.save 900 153.save 300 1054.save 60 1000055. 56.# Compress string objects using LZF when dump .rdb databases?57.# For default thats set to yes as its almost always a win
8、.58.# If you want to save some CPU in the saving child set it to no but59.# the dataset will likely be bigger if you have compressible values or keys.60.rdbcompression yes61. 62.# The filename where to dump the DB63.dbfilename dump.rdb64. 65.# For default save/load DB in/from the working directory66
9、.# Note that you must specify a directory not a file name.67.dir ./68. 69.# REPLICATION #70. 71.# Master-Slave replication. Use slaveof to make a Redis instance a copy of72.# another Redis server. Note that the configuration is local to the slave73.# so for example it is possible to configure the sl
10、ave to save the DB with a74.# different interval, or to listen to another port, and so on.75.#76.# slaveof 77. 78.# If the master is password protected (using the requirepass configuration79.# directive below) it is possible to tell the slave to authenticate before80.# starting the replication synch
11、ronization process, otherwise the master will81.# refuse the slave request.82.#83.# masterauth 84. 85.# SECURITY #86. 87.# Require clients to issue AUTH before processing any other88.# commands. This might be useful in environments in which you do not trust89.# others with access to the host running
12、 redis-server.90.#91.# This should stay commented out for backward compatibility and because most92.# people do not need auth (e.g. they run their own servers).93.#94.# requirepass foobared95. 96.# LIMITS #97. 98.# Set the max number of connected clients at the same time. By default there99.# is no
13、limit, and its up to the number of file descriptors the Redis process100.# is able to open. The special value 0 means no limts.101.# Once the limit is reached Redis will close all the new connections sending102.# an error max number of clients reached.103.#104.# maxclients 128105. 106.# Dont use mor
14、e memory than the specified amount of bytes.107.# When the memory limit is reached Redis will try to remove keys with an108.# EXPIRE set. It will try to start freeing keys that are going to expire109.# in little time and preserve keys with a longer time to live.110.# Redis will also try to remove ob
15、jects from free lists if possible.111.#112.# If all this fails, Redis will start to reply with errors to commands113.# that will use more memory, like SET, LPUSH, and so on, and will continue114.# to reply to most read-only commands like GET.115.#116.# WARNING: maxmemory can be a good idea mainly if
16、 you want to use Redis as a117.# state server or cache, not as a real DB. When Redis is used as a real118.# database the memory usage will grow over the weeks, it will be obvious if119.# it is going to use too much memory in the long run, and youll have the time120.# to upgrade. With maxmemory after
17、 the limit is reached youll start to get121.# errors for write operations, and this may even lead to DB inconsistency.122.#123.# maxmemory 124. 125.# APPEND ONLY MODE #126. 127.# By default Redis asynchronously dumps the dataset on disk. If you can live128.# with the idea that the latest records wil
18、l be lost if something like a crash129.# happens this is the preferred way to run Redis. If instead you care a lot130.# about your data and dont want to that a single record can get lost you should131.# enable the append only mode: when this mode is enabled Redis will append132.# every write operati
19、on received in the file appendonly.log. This file will133.# be read on startup in order to rebuild the full dataset in memory.134.#135.# Note that you can have both the async dumps and the append only file if you136.# like (you have to comment the save statements above to disable the dumps).137.# St
20、ill if append only mode is enabled Redis will load the data from the138.# log file at startup ignoring the dump.rdb file.139.#140.# The name of the append only file is appendonly.log141.#142.# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append143.# log file in background when it ge
21、ts too big.144. 145.appendonly yes146. 147.# The fsync() call tells the Operating System to actually write data on disk148.# instead to wait for more data in the output buffer. Some OS will really flush149.# data on disk, some other OS will just try to do it ASAP.150.#151.# Redis supports three diff
22、erent modes:152.#153.# no: dont fsync, just let the OS flush the data when it wants. Faster.154.# always: fsync after every write to the append only log . Slow, Safest.155.# everysec: fsync only if one second passed since the last fsync. Compromise.156.#157.# The default is always thats the safer of
23、 the options. Its up to you to158.# understand if you can relax this to everysec that will fsync every second159.# or to no that will let the operating system flush the output buffer when160.# it want, for better performances (but if you can live with the idea of161.# some data loss consider the def
24、ault persistence mode thats snapshotting).162. 163.appendfsync always164.# appendfsync everysec165.# appendfsync no166. 167.# ADVANCED CONFIG #168. 169.# Glue small output buffers together in order to send small replies in a170.# single TCP packet. Uses a bit more CPU but most of the times it is a w
25、in171.# in terms of number of queries per second. Use yes if unsure.172.glueoutputbuf yes173. 174.# Use object sharing. Can save a lot of memory if you have many common175.# string in your dataset, but performs lookups against the shared objects176.# pool so it uses more CPU and can be a bit slower.
26、 Usually its a good177.# idea.178.#179.# When object sharing is enabled (shareobjects yes) you can use180.# shareobjectspoolsize to control the size of the pool used in order to try181.# object sharing. A bigger pool size will lead to better sharing capabilities.182.# In general you want this value
27、to be at least the double of the number of183.# very common strings you have in your dataset.184.#185.# WARNING: object sharing is experimental, dont enable this feature186.# in production before of Redis 1.0-stable. Still please try this feature in187.# your development environment so that we can t
28、est it better.188.# shareobjects no189.# shareobjectspoolsize 1024启动redis打开运行窗口F:cd redis-2.0.2F:redis-2.0.2redis-server.exe redis.conf2944 15 Jun 22:44:29 * Server started, Redis version 2.0.22944 15 Jun 22:44:29 * DB loaded from append only file: 0 seconds2944 15 Jun 22:44:29 * The server is now r
29、eady to accept connections on port3792944 15 Jun 22:44:30 - DB 0: 1 keys (0 volatile) in 4 slots HT.2944 15 Jun 22:44:30 - 0 clients connected (0 slaves), 450888 bytes in use在打开一个窗口运行客户端F:redis-2.0.2redis-cli.exeredis设置值:redis set ajun ajunReconnecting. OKOK取值:redis get ajunajun停止redis服务redis shutdo
30、wn如果需要redis持久化数据 需要配置redis日志开启在每次更新操作后进行日志记录,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认值为no此时要在redis.conf中修改或者添加appendonly yes更新日志文件名,默认值为appendonly.aof#更新日志条件,共有3个可选值。no表示等操作系统进行数据缓存同步到磁盘,always表示每次更新操作后手动调用fsync()将数据写到磁盘,everysec表示每秒同步一次(默认值)。# appendfsync alwaysappendfsync everysec
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1