在redis slave上由info命令列出的过期密钥数量与我看到的不一致(Number of expiring keys listed by info command on redis slave not consistent with what I see)
当我在
redis-cli
对redis 3.2.4服务器运行info
命令时,它会显示我的到期时间:
expires=223518
但是,当我运行一个
keys *
命令并要求每个键的ttl
,并且只打印出ttl> 0的键时,我只看到几百个。我认为
expires
是过期密钥数量的计数,但我甚至不在这个数字的数量级内。有人能够确切地澄清
expires
意味着什么吗? 这是否包括待过期和先前已过期但尚未驱逐的密钥?
更新:
以下是我计算过期密钥数量的方法:
task count_tmp_keys: :environment do redis = Redis.new(timeout: 100) keys = redis.keys '*' ct_expiring = 0 keys.each do |k| ttl = redis.ttl(k) if ttl > 0 ct_expiring += 1 puts "Expiring: #{k}; ttl is #{ttl}; total: #{ct_expiring}" STDOUT.flush end end puts "Total expiring: #{ct_expiring}" puts "Done at #{Time.now}" end
当我运行这个脚本时,它显示我总共有78个到期
当我运行信息时,它说
db0:keys=10237963,expires=224098,avg_ttl=0
因为224098比78大得多,我很困惑。 有没有更好的方法让我获得所有225k到期密钥的列表?
另外,我的平均ttl是0怎么样? 你不期望它是非零的吗?
UPDATE
我有新的信息和本地这种情况的简单,100%的责备!
重新编写:在笔记本电脑上本地设置两个redis进程。 让一个成为另一个的奴隶。 在从属进程上,设置以下内容:
config set slave-serve-stale-data yes config set slave-read-only no
现在,连接到从站(而不是主站)并运行:
set foo 1 expire foo 10
10秒后,您将无法再访问foo,但
info
命令仍会显示您的1个密钥到期,平均ttl为0。有人可以解释这种行为吗?
When I run the
info
command inredis-cli
against a redis 3.2.4 server, it shows me this for expires:
expires=223518
However, when I then run a
keys *
command and ask for thettl
for each key, and only print out keys with a ttl > 0, I only see a couple hundred.I thought that the
expires
is a count of the number of expiring keys but I am not even within an order of magnitude of this number.Can someone clarify exactly what
expires
is meant to convey? Does this include both to-be-expired and previously expired but not yet evicted keys?
Update:
Here is how I counted the number of keys expiring:
task count_tmp_keys: :environment do redis = Redis.new(timeout: 100) keys = redis.keys '*' ct_expiring = 0 keys.each do |k| ttl = redis.ttl(k) if ttl > 0 ct_expiring += 1 puts "Expiring: #{k}; ttl is #{ttl}; total: #{ct_expiring}" STDOUT.flush end end puts "Total expiring: #{ct_expiring}" puts "Done at #{Time.now}" end
When I ran this script it shows I have a total expiring of 78
When I run info, it says
db0:keys=10237963,expires=224098,avg_ttl=0
Because 224098 is so much larger than 78, I am very confused. Is there perhaps a better way for me to obtain a list of all 225k expiring keys?
Also, how is it that my average ttl is 0? Wouldn't you expect it to be nonzero?
UPDATE
I have new information and a simple, 100% repro of this situation locally!
To repro: setup two redis processes locally on your laptop. Make one a slave of the other. On the slave process, set the following:
config set slave-serve-stale-data yes config set slave-read-only no
Now, connect to the slave (not the master) and run:
set foo 1 expire foo 10
After 10 seconds, you will no longer be able to access foo, but
info
command will still show that you have 1 key expiring with an average ttl of 0.Can someone explain this behavior?
原文:https://stackoverflow.com/questions/45844944
满意答案
您可以平均使用
COALESCE
- 换句话说,如果在您的平均查询中找不到结果,您将改为显示0.00而不是NULL,因为COALESCE
将转换为第一个非null参数。我在本地复制了您的数据库,并使用所有国家/地区字符串进行了测试,并使用以
SELECT c.carID, c.description, c.model, cy.name, ct.description, COALESCE(l.avgLikes,'0.00') AS 'avglikes' FROM Cars c INNER JOIN Country cy ON c.countryID = cy.countryID AND cy.name = "Germany" INNER JOIN CarType ct ON c.carTypeID = ct.carTypeID LEFT JOIN (SELECT l.carId, AVG(Likes) as avgLikes FROM Likes l GROUP BY l.CarId ) l ON c.carID = l.carID
简单,但希望成功的解决方案。
You could use a
COALESCE
on average likes - in other words, if no results are found in your average query, you will instead show 0.00 instead of NULL, asCOALESCE
will translate to the first non-null parameter.I copied your database locally and tested with all country strings and got the expected output using:
SELECT c.carID, c.description, c.model, cy.name, ct.description, COALESCE(l.avgLikes,'0.00') AS 'avglikes' FROM Cars c INNER JOIN Country cy ON c.countryID = cy.countryID AND cy.name = "Germany" INNER JOIN CarType ct ON c.carTypeID = ct.carTypeID LEFT JOIN (SELECT l.carId, AVG(Likes) as avgLikes FROM Likes l GROUP BY l.CarId ) l ON c.carID = l.carID
Simple, but hopefully successful solution for you.
相关问答
更多如何在SQL查询返回的结果下面选择10行?(How to select 10 rows below the result returned by the SQL query?)
尽管SQL查询,仍返回零行(Zero rows being returned, despite SQL Query)
PHP - 获取sql select查询返回的行数(PHP - get number of rows returned by a sql select query)
SQL返回4行时的2行总和(SQL Sum of 2 rows when 4 rows are returned)
SQL - 查询返回可能不存在的行(SQL - query returning rows that presumably do not exist)
从子查询SQL返回所有行?(Return all rows from sub-query SQL?)
如何从子查询中获取返回的行(how to get returned rows from a sub query)
使用NOT IN的SQL查询不返回任何行(SQL query with NOT IN returning no rows)
PHP SQL查询不返回与phpMyAdmin中相同的行(PHP SQL query not returning same rows as in phpMyAdmin)
PowerShell:如何确定SQL查询是否返回0行(PowerShell: How to determine if SQL query returns 0 rows)
相关文章
更多redis 集群环境搭建-redis集群管理
Redis Cookbook
Redis概述
redis主从从架构搭建-redis集群管理
redis 集群使用主从复制架构-redis集群管理
redis主从复制的原理-redis集群管理
redis从库只读设置-redis集群管理
redis sentinel(哨兵) 配置详解-redis集群管理
Redis配置文件详解
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!