Last active
December 31, 2015 05:29
-
-
Save ijin/7941042 to your computer and use it in GitHub Desktop.
Server Festa 2013 Autumn base syncer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mysql2' | |
require 'dalli' | |
require 'connection_pool' | |
$stdout.sync = true | |
unless ARGV[0] | |
puts "Usage: sync.rb PAGE_ID" | |
exit 1 | |
end | |
page_id = ARGV[0] | |
@memcached = ConnectionPool.new(:size => 5, :timeout => 5) { Dalli::Client.new } | |
#dc = Dalli::Client.new('localhost:11211') | |
client = Mysql2::Client.new(:host => "localhost", :username => "USERNAME", :password => "PASSWORD", :database => "wordpress") | |
@memcached.with do |dc| | |
while true do | |
time = Time.now | |
value = dc.get(page_id) | |
query = "UPDATE wp_posts SET comment_count = #{value} WHERE ID = #{page_id}" | |
client.query(query) | |
puts value | |
puts Time.now - time | |
sleep 0.005 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment