module Roma::CommandPlugin::PluginMapCount

Constants

DATE_FORMAT
PLUGIN_MAPCOUNT_VERSION

Private Instance Methods

countup(ctx, stype) click to toggle source
    # File lib/roma/plugin/plugin_mapcount.rb
 86 def countup(ctx, stype)
 87  v = {}
 88   v = data_load(ctx.stored.value) if ctx.stored
 89 
 90   args = ctx.params.value.split(/\s*,\s*/)
 91   args.each do |arg|
 92     if arg =~ /^([A-Za-z0-9]+)(:(\-?[\d]+))?$/
 93       key = $1
 94       count = 1
 95       count = $3.to_i if $3
 96       v[key] ||= 0
 97       v[key] += count
 98     else
 99       raise ClientErrorException, "invalid sub_keys format: #{ctx.params.value}"
100     end
101   end
102 
103   v["last_updated_date"] = Time.now.strftime(DATE_FORMAT)
104   expt = chg_time_expt(ctx.argv[2].to_i)
105 
106   ret_str = return_str(v, stype)
107   ret_msg = "VALUE #{ctx.params.key} 0 #{ret_str.length}\r\n#{ret_str}\r\nEND"
108   [0, expt, Marshal.dump(v), :write, ret_msg]
109 end
data_load(data) click to toggle source
    # File lib/roma/plugin/plugin_mapcount.rb
170 def data_load(data)
171   begin
172     Marshal.load(data)
173   rescue => e
174     msg = "SERVER_ERROR #{e} #{$@}".tr("\r\n"," ")
175     send_data("#{msg}\r\n")
176     @log.error("#{e} #{$@}")
177   end
178 end
get(ctx, stype) click to toggle source
    # File lib/roma/plugin/plugin_mapcount.rb
141 def get(ctx, stype)
142   ret = nil
143   if ctx.stored
144     ret_val = data_load(ctx.stored.value)
145 
146     if ret_val.is_a?(Hash)
147       args = ctx.params.value.split(/\s*,\s*/)
148       if args.count == 0
149         ret = return_str(ret_val, stype)
150       else
151         ret = {}
152         ret["last_updated_date"] = ret_val["last_updated_date"]
153         args.each do |arg|
154           ret[arg] = ret_val[arg] if ret_val[arg] != nil
155         end
156         ret = return_str(ret, stype)
157       end
158     end
159   end
160 
161   send_data("VALUE #{ctx.params.key} 0 #{ret.length}\r\n#{ret}\r\n") if ret
162   send_data("END\r\n")
163 end
return_str(data, stype) click to toggle source
    # File lib/roma/plugin/plugin_mapcount.rb
165 def return_str(data, stype)
166   return Marshal.dump(data) if stype == :marshal
167   data.to_json
168 end
update(ctx, stype) click to toggle source
    # File lib/roma/plugin/plugin_mapcount.rb
111 def update(ctx, stype)
112   if !ctx.stored
113     send_data("END\r\n")
114     return
115   end
116 
117   v = {}
118   v = data_load(ctx.stored.value)
119   v["last_updated_date"] = Time.now.strftime(DATE_FORMAT)
120 
121   if v.is_a?(Hash)
122     args = ctx.params.value.split(/\s*,\s*/)
123     if args.count == 0
124       ret = return_str(v, stype)
125     else
126       ret = {}
127       ret["last_updated_date"] = v["last_updated_date"]
128       args.each do |arg|
129         ret[arg] = v[arg] if v[arg] != nil
130       end
131       ret = return_str(ret, stype)
132     end
133   end
134 
135   expt = chg_time_expt(ctx.argv[2].to_i)
136 
137   ret_msg = "VALUE #{ctx.params.key} 0 #{ret.length}\r\n#{ret}\r\nEND"
138   [0, expt, Marshal.dump(v), :write, ret_msg]
139 end