Commit b303d471 by ivan Lan

Fix ohm obj ttl

parent 390bb5b0
...@@ -44,9 +44,10 @@ module WeatherModel ...@@ -44,9 +44,10 @@ module WeatherModel
obj.update_ttl self.class.instance_variable_get(:@expire) obj.update_ttl self.class.instance_variable_get(:@expire)
end end
# def self.all_valid def self.all
# self.all.to super.select{ |x| x.attributes.empty?}.map(&:delete)
# end super
end
private private
......
...@@ -6,7 +6,7 @@ RSpec.describe WeatherModel do ...@@ -6,7 +6,7 @@ RSpec.describe WeatherModel do
include WeatherModel include WeatherModel
before do before do
# start an ohm # start an ohm
Ohm.redis = Redic.new("redis://127.0.0.1:6379") Ohm.redis = Redic.new("redis://127.0.0.1:6379/5")
# run migration # run migration
Dir[File.dirname(__FILE__) + '/../db/migrate/*.rb'].each { |file| require file } Dir[File.dirname(__FILE__) + '/../db/migrate/*.rb'].each { |file| require file }
ActiveRecord::Base.establish_connection( ActiveRecord::Base.establish_connection(
...@@ -23,6 +23,8 @@ RSpec.describe WeatherModel do ...@@ -23,6 +23,8 @@ RSpec.describe WeatherModel do
end end
it 'Forecast' do it 'Forecast' do
@expire = 2
Forecast::ShanghaiTen::Ohm.expire @expire
mysql_obj = Forecast::ShanghaiTen.create({ mysql_obj = Forecast::ShanghaiTen.create({
datetime: '2017-05-16', datetime: '2017-05-16',
cityname: 'shanghai', cityname: 'shanghai',
...@@ -36,23 +38,13 @@ RSpec.describe WeatherModel do ...@@ -36,23 +38,13 @@ RSpec.describe WeatherModel do
expect(Forecast::ShanghaiTen.count).to eq(1) expect(Forecast::ShanghaiTen.count).to eq(1)
expect(Forecast::ShanghaiTen::Ohm.all.count).to eq(1) expect(Forecast::ShanghaiTen::Ohm.all.count).to eq(1)
expect(Forecast::ShanghaiTen::Ohm.all.first.temp_low).to eq(mysql_obj.temp_low.to_s) expect(Forecast::ShanghaiTen::Ohm.all.first.temp_low).to eq(mysql_obj.temp_low.to_s)
# expect(Forecast::ShanghaiTen::Ohm.all.first.get_ttl).to eq(5) expect(Forecast::ShanghaiTen::Ohm.all.first.get_ttl).to eq(@expire)
# 'ohm 对象 同步 mysql对象更新' # 'ohm 对象 同步 mysql对象更新'
mysql_obj.update(temp_low: 99) mysql_obj.update(temp_low: 99)
expect(Forecast::ShanghaiTen::Ohm.all.first.temp_low).to eq('99'), 'ohm 对象 同步 mysql对象更新' expect(Forecast::ShanghaiTen::Ohm.all.first.temp_low).to eq('99'), 'ohm 对象 同步 mysql对象更新'
# p Forecast::ShanghaiTen::Ohm.all.first.get_ttl sleep 3
# sleep 4
# expect(Forecast::ShanghaiTen::Ohm.all.count).to eq(1)
p Forecast::ShanghaiTen::Ohm.all.first.key
# sleep 2
p
p Ohm.redis.call('KEYS', '*ShanghaiTen*')
# p Ohm.redis.call('HGETALL', 'Forecast::ShanghaiTen::Ohm:indices:cityname:shanghai')
# p Forecast::ShanghaiTen::Ohm.find(mysql_id: mysql_obj.id).to_a
# expect(Forecast::ShanghaiTen::Ohm.find(mysql_id: mysql_obj.id)).to eq(0)
expect(Forecast::ShanghaiTen::Ohm.all.count).to eq(0), 'TTL过期对象删除成功'
end end
after do after do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment