最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

設置Redis最大占用內存的實現(xiàn)

 更新時間:2022年05月18日 11:00:21   作者:R先生專欄  
本文主要介紹了設置Redis最大占用內存的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

Redis需要設置最大占用內存嗎?如果Redis內存使用超出了設置的最大值會怎樣?

打開redis配置文件

找到如下段落,設置maxmemory參數(shù),maxmemory是bytes字節(jié)類型,注意轉換。修改如下所示:

# In short... if you have slaves attached it is suggested that you set a lower
# limit for maxmemory so that there is some free RAM on the system for slave
# output buffers (but this is not needed if the policy is 'noeviction').
#
# maxmemory <bytes>
maxmemory 268435456

本機服務器redis配置文件路徑:/usr/local/openresty/lualib/redis/redis.conf,由于本機自帶內存只有4G,一般推薦Redis設置內存為最大物理內存的四分之三,所以設置3G,換成Byte是3221225472.

我們可以在CentOS下輸入命令:find / -name redis查找redis目錄:

[root@VM-8-8-centos ~]# find / -name redis
/etc/selinux/targeted/active/modules/100/redis
/usr/local/openresty/lualib/redis

Redis使用超過設置的最大值

如果Redis的使用超過了設置的最大值會怎樣?讓我們來改一改上面的配置,故意把最大值設為1個byte試試。

# output buffers (but this is not needed if the policy is 'noeviction').
#
# maxmemory <bytes>
maxmemory 1

打開debug模式下的頁面,提示錯誤:OOM command not allowed when used memory > ‘maxmemory’.

設置了maxmemory的選項,redis內存使用達到上限??梢酝ㄟ^設置LRU算法刪除部分key,釋放空間。默認是按照過期時間的,如果set時候沒有加上過期時間就會導致數(shù)據(jù)寫滿maxmemory。

如果不設置maxmemory或者設置為0,64位系統(tǒng)不限制內存,32位系統(tǒng)最多使用3GB內存。

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

  • volatile-lru -> 根據(jù)LRU算法生成的過期時間來刪除
  • allkeys-lru -> 根據(jù)LRU算法刪除任何key
  • volatile-random -> 根據(jù)過期設置來隨機刪除key
  • allkeys->random -> 無差別隨機刪
  • volatile-ttl -> 根據(jù)最近過期時間來刪除(輔以TTL)
  • noeviction -> 誰也不刪,直接在寫操作時返回錯誤 如果設置了maxmemory,一般都要設置過期策略。打開Redis的配置文件有如下描述,Redis有六種過期策略:
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly 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

那么打開配置文件,添加如下一行,使用volatile-lru的過期策略:

maxmemory-policy volatile-lru

保存文件退出,重啟redis服務。

使用info命令查看Redis內存使用情況

如服務器Redis所在目錄:/usr/local/openresty/lualib/redis/src

在終端輸入./redis-cli,打開Redis客戶端,輸入info命令。

出來如下信息:

[root@iZ94r80gdghZ src]# ./redis-cli
127.0.0.1:6379> info
# Server
redis_version:3.0.7
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:f07a42660a61a05e
redis_mode:standalone
os:Linux 3.10.0-327.10.1.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:2165
run_id:8ec8a8dc969d6e2f2867d9188ccb90850bfc9acb
tcp_port:6379
uptime_in_seconds:668
uptime_in_days:0
hz:10
lru_clock:15882419
config_file:/etc/redis/6379.conf

# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:816232
used_memory_human:797.10K
used_memory_rss:7655424
used_memory_peak:816232
used_memory_peak_human:797.10K
used_memory_lua:36864
mem_fragmentation_ratio:9.38
mem_allocator:jemalloc-3.6.0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1458722327
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok

# Stats
total_connections_received:1
total_commands_processed:0
instantaneous_ops_per_sec:0
total_net_input_bytes:14
total_net_output_bytes:0
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0

# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:0.30
used_cpu_user:0.29
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Cluster
cluster_enabled:0

# Keyspace
db0:keys=1,expires=1,avg_ttl=425280

其中used_memory:816232,僅用了0.7M左右。

到此這篇關于設置Redis最大占用內存的實現(xiàn)的文章就介紹到這了,更多相關Redis最大占用內存內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Redis數(shù)據(jù)一致性問題的三種解決方案

    Redis數(shù)據(jù)一致性問題的三種解決方案

    Redis(Remote?Dictionary?Server?),是一個高性能的基于Key-Value結構存儲的NoSQL開源數(shù)據(jù)庫,大部分公司采用Redis來實現(xiàn)分布式緩存,用來提高數(shù)據(jù)查詢效率,本文就給大家介紹三種Redis數(shù)據(jù)一致性問題的解決方案,需要的朋友可以參考下
    2023-07-07
  • 使用Redis有序集合實現(xiàn)IP歸屬地查詢詳解

    使用Redis有序集合實現(xiàn)IP歸屬地查詢詳解

    這篇文章主要介紹了使用Redis有序集合實現(xiàn)IP歸屬地查詢,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-04-04
  • 一文詳解Redis在Ubuntu系統(tǒng)上的安裝步驟

    一文詳解Redis在Ubuntu系統(tǒng)上的安裝步驟

    安裝redis在Ubuntu上有多種方法,下面這篇文章主要給大家介紹了關于Redis在Ubuntu系統(tǒng)上安裝的相關資料,文中通過圖文以及代碼介紹的非常詳細,需要的朋友可以參考下
    2024-07-07
  • Redis主從集群切換數(shù)據(jù)丟失的解決方案

    Redis主從集群切換數(shù)據(jù)丟失的解決方案

    這篇文章主要介紹了Redis主從集群切換數(shù)據(jù)丟失的解決方案,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • Redis安裝配置與常用命令

    Redis安裝配置與常用命令

    Redis 是一款開源的,基于 BSD 許可的,高級鍵值 (key-value) 緩存 (cache) 和存儲 (store) 系統(tǒng)。由于 Redis 的鍵包括 string,hash,list,set,sorted set,bitmap 和 hyperloglog,所以常常被稱為數(shù)據(jù)結構服務器。
    2018-03-03
  • Redis和數(shù)據(jù)庫 數(shù)據(jù)同步問題的解決

    Redis和數(shù)據(jù)庫 數(shù)據(jù)同步問題的解決

    這篇文章主要介紹了Redis和數(shù)據(jù)庫 數(shù)據(jù)同步問題的解決操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • redis與memcached的區(qū)別_動力節(jié)點Java學院整理

    redis與memcached的區(qū)別_動力節(jié)點Java學院整理

    Memcached是以LiveJurnal旗下Danga Interactive公司的Bard Fitzpatric為首開發(fā)的高性能分布式內存緩存服務器。那么redis與memcached有什么區(qū)別呢?下面小編給大家介紹下redis與memcached的區(qū)別,感興趣的朋友參考下吧
    2017-08-08
  • Python Redis如何執(zhí)行Lua腳本

    Python Redis如何執(zhí)行Lua腳本

    這篇文章主要介紹了Python Redis如何執(zhí)行Lua腳本問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • redis的持久化和緩存機制解讀

    redis的持久化和緩存機制解讀

    這篇文章主要介紹了redis的持久化和緩存機制,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • 淺談Redis緩存雪崩解決方案

    淺談Redis緩存雪崩解決方案

    本文主要介紹了Redis緩存雪崩解決方案,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-05-05

最新評論

肇源县| 安阳市| 黎平县| 吉林省| 吉林省| 遂宁市| 吉水县| 萝北县| 炉霍县| 常州市| 罗定市| 曲麻莱县| 美姑县| 嘉善县| 琼海市| 洛南县| 东海县| 呼和浩特市| 柯坪县| 金昌市| 弋阳县| 泽州县| 区。| 扶风县| 微博| 正定县| 乌兰察布市| 浦江县| 故城县| 武冈市| 清苑县| 当雄县| 常德市| 天祝| 米林县| 永福县| 彰化市| 名山县| 广元市| 积石山| 阿巴嘎旗|