Redis----windows下的常用命令
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Redis----windows下的常用命令
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                1:首先下載redis。
從下面地址下:https://github.com/MSOpenTech/redis/releases
2:創(chuàng)建redis.conf文件:
這是一個配置文件,指定了redis的監(jiān)聽端口,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硬盤需要配置虛擬內(nèi)存,如果還有問題,清理磁盤碎片 redis.windows.conf <span style="color: #ff0000;"><strong>maxheap 1024000000 daemonize no </strong></span> | 
更改redis的配置需要修改redis.conf文件,以下是它一些主要的配置注釋:
#是否作為守護進程運行 daemonize no #Redis 默認監(jiān)聽端口 port 6379 #客戶端閑置多少秒后,斷開連接 timeout 300 #日志顯示級別 loglevel verbose #指定日志輸出的文件名,也可指定到標準輸出端口 logfile redis.log #設(shè)置數(shù)據(jù)庫的數(shù)量,默認最大是16,默認連接的數(shù)據(jù)庫是0,可以通過select N 來連接不同的數(shù)據(jù)庫 databases 32 #Dump持久化策略 #當(dāng)有一條Keys 數(shù)據(jù)被改變是,900 秒刷新到disk 一次 #save 900 1 #當(dāng)有10 條Keys 數(shù)據(jù)被改變時,300 秒刷新到disk 一次 save 300 100 #當(dāng)有1w 條keys 數(shù)據(jù)被改變時,60 秒刷新到disk 一次 save 6000 10000 #當(dāng)dump .rdb 數(shù)據(jù)庫的時候是否壓縮數(shù)據(jù)對象 rdbcompression yes #dump 持久化數(shù)據(jù)保存的文件名 dbfilename dump.rdb ########### Replication ##################### #Redis的主從配置,配置slaveof則實例作為從服務(wù)器 #slaveof 192.168.0.105 6379 #主服務(wù)器連接密碼 # masterauth <master-password> ############## 安全性 ########### #設(shè)置連接密碼 #requirepass <password> ############### LIMITS ############## #最大客戶端連接數(shù) # maxclients 128 #最大內(nèi)存使用率 # 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主從復(fù)制
在從服務(wù)器配置文件中配置slaveof ,填寫服務(wù)器IP及端口即可,如果主服務(wù)器設(shè)置了連接密碼,在masterauth后指定密碼就行了。
持久化
- redis提供了兩種持久化文案,Dump持久化和AOF日志文件持久化。
- Dump持久化是把內(nèi)存中的數(shù)據(jù)完整寫入到數(shù)據(jù)文件,由配置策略觸發(fā)寫入,如果在數(shù)據(jù)更改后又未達到觸發(fā)條件而發(fā)生故障會造成部分數(shù)據(jù)丟失。
- AOF持久化是日志存儲的,是增量的形式,記錄每一個數(shù)據(jù)操作動作,數(shù)據(jù)恢復(fù)時就根據(jù)這些日志來生成。
?
3.命令行操作
使用CMD命令提示符,打開redis-cli連接redis服務(wù)器 ,也可以使用telnet客戶端
# redis-cli -h 服務(wù)器 –p 端口 –a 密碼
redis-cli.exe -h 127.0.0.1 -p 6379連接成功后,就可對redis數(shù)據(jù)增刪改查了,如字符串操作:
以下是一些服務(wù)器管理常用命令:
info #查看服務(wù)器信息 select <dbsize> #選擇數(shù)據(jù)庫索引 select 1 flushall #清空全部數(shù)據(jù) flushdb #清空當(dāng)前索引的數(shù)據(jù)庫 slaveof <服務(wù)器> <端口> #設(shè)置為從服務(wù)器 slaveof no one #設(shè)置為主服務(wù)器 shutdown #關(guān)閉服務(wù)?
附加幾個 bat 批處理腳本,請根據(jù)需要靈活配置
| 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? | 
總結(jié)
以上是生活随笔為你收集整理的Redis----windows下的常用命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: JPA Annotation注解
- 下一篇: 关于验证码的DEMO
