资讯专栏INFORMATION COLUMN

win10 Redis的安装使用及配置

张利勇 / 974人阅读

摘要:原文地址下载安装版是上的一个开源项目我们可以直接下载解压使用。通过快捷方式启动服务修改的默认配置设置的最大占用内存设置最大占用内存,打开配置文件,找到如下段落,设置参数,是字节类型,注意转换。是近期最少使用算法。

原文地址

下载安装

Redis--Window版是GitHub上的一个开源项目我们可以直接下载解压使用。
Download Now

在D盘下新建Redis文件(这个路径可以自定义),将Redis解压至该文件

安装完后 打开 win控制台 cd 进入 Redis 目录
运行:redis-server.exe redis.windows.conf
如果出现以下信息则说明安装成功。

配置

配置之前先关掉Redis服务

添加启动Redis的快捷方式

为redis-server.exe创建快捷方式redis(名字 自定义)

修改redis的属性,为redis的目标属性,加入并指定读取的配置文件redis.windows.conf,前面要加空格。

通过快捷方式redis启动Redis服务

修改Redis的默认配置 设置Redis的最大占用内存

Redis设置最大占用内存,打开redis配置文件,找到如下段落,设置maxmemory参数,maxmemory是bytes字节类型,注意转换。修改如下所示:

# NOTE: since Redis uses the system paging file to allocate the heap memory,
# the Working Set memory usage showed by the Windows Task Manager or by other
# tools such as ProcessExplorer will not always be accurate. For example, right
# after a background save of the RDB or the AOF files, the working set value
# may drop significantly. In order to check the correct amount of memory used
# by the redis-server to store the data, use the INFO client command. The INFO
# command shows only the memory used to store the redis data, not the extra
# memory used by the Windows process for its own requirements. Th3 extra amount
# of memory not reported by the INFO command can be calculated subtracting the
# Peak Working Set reported by the Windows Task Manager and the used_memory_peak
# reported by the INFO command.
#
# maxmemory   根据自己需求配置
maxmemory 2147483648    

如果不设置maxmemory或者设置为0,64位系统不限制内存,32位系统最多使用3GB内存。

修改数据默认存放位置

这里自定义一个文件夹,用来存放Redis数据

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the "dbfilename" configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir D:MyRedisSwap
设置LRU算法删除数据

设置了maxmemory的选项,redis内存使用达到上限。可以通过设置LRU算法来删除部分key,释放空间。默认是按照过期时间的,如果set时候没有加上过期时间就会导致数据写满maxmemory。

LRU是Least Recently Used 近期最少使用算法。

volatile-lru -> 根据LRU算法生成的过期时间来删除。

-allkeys-lru -> 根据LRU算法删除任何key。

volatile-random -> 根据过期设置来随机删除key。

allkeys->random -> 无差别随机删。

volatile-ttl -> 根据最近过期时间来删除(辅以TTL)

noeviction -> 谁也不删,直接在写操作时返回错误。

如果设置了maxmemory,一般都要设置过期策略。Redis默认有六种过期策略

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key according to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don"t expire at all, just return an error on write operations
#
# Note: with any of the above policies, Redis will return an error on write
#       operations, when there are no suitable keys for eviction.
#
#       At the date of writing these commands are: set setnx setex append
#       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
#       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
#       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
#       getset mset msetnx exec sort
#
# The default is:
#
# maxmemory-policy noeviction
maxmemory-policy volatile-lru

以下是其他配置:

Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 (在Windows上不支持守护进程)

daemonize no 

指定Redis监听端口,默认端口为6379
(在Windows上不支持守护进程)

 port 6379

绑定的主机地址

bind 127.0.0.1

指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合

save  

Redis默认配置文件中提供了三个条件:

save 900 1
save 300 10
save 60 10000

分别表示900秒(15分钟)内有1个更改,300秒(5分钟)内有10个更改以及60秒内有10000个更改。

指定更新日志文件名,默认为appendonly.aof

appendfilename appendonly.aof

指定更新日志条件,共有3个可选值:

no:表示等操作系统进行数据缓存同步到磁盘(快) 
always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全) 
everysec:表示每秒同步一次(折衷,默认值)

appendfsync everysec

指定在超过一定的数量或者最大的元素超过某一临界值时,采用一种特殊的哈希算法

hash-max-zipmap-entries 64
hash-max-zipmap-value 512

参考链接:

Redis中文网

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/69248.html

相关文章

  • win10安装javaee开发环境(jdk+tomcat+mysql+redis+activemq

    摘要:第步配置环境变量在中使用即可,不用写第步输入进入中,输入检验是否安装成功。安装服务启动服务停止服务切换到目录下运行参考安装解压,配置环境变量,下开启和关闭窗口方式启动安装服务启动协助服务命令校验是否启动输入参考 1.安装jdk 第1步:在官网下载和自己电脑位数相同的安装包 第2步:选择安装路径,默认在C盘,建议自定义选择其他盘符,避免c盘重装系统后,需要重新安装。 第3步:安装过程中...

    alaege 评论0 收藏0
  • SimfaseDevEnv一个Vagrant构建开发环境

    摘要:整体与很像,但是做了一些更改,为了更适应中国国内的开发网络环境。表示宿主机器的目录,表示环境目录。将虚拟机置于休眠状态。在开发过程中可能会需要增加多个站点来运行不同的开发程序。与扩展名重名,建议将的改成为佳。 SimfaseDevEnv 介绍 SimfaseDevEnv是为php开发者提供的开发环境,构建在vagrant之上;Vagrant的Vagrangfile配置文件是在Homes...

    Noodles 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<