偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Redis快速入門,學(xué)會這15點,真的夠用了!

數(shù)據(jù)庫 其他數(shù)據(jù)庫 Redis
大家都知道了redis是基于key-value的no sql數(shù)據(jù)庫,因此,先來了解一下關(guān)于key相關(guān)的知識點。

 1、Redis簡介

REmote DIctionary Server(Redis)是一個由Salvatore Sanfilippo寫的key-value存儲系統(tǒng)。Redis是一個開源的使用ANSI C語言編寫、遵守BSD協(xié)議、支持網(wǎng)絡(luò)、可基于內(nèi)存亦可持久化的日志型、Key-Value數(shù)據(jù)庫,并提供多種語言的API。它通常被稱為數(shù)據(jù)結(jié)構(gòu)服務(wù)器,因為值(value)可以是 字符串(String), 哈希(Map), 列表(list), 集合(sets) 和 有序集合(sorted sets)等類型。

大家都知道了redis是基于key-value的no sql數(shù)據(jù)庫,因此,先來了解一下關(guān)于key相關(guān)的知識點

    1、任何二進制的序列都可以作為key使用

    2、Redis有統(tǒng)一的規(guī)則來設(shè)計key

    3、對key-value允許的最大長度是512MB 

2、支持的語言

  1. ActionScript Bash  C  C#  C++  Clojure Common LispCrystal  D  Dart  Elixir  emacs  lisp  Erlang  Fancy  gawk  GNU Prolog  Go  Haskell  Haxe  Io Java  Javascript  Julia  Lua  Matlab  mruby  Nim  Node.js  Objective-C  OCaml Pascal  Perl  PHP  Pure Data  Python  R  Racket  Rebol  Ruby  Rust Scala  Scheme  Smalltalk  Swift  Tcl  VB  VCL 

3、Redis的應(yīng)用場景到底有哪些??

    1、最常用的就是會話緩存

    2、消息隊列,比如支付

    3、活動排行榜或計數(shù)

    4、發(fā)布、訂閱消息(消息通知)

    5、商品列表、評論列表等

4、Redis安裝

關(guān)于redis安裝與相關(guān)的知識點介紹請參考 Nosql數(shù)據(jù)庫服務(wù)之redis

安裝的大概步驟如下:

Redis是c語言開發(fā)的,安裝redis需要c語言的編譯環(huán)境

如果沒有g(shù)cc需要在線安裝:yum install gcc-c++

第一步:獲取源碼包:wget http://download.redis.io/rele...

第二步:解壓縮redis:tar zxvf redis-3.0.0.tar.gz

第三步:編譯。進入redis源碼目錄(cd redis-3.0.0)。執(zhí)行 make

第四步:安裝。make install PREFIX=/usr/local/redis

PREFIX參數(shù)指定redis的安裝目錄

5、Redis數(shù)據(jù)類型

Redis一共支持五種數(shù)據(jù)類型

1、string(字符串)

2、hash(哈希)

3、list(列表)

4、set(集合)

5、zset(sorted set 有序集合)

string(字符串)

它是redis最基本的數(shù)據(jù)類型,一個key對應(yīng)一個value,需要注意是一個鍵值最大存儲512MB。 

  1. 127.0.0.1:6379> set key "hello world"  
  2. OK  
  3. 127.0.0.1:6379> get key  
  4. "hello world"  
  5. 127.0.0.1:6379> getset key "nihao"  
  6. "hello world"  
  7. 127.0.0.1:6379> mset key1 "hi" key2 "nihao" key3 "hello"  
  8. OK  
  9. 127.0.0.1:6379> get key1  
  10. "hi"  
  11. 127.0.0.1:6379> get key2  
  12. "nihao"  
  13. 127.0.0.1:6379> get key3  
  14. "hello" 

相關(guān)命令介紹

set 為一個Key設(shè)置value(值)

get 獲得某個key對應(yīng)的value(值)

getset 為一個Key設(shè)置value(值)并返回對應(yīng)的值

mset 為多個key設(shè)置value(值)

hash(哈希)

redis hash是一個鍵值對的集合, 是一個string類型的field和value的映射表,適合用于存儲對象 

  1. 127.0.0.1:6379> hset redishash 1 "001"  
  2. (integer) 1  
  3. 127.0.0.1:6379> hget redishash 1  
  4. "001"  
  5. 127.0.0.1:6379> hmset redishash 1 "001" 2 "002"  
  6. OK  
  7. 127.0.0.1:6379> hget redishash 1  
  8. "001"  
  9. 127.0.0.1:6379> hget redishash 2  
  10. "002"  
  11. 127.0.0.1:6379> hmget redishash 1 2  
  12. 1) "001"  
  13. 2) "002" 

相關(guān)命令介紹

hset 將Key對應(yīng)的hash中的field配置為value,如果hash不存則自動創(chuàng)建,

hget 獲得某個hash中的field配置的值

hmset 批量配置同一個hash中的多個field值

hmget 批量獲得同一個hash中的多個field值

list(列表)

是redis簡單的字符串列表,它按插入順序排序 

  1. 127.0.0.1:6379> lpush word  hi  
  2. (integer) 1  
  3. 127.0.0.1:6379> lpush word  hello  
  4. (integer) 2  
  5. 127.0.0.1:6379> rpush word  world  
  6. (integer) 3  
  7. 127.0.0.1:6379> lrange word 0 2  
  8. 1) "hello"  
  9. 2) "hi"  
  10. 3) "world"  
  11. 127.0.0.1:6379> llen word  
  12. (integer) 3 

相關(guān)命令介紹

lpush 向指定的列表左側(cè)插入元素,返回插入后列表的長度

rpush 向指定的列表右側(cè)插入元素,返回插入后列表的長度

llen  返回指定列表的長度

lrange 返回指定列表中指定范圍的元素值

set(集合)

是string類型的無序集合,也不可重復(fù) 

  1. 127.0.0.1:6379> sadd redis redisset  
  2. (integer) 1  
  3. 127.0.0.1:6379> sadd redis redisset1  
  4. (integer) 1  
  5. 127.0.0.1:6379> sadd redis redisset2  
  6. (integer) 1  
  7. 127.0.0.1:6379> smembers redis  
  8. 1) "redisset1"  
  9. 2) "redisset"  
  10. 3) "redisset2"  
  11. 127.0.0.1:6379> sadd redis redisset2  
  12. (integer) 0  
  13. 127.0.0.1:6379> smembers redis  
  14. 1) "redisset1"  
  15. 2) "redisset"  
  16. 3) "redisset2"  
  17. 127.0.0.1:6379> smembers redis  
  18. 1) "redisset1"  
  19. 2) "redisset3"  
  20. 3) "redisset"  
  21. 4) "redisset2"  
  22. 127.0.0.1:6379> srem redis redisset 
  23. (integer) 1  
  24. 127.0.0.1:6379> smembers redis  
  25. 1) "redisset1"  
  26. 2) "redisset3"  
  27. 3) "redisset2" 

相關(guān)命令介紹

sadd 添加一個string元素到key對應(yīng)的set集合中,成功返回1,如果元素存在返回0

smembers 返回指定的集合中所有的元素

srem 刪除指定集合的某個元素

zset(sorted set 有序集合)

是string類型的有序集合,也不可重復(fù)

sorted set中的每個元素都需要指定一個分數(shù),根據(jù)分數(shù)對元素進行升序排序,如果多個元素有相同的分數(shù),則以字典序進行升序排序,sorted set 因此非常適合實現(xiàn)排名 

  1. 127.0.0.1:6379> zadd nosql 0 001  
  2. (integer) 1  
  3. 127.0.0.1:6379> zadd nosql 0 002  
  4. (integer) 1  
  5. 127.0.0.1:6379> zadd nosql 0 003  
  6. (integer) 1  
  7. 127.0.0.1:6379> zcount nosql 0 0   
  8. (integer) 3  
  9. 127.0.0.1:6379> zcount nosql 0 3  
  10. (integer) 3  
  11. 127.0.0.1:6379> zrem nosql 002  
  12. (integer) 1  
  13. 127.0.0.1:6379> zcount nosql 0 3  
  14. (integer) 2  
  15. 127.0.0.1:6379> zscore nosql 003  
  16. "0"  
  17. 127.0.0.1:6379> zrangebyscore nosql 0 10  
  18. 1) "001"  
  19. 2) "003"  
  20. 127.0.0.1:6379> zadd nosql 1 003  
  21. (integer) 0  
  22. 127.0.0.1:6379> zadd nosql 1 004  
  23. (integer) 1 
  24.  127.0.0.1:6379> zrangebyscore nosql 0 10  
  25. 1) "001"  
  26. 2) "003"  
  27. 3) "004"  
  28. 127.0.0.1:6379> zadd nosql 3 005  
  29. (integer) 1  
  30. 127.0.0.1:6379> zadd nosql 2 006  
  31. (integer) 1  
  32. 127.0.0.1:6379> zrangebyscore nosql 0 10  
  33. 1) "001"  
  34. 2) "003"  
  35. 3) "004"  
  36. 4) "006"  
  37. 5) "005" 

相關(guān)命令介紹

zadd  向指定的sorteset中添加1個或多個元素

zrem  從指定的sorteset中刪除1個或多個元素

zcount 查看指定的sorteset中指定分數(shù)范圍內(nèi)的元素數(shù)量

zscore 查看指定的sorteset中指定分數(shù)的元素

zrangebyscore 查看指定的sorteset中指定分數(shù)范圍內(nèi)的所有元素

6、鍵值相關(guān)的命令 

  1. 127.0.0.1:6379> exists key  
  2. (integer) 1  
  3. 127.0.0.1:6379> exists key1  
  4. (integer) 1  
  5. 127.0.0.1:6379> exists key100  
  6. (integer) 0  
  7. 127.0.0.1:6379> get key  
  8. "nihao,hello"  
  9. 127.0.0.1:6379> get key1  
  10. "hi"  
  11. 127.0.0.1:6379> del key1  
  12. (integer) 1  
  13. 127.0.0.1:6379> get key1  
  14. (nil)  
  15. 127.0.0.1:6379> rename key key0  
  16. OK  
  17. 127.0.0.1:6379> get key(nil)  
  18. 127.0.0.1:6379> get key0  
  19. "nihao,hello"  
  20. 127.0.0.1:6379> type key0  
  21. string 

exists       #確認key是否存在

del           #刪除key

expire       #設(shè)置Key過期時間(單位秒)

persist     #移除Key過期時間的配置

rename     #重命名key

type         #返回值的類型 

7、Redis服務(wù)相關(guān)的命令 

  1. 127.0.0.1:6379> select 0  
  2. OK  
  3. 127.0.0.1:6379> info  
  4. # Server  
  5. redis_version:3.0.6  
  6. redis_git_sha1:00000000  
  7. redis_git_dirty:0  
  8. redis_build_id:347e3eeef5029f3  
  9. redis_mode:standalone  
  10. os:Linux 3.10.0-693.el7.x86_64 x86_64  
  11. arch_bits:64  
  12. multiplexing_api:epoll  
  13. gcc_version:4.8.5  
  14. process_id:31197  
  15. run_id:8b6ec6ad5035f5df0b94454e199511084ac6fb12  
  16. tcp_port:6379  
  17. uptime_in_seconds:8514  
  18. uptime_in_days:0  
  19. hz:10  
  20. lru_clock:14015928  
  21. config_file:/usr/local/redis/redis.conf  
  22. -------------------省略N行  
  23. 127.0.0.1:6379> CONFIG GET 0  
  24. (empty list or set)  
  25. 127.0.0.1:6379> CONFIG GET 15  
  26. (empty list or set) 

slect           #選擇數(shù)據(jù)庫(數(shù)據(jù)庫編號0-15)

quit             #退出連接

info             #獲得服務(wù)的信息與統(tǒng)計

monitor       #實時監(jiān)控

config get   #獲得服務(wù)配置

flushdb       #刪除當前選擇的數(shù)據(jù)庫中的key

flushall       #刪除所有數(shù)據(jù)庫中的key 

8、Redis的發(fā)布與訂閱

Redis發(fā)布與訂閱(pub/sub)是它的一種消息通信模式,一方發(fā)送信息,一方接收信息。

下圖是三個客戶端同時訂閱同一個頻道

下圖是有新信息發(fā)送給頻道1時,就會將消息發(fā)送給訂閱它的三個客戶端

9、Redis事務(wù)

Redis事務(wù)可以一次執(zhí)行多條命令

1、發(fā)送exec命令前放入隊列緩存,結(jié)束事務(wù)

2、收到exec命令后執(zhí)行事務(wù)操作,如果某一命令執(zhí)行失敗,其它命令仍可繼續(xù)執(zhí)行

 3、一個事務(wù)執(zhí)行的過程中,其它客戶端提交的請求不會被插入到事務(wù)執(zhí)行的命令列表中

一個事務(wù)經(jīng)歷三個階段

開始事務(wù)(命令:multi)

命令執(zhí)行

結(jié)束事務(wù)(命令:exec) 

  1. 127.0.0.1:6379> MULTI  
  2. OK  
  3. 127.0.0.1:6379> set key key1  
  4. QUEUED  
  5. 127.0.0.1:6379> get key  
  6. QUEUED  
  7. 127.0.0.1:6379> rename key key001  
  8. QUEUED  
  9. 127.0.0.1:6379> exec  
  10. 1) OK  
  11. 2) "key1"  
  12. 3) OK 

10、Redis安全配置

可以通過修改配置文件設(shè)備密碼參數(shù)來提高安全性

 #requirepass foobared

去掉注釋#號就可以配置密碼

沒有配置密碼的情況下查詢?nèi)缦?/strong> 

  1. 127.0.0.1:6379> CONFIG GET requirepass  
  2. 1) "requirepass"  
  3. 2) "" 

配置密碼之后,就需要進行認證 

  1. 127.0.0.1:6379> CONFIG GET requirepass  
  2. (error) NOAUTH Authentication required.  
  3. 127.0.0.1:6379> AUTH foobared   
  4. #認證OK  
  5. 127.0.0.1:6379> CONFIG GET requirepass  
  6. 1) "requirepass"  
  7. 2) "foobared" 

11、Redis持久化

Redis持久有兩種方式:Snapshotting(快照),Append-only file(AOF)

Snapshotting(快照)

1、將存儲在內(nèi)存的數(shù)據(jù)以快照的方式寫入二進制文件中,如默認dump.rdb中

2、save 900 1 

#900秒內(nèi)如果超過1個Key被修改,則啟動快照保存

3、save 300 10 

#300秒內(nèi)如果超過10個Key被修改,則啟動快照保存

4、save 60 10000 

#60秒內(nèi)如果超過10000個Key被修改,則啟動快照保存

Append-only file(AOF)

1、使用AOF持久時,服務(wù)會將每個收到的寫命令通過write函數(shù)追加到文件中(appendonly.aof)

2、AOF持久化存儲方式參數(shù)說明

appendonly yes  

#開啟AOF持久化存儲方式

appendfsync always 

#收到寫命令后就立即寫入磁盤,效率最差,效果最好

appendfsync everysec

#每秒寫入磁盤一次,效率與效果居中

appendfsync no 

#完全依賴OS,效率最佳,效果沒法保證

12、Redis 性能測試

自帶相關(guān)測試工具 

  1. [root@test ~]# redis-benchmark --help 
  2. Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]   
  3. -h <hostname>      Server hostname (default 127.0.0.1)   
  4. -p <port>          Server port (default 6379)   
  5. -s <socket>        Server socket (overrides host and port) -a <password>      Password for Redis Auth   
  6. -c <clients>       Number of parallel connections (default 50)   
  7. -n <requests>      Total number of requests (default 100000)   
  8. -d <size>          Data size of SET/GET value in bytes (default 2)   
  9. -dbnum <db>        SELECT the specified db number (default 0)   
  10. -k <boolean>       1=keep alive 0=reconnect (default 1)   
  11. -r <keyspacelen>   Use random keys for SET/GET/INCR, random values for SADD  Using this option the benchmark will expand the string __rand_int__  inside an argument with a 12 digits number in the specified range  from 0 to keyspacelen-1. The substitution changes every time a command  is executed. Default tests use this to hit random keys in the  specified range.  
  12. -P <numreq>        Pipeline <numreq> requests. Default 1 (no pipeline).   
  13. -q                 Quiet. Just show query/sec values --csv              Output in CSV format   
  14. -l                 Loop. Run the tests forever   
  15. -t <tests>         Only run the comma separated list of tests. The test                    names are the same as the ones produced as output.   
  16. -I                 Idle mode. Just open N idle connections and wait.  
  17. Examples:  
  18. Run the benchmark with the default configuration against 127.0.0.1:6379:     
  19. $ redis-benchmark 
  20. Use 20 parallel clients, for a total of 100k requests, against 192.168.1.1:    
  21. $ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20   
  22. Fill 127.0.0.1:6379 with about 1 million keys only using the SET test:     
  23. $ redis-benchmark -t set -n 1000000 -r 100000000   
  24. Benchmark 127.0.0.1:6379 for a few commands producing CSV output:     
  25. $ redis-benchmark -t ping,set,get -n 100000 --csv   
  26. Benchmark a specific command line:     
  27. $ redis-benchmark -r 10000 -n 10000 eval 'return redis.call("ping")' 0  
  28. Fill a list with 10000 random elements:     
  29. $ redis-benchmark -r 10000 -n 10000 lpush mylist __rand_int__   
  30. On user specified command lines __rand_int__ is replaced with a random integer with a range of values selected by the -r option. 

實際測試同時執(zhí)行100萬的請求 

  1. [root@test ~]# redis-benchmark -n 1000000 -q  
  2. PING_INLINE: 152578.58 requests per second  
  3. PING_BULK: 150308.14 requests per second  
  4. SET: 143266.47 requests per second  
  5. GET: 148632.58 requests per second  
  6. INCR: 145857.64 requests per second  
  7. LPUSH: 143781.45 requests per second  
  8. LPOP: 147819.66 requests per second  
  9. SADD: 138350.86 requests per second  
  10. SPOP: 134282.27 requests per second  
  11. LPUSH (needed to benchmark LRANGE): 141302.81 requests per second  
  12. LRANGE_100 (first 100 elements): 146756.67 requests per second  
  13. LRANGE_300 (first 300 elements): 148104.27 requests per second  
  14. LRANGE_500 (first 450 elements): 152671.75 requests per second  
  15. LRANGE_600 (first 600 elements): 148104.27 requests per second  
  16. MSET (10 keys): 132731.62 requests per second 

13、Redis的備份與恢復(fù)

Redis自動備份有兩種方式

第一種是通過dump.rdb文件實現(xiàn)備份

第二種使用aof文件實現(xiàn)自動備份

dump.rdb備份

Redis服務(wù)默認的自動文件備份方式(AOF沒有開啟的情況下),在服務(wù)啟動時,就會自動從dump.rdb文件中去加載數(shù)據(jù)。

**具體配置在redis.conf

save 900 1

save 300 10

save 60 10000**

也可以手工執(zhí)行save命令實現(xiàn)手動備份 

  1. 127.0.0.1:6379> set name key  
  2. OK  
  3. 127.0.0.1:6379> SAVE  
  4. OK  
  5. 127.0.0.1:6379> set name key1  
  6. OK  
  7. 127.0.0.1:6379> BGSAVE  
  8. Background saving started 

redis快照到dump文件時,會自動生成dump.rdb的文件 

  1. # The filename where to dump the DB  
  2. dbfilename dump.rdb  
  3. -rw-r--r-- 1 root root   253 Apr 17 20:17 dump.rdb 

SAVE命令表示使用主進程將當前數(shù)據(jù)庫快照到dump文件

BGSAVE命令表示,主進程會fork一個子進程來進行快照備份

兩種備份不同之處,前者會阻塞主進程,后者不會。

恢復(fù)舉例 

  1. # Note that you must specify a directory here, not a file name.dir   
  2. /usr/local/redisdata/  
  3. #備份文件存儲路徑 
  4. 127.0.0.1:6379> CONFIG GET dir  
  5. 1) "dir"  
  6. 2) "/usr/local/redisdata"  
  7. 127.0.0.1:6379> set key 001  
  8. OK  
  9. 127.0.0.1:6379> set key1 002  
  10. OK  
  11. 127.0.0.1:6379> set key2 003  
  12. OK  
  13. 127.0.0.1:6379> save  
  14. OK 

將備份文件備份到其它目錄 

  1. [root@test ~]# ll /usr/local/redisdata/  
  2. total 4 
  3. -rw-r--r-- 1 root root 49 Apr 17 21:24 dump.rdb  
  4. [root@test ~]# date  
  5. Tue Apr 17 21:25:38 CST 2018  
  6. [root@test ~]# cp ./dump.rdb /tmp/ 

刪除數(shù)據(jù) 

  1. 127.0.0.1:6379> del key1  
  2. (integer) 1  
  3. 127.0.0.1:6379> get key1  
  4. (nil) 

關(guān)閉服務(wù),將原備份文件拷貝回save備份目錄 

  1. [root@test ~]# redis-cli -a foobared shutdown  
  2. [root@test ~]# lsof -i :6379  
  3. [root@test ~]# cp /tmp/dump.rdb /usr/local/redisdata/  
  4. cp: overwrite ‘/usr/local/redisdata/dump.rdb’? y  
  5. [root@test ~]# redis-server /usr/local/redis/redis.conf &  
  6. [1] 31487 

登錄查看數(shù)據(jù)是否恢復(fù) 

  1. [root@test ~]# redis-cli -a foobared  
  2. 127.0.0.1:6379> mget key key1 key2  
  3. 1) "001"  
  4. 2) "002"  
  5. 3) "003" 

AOF自動備份

redis服務(wù)默認是關(guān)閉此項配置 

  1. ###### APPEND ONLY MODE ##########  
  2. appendonly no 
  3. # The name of the append only file (default: "appendonly.aof")  
  4. appendfilename "appendonly.aof"  
  5. # appendfsync always  
  6. appendfsync everysec  
  7. # appendfsync no 

配置文件的相關(guān)參數(shù),前面已經(jīng)詳細介紹過。

AOF文件備份,是備份所有的歷史記錄以及執(zhí)行過的命令,和mysql binlog很相似,在恢復(fù)時就是重新執(zhí)次一次之前執(zhí)行的命令,需要注意的就是在恢復(fù)之前,和數(shù)據(jù)庫恢復(fù)一樣需要手工刪除執(zhí)行過的del或誤操作的命令。

AOF與dump備份不同

1、aof文件備份與dump文件備份不同

2、服務(wù)讀取文件的優(yōu)先順序不同,會按照以下優(yōu)先級進行啟動

      如果只配置AOF,重啟時加載AOF文件恢復(fù)數(shù)據(jù)

      如果同時 配置了RBD和AOF,啟動是只加載AOF文件恢復(fù)數(shù)據(jù)

      如果只配置RBD,啟動時將加載dump文件恢復(fù)數(shù)據(jù)

注意:只要配置了aof,但是沒有aof文件,這個時候啟動的數(shù)據(jù)庫會是空的

14、Redis 生產(chǎn)優(yōu)化介紹

1、內(nèi)存管理優(yōu)化  

  1. hash-max-ziplist-entries 512    
  2.  hash-max-ziplist-value 64    
  3.  list-max-ziplist-entries 512    
  4.  list-max-ziplist-value 64  
  5.  #list的成員與值都不太大的時候會采用緊湊格式來存儲,相對內(nèi)存開銷也較小 

在linux環(huán)境運行Redis時,如果系統(tǒng)的內(nèi)存比較小,這個時候自動備份會有可能失敗,需要修改系統(tǒng)的vm.overcommit_memory 參數(shù),這個參數(shù)是linux系統(tǒng)的內(nèi)存分配策略

0 表示內(nèi)核將檢查是否有足夠的可用內(nèi)存供應(yīng)用進程使用;如果有足夠的可用內(nèi)存,內(nèi)存申請允許;否則,內(nèi)存申請失敗,并把錯誤返回給應(yīng)用進程。

1 表示內(nèi)核允許分配所有的物理內(nèi)存,而不管當前的內(nèi)存狀態(tài)如何。

2 表示內(nèi)核允許分配超過所有物理內(nèi)存和交換空間總和的內(nèi)存

Redis官方的說明是,建議將vm.overcommit_memory的值修改為1,可以用下面幾種方式進行修改:

(1)編輯/etc/sysctl.conf 改vm.overcommit_memory=1,然后sysctl -p 使配置文件生效

(2)sysctl vm.overcommit_memory=1

(3)echo 1 > /proc/sys/vm/overcommit_memory

**2、內(nèi)存預(yù)分配

3、持久化機制**

定時快照:效率不高,會丟失數(shù)據(jù)

AOF:保持數(shù)據(jù)完整性(一個實例的數(shù)量不要太大2G最大)

優(yōu)化總結(jié)

1)根據(jù)業(yè)務(wù)需要選擇合適的數(shù)據(jù)類型

2)當業(yè)務(wù)場景不需持久化時就關(guān)閉所有持久化方式(采用ssd磁盤來提升效率)

3)不要使用虛擬內(nèi)存的方式,每秒實時寫入AOF

4)不要讓REDIS所在的服務(wù)器物理內(nèi)存使用超過內(nèi)存總量的3/5

5)要使用maxmemory

6)大數(shù)據(jù)量按業(yè)務(wù)分開使用多個redis實例

15、Redis集群應(yīng)用

集群是將多個redis實例集中在一起,實現(xiàn)同一業(yè)務(wù)需求,或者實現(xiàn)高可用與負載均衡

到底有哪些集群方案呢??

1、haproxy+keepalived+redis集群

1)通過redis的配置文件,實現(xiàn)主從復(fù)制、讀寫分離

2)通過haproxy的配置,實現(xiàn)負載均衡,當從故障時也會及時從集群中T除

3)利用keepalived來實現(xiàn)負載的高可用

2、redis官方Sentinel集群管理工具

Redis集群生產(chǎn)環(huán)境高可用方案實戰(zhàn)過程

1)sentinel負責對集群中的主從服務(wù)監(jiān)控、提醒和自動故障轉(zhuǎn)移

2)redis集群負責對外提供服務(wù)

關(guān)于redis sentinel cluster集群配置可參考

3、Redis Cluster

Redis Cluster是Redis的分布式解決方案,在Redis 3.0版本正式推出的,有效解決了Redis分布式方面的需求。當遇到單機內(nèi)存、并發(fā)、流量等瓶頸時,可以采用Cluster架構(gòu)達到負載均衡的目的。

1)官方推薦,毋庸置疑。

2)去中心化,集群最大可增加1000個節(jié)點,性能隨節(jié)點增加而線性擴展。

3)管理方便,后續(xù)可自行增加或摘除節(jié)點,移動分槽等等。

4)簡單,易上手。 

 

責任編輯:龐桂玉 來源: segmentfault
相關(guān)推薦

2019-08-20 14:40:35

Redis數(shù)據(jù)庫

2018-06-14 14:59:26

Redis數(shù)據(jù)庫運維

2018-05-14 09:05:40

Redis數(shù)據(jù)庫String

2020-01-15 09:53:59

MySQL緩存索引

2021-07-07 09:11:45

B端圖表數(shù)據(jù)

2020-07-29 08:05:42

JavaScriptTypeScript工具

2015-10-29 15:36:19

Redis入門

2016-09-21 22:31:47

Python作用域

2021-03-15 23:11:12

內(nèi)存虛擬化技術(shù)

2013-06-27 09:41:19

LuaLua語言Lua語言快速入門

2024-04-16 00:00:00

Spring微服務(wù)架構(gòu)

2020-12-25 09:38:07

Vue前端代碼

2021-03-01 06:12:51

Redis存儲數(shù)據(jù)結(jié)構(gòu)

2019-07-24 14:05:17

Redis內(nèi)存集群

2019-07-25 15:23:05

Redis電腦數(shù)據(jù)庫

2021-09-04 23:38:44

微信手機內(nèi)存

2013-12-19 10:08:52

AWS服務(wù)器

2023-12-19 09:36:35

PostgreSQL數(shù)據(jù)庫開源

2020-05-08 15:37:20

Redis分布式優(yōu)化點

2009-11-16 17:41:46

Oracle數(shù)據(jù)塊
點贊
收藏

51CTO技術(shù)棧公眾號