重构set redis
来源:互联网 发布:根据域名查询服务器 编辑:程序博客网 时间:2024/05/22 06:55
def set_redis_data(channel_id,channel) redis = Redis.new(:host => '10.xxx.xx.xx', :port => 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
变形第一次,在video_controller的方法
def set_redis_data(channel) cache_key = "channel_#{channel.channel_id}" video_list = Redis::List.new("channel_#{channel.channel_id}") needed_attributes = %w(show_id showname begin_time end_time vid thumbhd channel_id title) videos = channel.videos.active.where(:begin_time.gt => 10.hours.ago.to_i).only(needed_attributes).asc(:begin_time) videos_json = videos.map { |video| video.to_json } video_list.clear video_list.push *videos_jsonend第二次变形,放channel.rb里啦
<pre name="code" class="html"> def set_redis video_list = Redis::List.new("channel_#{channel_id}") needed_attributes = %w(showid duration showname begin_time end_time vid thumbhd channel_id title) all_videos = videos.active.where(:begin_time.gt => 10.hours.ago.to_i).only(needed_attributes).asc(:begin_time) video_list.clear unless all_videos.empty? videos_json = all_videos.map { |video| video.to_json } video_list.push *videos_json end end
0 0
- 重构set redis
- redis -- set
- redis set
- redis set
- Redis-Set
- redis-set
- 重构Oc的get,set方法
- jbuilder的set!方法重构接口
- iOS @property 重构set、get方法
- 重构案例积累系列:get set方法重构
- set 去重
- set去重
- set 去重
- set排序重定义
- set hashSet 去重
- set集合去重
- redis--set数据类型
- redis数据类型之set
- 【CSS学习】CSS Id 和 Class
- Fragment
- 问题解决:Ubuntu 12.04在vmware10下无法进入Unity模式
- [html5]离线存储
- mysql代理之Atlas
- 重构set redis
- 这是一道BFS入门题
- hdu1863
- Qt 3D教程(二)初步显示3D的内容
- hdu 1213 How Many Tables
- redis主从复制(详细的)
- Group BY
- Find Peak Element
- hdu 1116 Play on Words(欧拉图)