redis数据库在windows下的安装,配置与使用

来源:互联网 发布:淘宝代运营公司w863 编辑:程序博客网 时间:2024/05/17 02:16

redis数据库在windows下的安装,配置与使用

1. 背景。

因为分布式爬虫搭建的需要,会使用到Scrapy-redis实现分布式爬虫。
Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。

2. 环境。

  • 系统:win7

3. redis安装与配置。

3.1. 下载安装文件。

  • 资源路径: https://redis.io/download
  • Redis官方是不支持windows的,只是 Microsoft Open Tech group 在 GitHub上开发了一个Win64的版本。在上面的资源路径下,找到windows的相关入口:
    这里写图片描述

  • 寻找最近的稳定的release版本:
    这里写图片描述

  • 找到下面的两个文件:一个安装文件;一个压缩包。
    这里写图片描述

3.2. redis安装。

  • 两种文件分别对应两种安装方式:
    这里写图片描述

3.2.1. 第一种方式:解压压缩包。

  • 解压文件 Redis-x64-3.0.504.zip 到如下目录:
    这里写图片描述

  • 按如下方式,在cmd中启动redis-server
    这里写图片描述

  • 最后启动 redis-cli 测试redis是否安装成功。
    这里写图片描述

3.3. redis配置。

  • 所有的设置都是在文件 redis.windows.conf 中进行配置。
    这里写图片描述

3.3.1. 绑定IP地址。

# Master端redis.conf里注释bind 127.0.0.1,Slave端才能远程连接到Master端的Redis数据库。# By default Redis listens for connections from all the network interfaces# available on the server. It is possible to listen to just one or multiple# interfaces using the "bind" configuration directive, followed by one or# more IP addresses.## Examples:## bind 192.168.1.100 10.0.0.1# bind 127.0.0.1

3.3.2. 是否在运行时显示界面:

# daemonize yno表示Redis默认不作为守护进程运行,即在运行redis-server /etc/redis/redis.conf时,将显示Redis启动提示画面;# daemonize yes则默认后台运行,不必重新启动新的终端窗口执行其他命令,看个人喜好和实际需要。# 但是windows不支持这两个设置,看如下说明:# On Windows, daemonize and pidfile are not supported.# However, you can run redis as a Windows service, and specify a logfile.# The logfile will contain the pid. 

3.3.3. 设置验证密码:

# 设置完验证密码之后,需要重新启动redis-server################################## SECURITY #################################### Require clients to issue AUTH <PASSWORD> 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).# # Warning: since Redis is pretty fast an outside user can try up to# 150k passwords per second against a good box. This means that you should# use a very strong password otherwise it will be very easy to break.## requirepass foobaredrequirepass redisPasswordTest123456
  • 重新连接时,需要在 Auth 栏键入密码,如下所示:
    这里写图片描述

  • 更多 redis命令 ,可以看官方网站或中文站,传送门:http://www.redis.cn/commands.html

4. redis可视化工具:Redis Desktop Manager

4.1. 安装

  • Redis Desktop Manager 是一款可视化的Redis工具,是基于Qt5的跨平台Redis桌面管理软件,而且是开源的,托管在github上:https://github.com/uglide/RedisDesktopManager

    • 支持: Windows 7+, Mac OS X 10.10+, Ubuntu 14+
    • 特点: C++ 编写,响应迅速,性能好。但不支持数据库备份与恢复。
  • 找到release版本:
    这里写图片描述

  • 寻找最近的稳定的release版本:
    这里写图片描述

  • 安装,windows安装程序,非常简单。
    这里写图片描述

4.2. 使用。

  • 打开,进行连接。
    这里写图片描述
  • 可以看到,我之前添加的键值对,testkey: “100” 已经存在了。
    这里写图片描述

  • 两种方式操作redis数据库中的数据元素:

    • 第一种方式:使用控制台命令的方式操作redis数据库。
      这里写图片描述
      这里写图片描述
    • 第二种方式:通过UI操作。
      这里写图片描述

5. 分布式基础

这里写图片描述

  • Redis分布式策略:假设现在有2台电脑,都是win7,其中作为Master端的IP是172.16.7.107。作为Slaver端的IP是172.16.1.99

  • Master端(172.16.7.107):开启redis-server服务。
    这里写图片描述

  • Slaver端(172.16.1.99):使用Redis Desktop Manager或者redis-cli 进行连接。

    • Redis Desktop Manager连接
      这里写图片描述
      这里写图片描述
    • redis-cli连接
      这里写图片描述

6. 附录:


  • redis学习指南

https://www.cnblogs.com/hoojo/p/4466024.html