defSet_redis_data (channel_id,channel) Redis= Redis.new (: host = ='10.xxx.xx.xx',:p ort = 6379) Redis.del(channel_id) yesterday= (time.now-36000). To_i All_channel_videos= Channel.videos.not_deleted.where (: begin_time.gt = =yesterday). Desc (: begin_time) All_channel_videos.each do|v|Video_hash={} Video_hash[:showid]=V.showid Video_hash[:showname]=V.showname Video_hash[:begin_time]=V.begin_time Video_hash[:end_time]=V.end_time Video_hash[:vid]=V.vid Video_hash[:thumbhd]=V.thumbhd video_hash[:channel_id]=v.channel_id Video_hash[:title]=v.title Redis.lpush channel_id, Video_hash.to_json end End
In the Video_controller method
def Set_redis_data (channel) Cache_key "channel_#{channel.channel_id}" = Redis::list.new ("channel_#{channel.channel_id}") =%W (show_id showname begin_time end_time vid thumbhd channel_id title) = Channel.videos.active.where (: begin_time.gt =hours.ago.to_i). Only (Needed_attributes). ASC (: Begin_time ) = videos.map {|video| Video.to_json} video_list.clear video.push videos_jsonend
In the model CHANNEL.RB.
def Set_redis = Redis::list.new ("channel_#{channel_id}") =%W (show_id showname begin _time end_time vid thumbhd channel_id title) = Videos.active.where (: begin_time.gt = hours.ago.to _i). Only (Needed_attributes). ASC (: begin_time) = all_videos.map {|video| Video.to_json} video_ List.clear video.push videos_json End
Refactoring set Redis