Maximum arity of ruby function? -
i looking make efficient function clear out redis-based cache.
i have method call returns number of keys redis:
$redis.keys("foo:*")
that returns keys start "foo:". next, i'd delete values these keys.
one (memory-intensive) way is:
$redis.keys("foo:*").each |key| $redis.del(key) end
i'd avoid loading keys memory, , making numerous requests redis server.
another way use splat operator:
keys = $redis.keys("foo:*") $redis.del(*keys)
the problem don't know maximum arity of $redis.del
method, nor of ruby method, can't seem find online.
what maximum arity?
@muistooshort in comments had suggestion turned out right, redis driver knows array argument:
# there 1,000,000 keys of form "foo:#{number}" keys = $redis.keys("foo:*") $redis.del(keys) # => 1000000
simply pass array of keys $redis.del
Comments
Post a Comment