redis键复制
redis并没有提供key的复制命令,但是可以通过redis提供的lua脚本实现。
require 'rubygems' require 'redis' r = Redis.new KeyCopyScript = <<EOF local max_key = tonumber(ARGV[1]) local i = 0 while(i <= max_key) do local key_1 = "account:" .. i .. ":" .. KEYS[1] local res = redis.call('exists',key_1) if( res ) then local key_2 = "account:" .. i .. ":" .. KEYS[2] local val = redis.call('get',key_1) redis.call('set',key_2,val) i = i + 1 end end EOF puts r.eval(KeyCopyScript,["value_src","value_dest"],[2])
blog comments powered by Disqus