服务器之家:专注于服务器技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - Redis - Windows下Redis的安装使用教程

Windows下Redis的安装使用教程

2019-10-29 19:42CSDN Redis

这篇文章主要以图文结合的方式为大家详细介绍了Windows下Redis的安装使用,Redis的出现,很大程度补偿了memcached这类key/value存储的不足,在部分场合可以对关系数据库起到很好的补充作用,对Redis感兴趣的小伙伴们可以参考一下

本文主要为大家介绍缓存技术中的一种Redis的安装和使用,供大家参考,具体内容如下

一、下载Redis for windows

在网络中搜索Redis fow windows,就可以下载Redis的压缩包。解压包。

Windows下Redis的安装使用教程

会发现其中有32位和64位的不同版本的包,根据需要,使用对应的压缩包即可。

二、解压

我使用的是redisbin_x64.zip的压缩包,将其解压到redis的文件夹中。

Windows下Redis的安装使用教程

解压之后,会发现内容只有一些.exe的文件。到这里,redis就算做好了一半了。

三、配置

在redis下新建一个conf的文件夹,并创建 redis.conf 文本文件。将一下内容复制到配置文件中。

  1. # Redis configuration file example  
  2.    
  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. # 是否以后台进程的形式运行,默认为no  
  6. daemonize no  
  7.    
  8. # When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.  
  9. # You can specify a custom pid file location here.  
  10. # 如果指定以后台形式执行,则需要指定一个pid文件  
  11. pidfile /var/run/redis.pid  
  12.    
  13. # Accept connections on the specified port, default is 6379  
  14. #监听端口号  
  15. port 6379  
  16.    
  17. # If you want you can bind a single interface, if the bind option is not  
  18. # specified all the interfaces will listen for connections.  
  19. # 绑定主机IP  
  20. # bind 127.0.0.1  
  21.    
  22. # Close the connection after a client is idle for N seconds (0 to disable)  
  23. # 客户端空闲超时时间,设置为0,则没有超时。过了空闲时间,则会将客户端的连接关闭  
  24. timeout 300  
  25.    
  26. # Set server verbosity to 'debug'  
  27. # it can be one of:  
  28. # debug (a lot of information, useful for development/testing)  
  29. # notice (moderately verbose, what you want in production probably)  
  30. # warning (only very important / critical messages are logged)  
  31. # 日志记录等级  
  32. loglevel debug  
  33.    
  34. # Specify the log file name. Also 'stdout' can be used to force  
  35. # the demon to log on the standard output. Note that if you use standard  
  36. # output for logging but daemonize, logs will be sent to /dev/null  
  37. # 日志记录方式  
  38. logfile stdout  
  39.    
  40. # Set the number of databases. The default database is DB 0, you can select  
  41. # a different one on a per-connection basis using SELECT <dbid> where  
  42. # dbid is a number between 0 and 'databases'-1  
  43. # 可用数据库数目  
  44. databases 16  
  45.    
  46. ################################ SNAPSHOTTING #################################  
  47.  
  48. # Save the DB on disk:  
  49.  
  50. # save <seconds> <changes>  
  51.  
  52. # Will save the DB if both the given number of seconds and the given  
  53. # number of write operations against the DB occurred.  
  54.  
  55. # In the example below the behaviour will be to save:  
  56. # after 900 sec (15 min) if at least 1 key changed  
  57. # after 300 sec (5 min) if at least 10 keys changed  
  58. # after 60 sec if at least 10000 keys changed  
  59. save 900 1  
  60. save 300 10  
  61. save 60 10000  
  62.    
  63. # Compress string objects using LZF when dump .rdb databases?  
  64. # For default that's set to 'yes' as it's almost always a win.  
  65. # If you want to save some CPU in the saving child set it to 'no' but  
  66. # the dataset will likely be bigger if you have compressible values or keys.  
  67. # 存储到本地数据库时,是否需要压缩数据  
  68. rdbcompression yes  
  69.    
  70. # The filename where to dump the DB  
  71. #本地数据名称  
  72. dbfilename dump.rdb  
  73.    
  74. # For default save/load DB in/from the working directory  
  75. # Note that you must specify a directory not a file name.  
  76. # 本地数据库存放路径  
  77. dir ./  
  78.    
  79. ################################# REPLICATION #################################  
  80.    
  81. # Master-Slave replication. Use slaveof to make a Redis instance a copy of  
  82. # another Redis server. Note that the configuration is local to the slave  
  83. # so for example it is possible to configure the slave to save the DB with a  
  84. # different interval, or to listen to another port, and so on.  
  85. # 当该服务为从服务时,设置主服务的ip地址和端口号  
  86.  
  87. # slaveof <masterip> <masterport>  
  88.    
  89. # If the master is password protected (using the "requirepass" configuration  
  90. # directive below) it is possible to tell the slave to authenticate before  
  91. # starting the replication synchronization process, otherwise the master will  
  92. # refuse the slave request.  
  93. # 当该服务为从服务时,设置主服务的连接密码  
  94.  
  95. # masterauth <master-password>  
  96.    
  97. ################################## SECURITY ###################################  
  98.    
  99. # Require clients to issue AUTH <PASSWORD> before processing any other  
  100. # commands. This might be useful in environments in which you do not trust  
  101. # others with access to the host running redis-server.  
  102.  
  103. # This should stay commented out for backward compatibility and because most  
  104. # people do not need auth (e.g. they run their own servers).  
  105. # 连接密码  
  106.  
  107. # requirepass foobared  
  108.    
  109. ################################### LIMITS ####################################  
  110.    
  111. # Set the max number of connected clients at the same time. By default there  
  112. # is no limit, and it's up to the number of file descriptors the Redis process  
  113. # is able to open. The special value '0' means no limts.  
  114. # Once the limit is reached Redis will close all the new connections sending  
  115. # an error 'max number of clients reached'.  
  116. # 最大客户端连接数,默认不设置  
  117.  
  118. # maxclients 128  
  119.    
  120. # Don't use more memory than the specified amount of bytes.  
  121. # When the memory limit is reached Redis will try to remove keys with an  
  122. # EXPIRE set. It will try to start freeing keys that are going to expire  
  123. # in little time and preserve keys with a longer time to live.  
  124. # Redis will also try to remove objects from free lists if possible.  
  125.  
  126. # If all this fails, Redis will start to reply with errors to commands  
  127. # that will use more memory, like SET, LPUSH, and so on, and will continue  
  128. # to reply to most read-only commands like GET.  
  129.  
  130. # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a  
  131. # 'state' server or cache, not as a real DB. When Redis is used as a real  
  132. # database the memory usage will grow over the weeks, it will be obvious if  
  133. # it is going to use too much memory in the long run, and you'll have the time  
  134. # to upgrade. With maxmemory after the limit is reached you'll start to get  
  135. # errors for write operations, and this may even lead to DB inconsistency.  
  136. # 设置最大内存,达到最大内存设置后,Redis线尝试清楚已到期或即将到期的key,当此方法处理后,达到最大内存设置,将不能在进行写入操作。  
  137.  
  138. # maxmemory <bytes>  
  139.    
  140. ############################## APPEND ONLY MODE ###############################  
  141.    
  142. # By default Redis asynchronously dumps the dataset on disk. If you can live  
  143. # with the idea that the latest records will be lost if something like a crash  
  144. # happens this is the preferred way to run Redis. If instead you care a lot  
  145. # about your data and don't want to that a single record can get lost you should  
  146. # enable the append only mode: when this mode is enabled Redis will append  
  147. # every write operation received in the file appendonly.log. This file will  
  148. # be read on startup in order to rebuild the full dataset in memory.  
  149.  
  150. # Note that you can have both the async dumps and the append only file if you  
  151. # like (you have to comment the "save" statements above to disable the dumps).  
  152. # Still if append only mode is enabled Redis will load the data from the  
  153. # log file at startup ignoring the dump.rdb file.  
  154.  
  155. # The name of the append only file is "appendonly.log"  
  156.  
  157. # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append  
  158. # log file in background when it gets too big.  
  159. # 设置Redis服务器在每次操作完成后,是否更新日志操作,如果关闭,可能会在断电时导致一段时间内的数据丢失,  
  160. # 因为Redis本身同步数据文件是按照上面的save条件来同步的,所以有的数据会在一段时间内存储于内存中。  
  161.    
  162. appendonly no  
  163.    
  164. # 更新日志文件名  
  165. # appendfilename appendonly.aof  
  166.    
  167. # The fsync() call tells the Operating System to actually write data on disk  
  168. # instead to wait for more data in the output buffer. Some OS will really flush  
  169. # data on disk, some other OS will just try to do it ASAP.  
  170.  
  171. # Redis supports three different modes:  
  172.  
  173. # no: don't fsync, just let the OS flush the data when it wants. Faster.  
  174. # always: fsync after every write to the append only log . Slow, Safest.  
  175. # everysec: fsync only if one second passed since the last fsync. Compromise.  
  176.  
  177. # The default is "always" that's the safer of the options. It's up to you to  
  178. # understand if you can relax this to "everysec" that will fsync every second  
  179. # or to "no" that will let the operating system flush the output buffer when  
  180. # it want, for better performances (but if you can live with the idea of  
  181. # some data loss consider the default persistence mode that's snapshotting).  
  182. # 更新日志条件,有三个可选值:  
  183.    
  184. appendfsync always  
  185. # appendfsync everysec  
  186. # appendfsync no  
  187.    
  188. ############################### ADVANCED CONFIG ###############################  
  189.    
  190. # Glue small output buffers together in order to send small replies in a  
  191. # single TCP packet. Uses a bit more CPU but most of the times it is a win  
  192. # in terms of number of queries per second. Use 'yes' if unsure.  
  193. #glueoutputbuf yes  
  194.    
  195. # Use object sharing. Can save a lot of memory if you have many common  
  196. # string in your dataset, but performs lookups against the shared objects  
  197. # pool so it uses more CPU and can be a bit slower. Usually it's a good  
  198. # idea.  
  199.  
  200. # When object sharing is enabled (shareobjects yes) you can use  
  201. # shareobjectspoolsize to control the size of the pool used in order to try  
  202. # object sharing. A bigger pool size will lead to better sharing capabilities.  
  203. # In general you want this value to be at least the double of the number of  
  204. # very common strings you have in your dataset.  
  205.  
  206. # WARNING: object sharing is experimental, don't enable this feature  
  207. # in production before of Redis 1.0-stable. Still please try this feature in  
  208. # your development environment so that we can test it better.  
  209.    
  210. # shareobjects no  
  211. # shareobjectspoolsize 1024  
  212.    
  213. # 是否使用虚拟内存  
  214. #vm-enabled no;  
  215.    
  216. # 虚拟内存文件路径,不能多个redis共享  
  217. # vm-swap-file /tmp/redis.swap  
  218.    
  219. # 将所有大于vm-max-memory 的数据存入虚拟内存。无论vm-max-memory值大小,所有的索引数据都是内存数据。  
  220. # 如果将vm-max-memory设置为0,则所有的数据都存放在磁盘。  
  221. # vm-max-memory 0  

四、启动redis服务器

使用一下命令启动 redis服务器。

redis-server.exe conf/redis.conf

启动成功之后,你会看到如下的提示:

Windows下Redis的安装使用教程

五、连接redis服务器

使用redis自带的命令,能够连接服务器。

redis-cli.exe -h localhost -p 6379

连接成功之后,会提示以下内容:

Windows下Redis的安装使用教程

这个时候,你就能够使用redis的一下指令操作数据。其他指令,请在网上具体查看一下。

以上就是本文的全部内容,希望对大家的学习有所帮助。

延伸 · 阅读

精彩推荐
  • Redis聊一聊Redis与MySQL双写一致性如何保证

    聊一聊Redis与MySQL双写一致性如何保证

    一致性就是数据保持一致,在分布式系统中,可以理解为多个节点中数据的值是一致的。本文给大家分享Redis与MySQL双写一致性该如何保证,感兴趣的朋友一...

    mind_programmonkey6432021-08-12
  • Redisredis启动,停止,及端口占用处理方法

    redis启动,停止,及端口占用处理方法

    今天小编就为大家分享一篇redis启动,停止,及端口占用处理方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧 ...

    澄海单挑狂5152019-11-14
  • RedisRedis存取序列化与反序列化性能问题详解

    Redis存取序列化与反序列化性能问题详解

    这篇文章主要给大家介绍了关于Redis存取序列化与反序列化性能问题的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参...

    这名字已经存在9742021-02-24
  • Redis在ssm项目中使用redis缓存查询数据的方法

    在ssm项目中使用redis缓存查询数据的方法

    本文主要简单的使用Java代码进行redis缓存,即在查询的时候先在service层从redis缓存中获取数据。如果大家对在ssm项目中使用redis缓存查询数据的相关知识感...

    caychen8962019-11-12
  • Redis就这?Redis持久化策略——AOF

    就这?Redis持久化策略——AOF

    今天为大家介绍Redis的另一种持久化策略——AOF。注意:AOF文件只会记录Redis的写操作命令,因为读命令对数据的恢复没有任何意义...

    头发茂密的刘叔4052021-12-14
  • RedisLinux Redis 的安装步骤详解

    Linux Redis 的安装步骤详解

    这篇文章主要介绍了 Linux Redis 的安装步骤详解的相关资料,希望大家通过本文能掌握如何安装Redis,需要的朋友可以参考下 ...

    carl-zhao3822019-11-08
  • RedisRedis数据结构之链表与字典的使用

    Redis数据结构之链表与字典的使用

    这篇文章主要介绍了Redis数据结构之链表与字典的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友...

    白泽来了4052021-08-03
  • RedisRedis分布式锁升级版RedLock及SpringBoot实现方法

    Redis分布式锁升级版RedLock及SpringBoot实现方法

    这篇文章主要介绍了Redis分布式锁升级版RedLock及SpringBoot实现,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以...

    等不到的口琴7802021-07-25