Refactoring set Redis

Source: Internet
Author: User

    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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.