1:首先下載redis。
從下面地址下:https://github.com/MSOpenTech/redis/releases
2:創建redis.conf文件:
這是一個配置文件,指定了redis的監聽端口,timeout等。如下面有:port 6379。
配置:
遇到問題:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[18892] 05 Jan 16:02:28.584 #
The Windows version of Redis allocates a memory mapped heap
for
sharing with
the forked process used
for
persistence operations. In order to share
this
memory, Windows allocates
from
the system paging file a portion equal to the
size of the Redis heap. At
this
time there
is
insufficient contiguous free
space available
in
the system paging file
for
this
operation (Windows error
0x5AF). To work around
this
you may either increase the size of the system
paging file, or decrease the size of the Redis heap with the --maxheap flag.
Sometimes a reboot will defragment the system paging file sufficiently
for
this
operation to complete successfully.
Please see the documentation included with the binary distributions
for
more
details
on
the --maxheap flag.
Redis can not
continue
. Exiting.
|
處理方法:
1
2
3
4
5
|
windows硬盤需要配置虛擬內存,如果還有問題,清理磁盤碎片
redis.windows.conf
<span style=
"color: #ff0000;"
><strong>maxheap 1024000000
daemonize no
</strong></span>
|
更改redis的配置需要修改redis.conf文件,以下是它一些主要的配置注釋:
#是否作為守護進程運行
daemonize no
#Redis 默認監聽端口
port 6379
#客戶端閑置多少秒后,斷開連接
timeout 300
#日志顯示級別
loglevel verbose
#指定日志輸出的文件名,也可指定到標准輸出端口
logfile redis.log
#設置數據庫的數量,默認最大是16,默認連接的數據庫是0,可以通過select N 來連接不同的數據庫
databases 32
#Dump持久化策略
#當有一條Keys 數據被改變是,900 秒刷新到disk 一次
#save 900 1
#當有10 條Keys 數據被改變時,300 秒刷新到disk 一次
save 300 100
#當有1w 條keys 數據被改變時,60 秒刷新到disk 一次
save 6000 10000
#當dump .rdb 數據庫的時候是否壓縮數據對象
rdbcompression yes
#dump 持久化數據保存的文件名
dbfilename dump.rdb
########### Replication #####################
#Redis的主從配置,配置slaveof則實例作為從服務器
#slaveof 192.168.0.105 6379
#主服務器連接密碼
# masterauth <master-password>
############## 安全性 ########### #設置連接密碼 #requirepass <password> ############### LIMITS ############## #最大客戶端連接數 # maxclients 128 #最大內存使用率 # maxmemory <bytes> ########## APPEND ONLY MODE ######### #是否開啟日志功能 appendonly no # AOF持久化策略 #appendfsync always #appendfsync everysec #appendfsync no ################ VIRTUAL MEMORY ########### #是否開啟VM 功能 #vm-enabled no # vm-enabled yes #vm-swap-file logs/redis.swap #vm-max-memory 0 #vm-page-size 32 #vm-pages 134217728 #vm-max-threads 4
主從復制
在從服務器配置文件中配置slaveof ,填寫服務器IP及端口即可,如果主服務器設置了連接密碼,在masterauth后指定密碼就行了。
持久化
- redis提供了兩種持久化文案,Dump持久化和AOF日志文件持久化。
- Dump持久化是把內存中的數據完整寫入到數據文件,由配置策略觸發寫入,如果在數據更改后又未達到觸發條件而發生故障會造成部分數據丟失。
- AOF持久化是日志存儲的,是增量的形式,記錄每一個數據操作動作,數據恢復時就根據這些日志來生成。
3.命令行操作
使用CMD命令提示符,打開redis-cli連接redis服務器 ,也可以使用telnet客戶端
# redis-cli -h 服務器 –p 端口 –a 密碼
redis-cli.exe -h 127.0.0.1 -p 6379
連接成功后,就可對redis數據增刪改查了,如字符串操作:
以下是一些服務器管理常用命令:
info #查看服務器信息
select <dbsize> #選擇數據庫索引 select 1
flushall #清空全部數據
flushdb #清空當前索引的數據庫
slaveof <服務器> <端口> #設置為從服務器
slaveof no one #設置為主服務器
shutdown #關閉服務
附加幾個 bat 批處理腳本,請根據需要靈活配置
1
2
3
4
5
6
7
8
|
service-install.bat
redis-server.exe --service-install redis.windows.conf --loglevel verbose
uninstall-service.bat
redis-server --service-uninstall
startup.bat
redis-server.exe redis.windows.conf
|