Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weather-model
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
weather-model
Commits
b303d471
Commit
b303d471
authored
May 16, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ohm obj ttl
parent
390bb5b0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
17 deletions
+10
-17
storer.rb
lib/weather-model/storer.rb
+4
-3
weather-model_spec.rb
spec/weather-model_spec.rb
+6
-14
No files found.
lib/weather-model/storer.rb
View file @
b303d471
...
...
@@ -44,9 +44,10 @@ module WeatherModel
obj
.
update_ttl
self
.
class
.
instance_variable_get
(
:@expire
)
end
# def self.all_valid
# self.all.to
# end
def
self
.
all
super
.
select
{
|
x
|
x
.
attributes
.
empty?
}.
map
(
&
:delete
)
super
end
private
...
...
spec/weather-model_spec.rb
View file @
b303d471
...
...
@@ -6,7 +6,7 @@ RSpec.describe WeatherModel do
include
WeatherModel
before
do
# 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
Dir
[
File
.
dirname
(
__FILE__
)
+
'/../db/migrate/*.rb'
].
each
{
|
file
|
require
file
}
ActiveRecord
::
Base
.
establish_connection
(
...
...
@@ -23,6 +23,8 @@ RSpec.describe WeatherModel do
end
it
'Forecast'
do
@expire
=
2
Forecast
::
ShanghaiTen
::
Ohm
.
expire
@expire
mysql_obj
=
Forecast
::
ShanghaiTen
.
create
({
datetime:
'2017-05-16'
,
cityname:
'shanghai'
,
...
...
@@ -36,23 +38,13 @@ RSpec.describe WeatherModel do
expect
(
Forecast
::
ShanghaiTen
.
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.get_ttl).to eq(5
)
expect
(
Forecast
::
ShanghaiTen
::
Ohm
.
all
.
first
.
get_ttl
).
to
eq
(
@expire
)
# 'ohm 对象 同步 mysql对象更新'
mysql_obj
.
update
(
temp_low:
99
)
expect
(
Forecast
::
ShanghaiTen
::
Ohm
.
all
.
first
.
temp_low
).
to
eq
(
'99'
),
'ohm 对象 同步 mysql对象更新'
# p Forecast::ShanghaiTen::Ohm.all.first.get_ttl
# 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)
sleep
3
expect
(
Forecast
::
ShanghaiTen
::
Ohm
.
all
.
count
).
to
eq
(
0
),
'TTL过期对象删除成功'
end
after
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment