object idletime command

413 views
Skip to first unread message

lsbardel

unread,
Feb 2, 2012, 5:19:52 AM2/2/12
to redi...@googlegroups.com
Hello,
I'm using this script


to obtain information about keys for a given pattern.
The script calls the KEYS command to collect all relevant keys and subsequently it collect information.
Unfortunately, the OBJECT IDLETIME call will always return 0 (I assume because of the previous KEYS call).
How can I solve the issue?
Any help appreciated.

Thanks

Luca

Salvatore Sanfilippo

unread,
Feb 2, 2012, 5:49:17 AM2/2/12
to redi...@googlegroups.com
Hello Luca, just checked the code and KEYS should not reset the object
idle time, however I'm now trying your script to understand what
happens.

About your script, it sounds like a good idea to use scripting for
data sampling like that, however it could be more correct to pass the
pattern as argument and not as a key to EVAL.

More news soon,
Salvatore

> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/redis-db/-/uwzHSic7-mAJ.
> To post to this group, send email to redi...@googlegroups.com.
> To unsubscribe from this group, send email to
> redis-db+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/redis-db?hl=en.

--
Salvatore 'antirez' Sanfilippo
open source developer - VMware

http://invece.org
"We are what we repeatedly do. Excellence, therefore, is not an act,
but a habit." -- Aristotele

Salvatore Sanfilippo

unread,
Feb 2, 2012, 5:54:40 AM2/2/12
to redi...@googlegroups.com
The attached script fixes the issue. The problem is that you access
the key with STRLEN, LLEN, ..., before checking the idle time, so it
gets reset. I just inverted the calls and now it is working well. But
of course after the first run all the keys will have idle time 0.

Salvatore

local pattern = KEYS[1]
local type_table = {}
type_table['set'] = 'scard'
type_table['zset'] = 'zcard'
type_table['list'] = 'llen'
type_table['hash'] = 'hlen'
type_table['string'] = 'strlen'
local stats = {}
local typ, command, len
for i,key in ipairs(redis.call('KEYS',pattern)) do
idletime = redis.call('object','idletime',key)
typ = redis.call('type',key)['ok']
command = type_table[typ]
len = 0
if command then
len = len + redis.call(command, key)
end
stats[i] = {key,typ,len,redis.call('ttl',key),
redis.call('object','encoding',key),
idletime}
end
return stats

lsbardel

unread,
Feb 2, 2012, 6:40:48 AM2/2/12
to redi...@googlegroups.com
Of course! How could I not see that!?
Thanks a lot.

Luca

Salvatore Sanfilippo

unread,
Feb 2, 2012, 10:48:17 AM2/2/12
to redi...@googlegroups.com
On Thu, Feb 2, 2012 at 12:40 PM, lsbardel <luca.sb...@gmail.com> wrote:

> Of course! How could I not see that!?

It's very easy to overlook this stuff because the script as a "flow"
was gathering info. Just as a side effect was also changing this
info... :)

Keep an eye about shared integers! small integers will report OBJECT
IDLETIME that is "shared" across all the keys.

Salvatore

Reply all
Reply to author
Forward
0 new messages