欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

Redis需要設(shè)置最大占用內(nèi)存嗎?如果Redis內(nèi)存使用超出了設(shè)置的最大值會(huì)怎樣?

打開redis配置文件

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

# 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

本機(jī)服務(wù)器redis配置文件路徑:/usr/local/openresty/lualib/redis/redis.conf,由于本機(jī)自帶內(nèi)存只有4G,一般推薦Redis設(shè)置內(nèi)存為最大物理內(nèi)存的四分之三,所以設(shè)置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使用超過設(shè)置的最大值

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

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

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

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

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

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

  • volatile-lru -> 根據(jù)LRU算法生成的過期時(shí)間來刪除
  • allkeys-lru -> 根據(jù)LRU算法刪除任何key
  • volatile-random -> 根據(jù)過期設(shè)置來隨機(jī)刪除key
  • allkeys->random -> 無差別隨機(jī)刪
  • volatile-ttl -> 根據(jù)最近過期時(shí)間來刪除(輔以TTL)
  • noeviction -> 誰也不刪,直接在寫操作時(shí)返回錯(cuò)誤 如果設(shè)置了maxmemory,一般都要設(shè)置過期策略。打開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服務(wù)。

使用info命令查看Redis內(nèi)存使用情況

如服務(wù)器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左右。

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

相關(guān)文章

  • Redis中過期鍵如何刪除示例詳解

    Redis中過期鍵如何刪除示例詳解

    因?yàn)閞edis數(shù)據(jù)是基于內(nèi)存的,然而內(nèi)存是非常寶貴的資源,然后我們就會(huì)對(duì)一些不常用或者只用一次的數(shù)據(jù)進(jìn)行存活時(shí)間設(shè)置,這樣才能提高內(nèi)存的使用效率,下面這篇文章主要給大家介紹了關(guān)于Redis中過期鍵如何刪除的相關(guān)資料,需要的朋友可以參考下
    2022-04-04
  • Redis中散列類型的常用命令小結(jié)

    Redis中散列類型的常用命令小結(jié)

    散列類型的鍵值其實(shí)也是一種字典解耦,其存儲(chǔ)了字段和字段值的映射,但字段值只能是字符串,不支持其他數(shù)據(jù)類型,所以說散列類型不能嵌套其他的數(shù)據(jù)類型。下面就來詳細(xì)介紹下Redis中散列類型的常用命令,有需要的可以參考學(xué)習(xí)。
    2016-09-09
  • Redis的setNX分布式鎖超時(shí)時(shí)間失效 -1問題及解決

    Redis的setNX分布式鎖超時(shí)時(shí)間失效 -1問題及解決

    這篇文章主要介紹了Redis的setNX分布式鎖超時(shí)時(shí)間失效 -1問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • RedisTemplate批量操作工具類性能測(cè)試

    RedisTemplate批量操作工具類性能測(cè)試

    這篇文章主要為大家介紹了RedisTemplate批量操作工具類性能測(cè)試詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • redis三種高可用方式部署的實(shí)現(xiàn)

    redis三種高可用方式部署的實(shí)現(xiàn)

    這篇文章主要介紹了redis三種高可用方式部署的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • Redis三種集群模式詳解

    Redis三種集群模式詳解

    redis有三種集群模式,其中主從是最常見的模式,今天通過本文給大家分享Redis三種集群模式介紹,感興趣的朋友一起看看吧
    2021-10-10
  • 深入了解Redis的性能

    深入了解Redis的性能

    這篇文章主要介紹了Redis的性能,作者通過Visual Studio上的C#程序?qū)ζ溥M(jìn)行了分析,需要的朋友可以參考下
    2015-06-06
  • 利用redis實(shí)現(xiàn)聊天記錄轉(zhuǎn)存功能的全過程

    利用redis實(shí)現(xiàn)聊天記錄轉(zhuǎn)存功能的全過程

    社交類軟件聊天功能必不可少,聊天記錄存儲(chǔ)的方式也比較多,比如文本,數(shù)據(jù)庫,云等等,但是最好的選擇還是redis進(jìn)行存儲(chǔ),這篇文章主要給大家介紹了關(guān)于如何利用redis實(shí)現(xiàn)聊天記錄轉(zhuǎn)存功能的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • Windows下Redis的安裝使用圖解

    Windows下Redis的安裝使用圖解

    Redis是一個(gè)key-value存儲(chǔ)系統(tǒng)。Redis的出現(xiàn),很大程度補(bǔ)償了memcached這類key/value存儲(chǔ)的不足,在部分場(chǎng)合可以對(duì)關(guān)系數(shù)據(jù)庫起到很好的補(bǔ)充作用。這篇文章小編為大家分享了在Windows下進(jìn)行安裝和使用Redis的技巧。
    2015-09-09
  • Redis集群Lettuce主從切換問題解決方案

    Redis集群Lettuce主從切換問題解決方案

    這篇文章主要為大家介紹了Redis集群Lettuce主從切換問題解決方案,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07

最新評(píng)論