Windows下使用Redis(一)安裝使用

1、Redis 是什麼
node

  Redis 是一款依據BSD開源協議發行的高性能Key-Value存儲系統(cache and store)。它一般被稱爲數據結構服務器,由於值(value)能夠是 字符串(String), 哈希(Map), 列表(list), 集合(sets) , 有序集合(sorted sets)和位圖(bitmaps)等類型。官方網站是 http://redis.io/redis

  Redis 和其它 NO SQL 的比較本文不作過多闡述。我以爲 Redis 最好的地方就是提供數據持久化功能(定時把內存中的數據寫入文件),從而不至於一旦宕機將形成數據丟失。並且相較於 Memcached ,它提供的值類型選擇更爲寬泛。windows

 

2、Redis 下載安裝  
服務器

  打開 Redis 官網,咱們發現 Redis 官方並不支持 Windows 平臺,但 Microsoft Open Tech Group 卻改變了這一狀況數據結構

  點擊 Learn moreapp

  點擊 Download ZIP, 下載完後解壓,咱們發現其並無提供現成的執行安裝文件,這就須要咱們自行進行編譯。定位到目錄 Redis\redis2.8\msvs,打開文件 RedisServer.slnless

 

  項目結構以下圖tcp

  因爲筆者的機器爲64位,在編譯以前咱們確認一下編譯 Platform, 同時咱們能夠看到對於此 project 將會編譯產生 redis-server.exe 文件ide

   其它項目相似工具

   編譯成功以後,咱們到其 Debug 目錄下找到編譯產生的文件

  爲了便於處理,咱們新建目錄 Redis,並把這些文件拷貝過去

  其中的 redis.conf 來自以下目錄

  至此,咱們已經獲得全部須要的文件了,下面就可使用了,打開 CMD, 定位到目錄 D:\Developer\Redis\Redis,而後執行以下命令

redis-server.exe redis.conf

  執行成功的截圖(能夠看到端口爲6379, 進程標識符 PID 爲7696)

  執行過程當中還會讀取配置,因爲截圖太長,故這裏放出文字

複製代碼
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>cd D:\Developer\Redis\Redis

C:\Windows\system32>D:

D:\Developer\Redis\Redis>redis-server.exe redis.conf
processing redis.conf
arguments seen:
activerehashing
        yes
aof-load-truncated
        yes
aof-rewrite-incremental-fsync
        yes
appendfilename
        appendonly.aof
appendfsync
        everysec
appendonly
        no
auto-aof-rewrite-min-size
        64mb
auto-aof-rewrite-percentage
        100
client-output-buffer-limit
        normal, 0, 0, 0
        slave, 256mb, 64mb, 60
        pubsub, 32mb, 8mb, 60
daemonize
        no
databases
        16
dbfilename
        dump.rdb
dir
        ./
hash-max-ziplist-entries
        512
hash-max-ziplist-value
        64
hll-sparse-max-bytes
        3000
hz
        10
latency-monitor-threshold
        0
list-max-ziplist-entries
        512
list-max-ziplist-value
        64
logfile

loglevel
        notice
lua-time-limit
        5000
no-appendfsync-on-rewrite
        no
notify-keyspace-events

pidfile
        /var/run/redis.pid
port
        6379
rdbchecksum
        yes
rdbcompression
        yes
repl-disable-tcp-nodelay
        no
repl-diskless-sync
        no
repl-diskless-sync-delay
        5
save
        900, 1
        300, 10
        60, 10000
set-max-intset-entries
        512
slave-priority
        100
slave-read-only
        yes
slave-serve-stale-data
        yes
slowlog-log-slower-than
        10000
slowlog-max-len
        128
stop-writes-on-bgsave-error
        yes
tcp-backlog
        511
tcp-keepalive
        0
timeout
        0
zset-max-ziplist-entries
        128
zset-max-ziplist-value
        64
[7696] 12 May 14:24:45.265 # Warning: 32 bit instance detected but no memory lim
it set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 2.8.19 (00000000/0) 32 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 7696
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

[7696] 12 May 14:24:45.283 # Server started, Redis version 2.8.19
[7696] 12 May 14:24:45.283 * The server is now ready to accept connections on po
rt 6379
[7696] 12 May 14:39:46.081 * 1 changes in 900 seconds. Saving...
arguments seen:
logfile
        stdout
qfork
        140, 7696
[7696] 12 May 14:39:46.246 # fork operation complete
[7696] 12 May 14:39:46.256 * Background saving terminated with success
複製代碼

  Server 端好了,如今咱們開一個 Client 端來測試一下,新打開 CMD (以前打開的 CMD - Server 端不能關閉)

 

redis-cli.exe -h 10.7.15.172 -p 6379

   其中 10.7.15.172 爲本機 IP

set hello helloworld

  設置一個值

get hello

  讀取這個值

  大概15分鐘以後咱們發現 Server 端也有變化

  原來15分鐘自動把內存中的數據寫入 RDF 文件以防丟失。

  至於爲何是15分鐘,咱們能夠看到配置文件是這樣設置的(1個更改/900秒,10更改/300秒,10000更改/60秒),即更改的越多,數據寫入文件的時間間隔越短,這樣設計蠻合理的。

 

3、Redis Desktop Manager

   雖然經過上面的 CMD 咱們也能看到 Redis 在內存中的數據,但方式太不友好了,這裏介紹一個工具 Redis Desktop Manager

  下載完成後安裝,以後鏈接至 Server 便可

 

   點擊查看數據

 

4、Install Redis as Windows Service

   前面咱們經過 CMD 方式安裝了Redis, 可是很是不方便,由於咱們要一直保持窗口打開,並且若是機器重啓的話也須要從新打開。Redis 也能夠以 Windows Service 的方式進行部署。在部署以前咱們須要把配置文件找到

  而後拷貝到 Redis 目錄

  安裝服務

redis-server --service-install redis.windows.conf

  安裝成功提示

  查看服務

  啓動服務

redis-server --service-start

  中止服務

redis-server --service-stop

  卸載服務

redis-server --service-uninstall

 

  其實安裝成 Windows 服務還有一種方式,就是從 Github 上直接下載安裝文件,可是好像不是最新的版本

做者: 舍長
相關文章
相關標籤/搜索