<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>hrz3424 (qwe)</title>
    <link>https://ruby-china.org/hrz3424</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>自动生成编码导入数据库 利用 Redis 筛选重复的主键值</title>
      <description>&lt;p&gt;文档等我下班之后编写，现在要搬砖了，呵呵！
求助大家代码出现不稳定性，现在不知道原因在哪儿，主键的重复也做判断，但是在插入数据库报错，主键重复&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DateTime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_s&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'%Y-%m-%d %H:%M:%S'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to_s&lt;/span&gt; &lt;span class="c1"&gt;#Time.zone.now&lt;/span&gt;
     &lt;span class="n"&gt;updated_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt;
     &lt;span class="vg"&gt;$redis_qrcodes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Redis&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Namespace&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'qrcode'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;redis: &lt;/span&gt;&lt;span class="no"&gt;Redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="vg"&gt;$redis_qrcodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;del&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'code'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="vi"&gt;@code_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Qrcode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pluck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="vg"&gt;$redis_qrcodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sadd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'code'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="vi"&gt;@code_key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="vi"&gt;@code_key.empty&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;
     &lt;span class="n"&gt;sql_line_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
     &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
       &lt;span class="n"&gt;tmp_code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Qrcode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;digit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
         &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="vg"&gt;$redis_qrcodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sismember&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'code'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tmp_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="vg"&gt;$redis_qrcodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sadd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'code'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tmp_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="n"&gt;sql_line_array&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s2"&gt;"('&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;tmp_code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;','&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;digit&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;','&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;prefixion&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;', '&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;webpage_jump&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;','&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;created_at&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;','&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;updated_at&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;')"&lt;/span&gt;
           &lt;span class="no"&gt;CodeJob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;wait: &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;minute&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;perform_later&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tmp_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="k"&gt;break&lt;/span&gt;
         &lt;span class="k"&gt;else&lt;/span&gt;
            &lt;span class="nb"&gt;p&lt;/span&gt; &lt;span class="s2"&gt;"------------出现重复编码---- &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;tmp_code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-----------------"&lt;/span&gt;
           &lt;span class="n"&gt;tmp_code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Qrcode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;digit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
         &lt;span class="k"&gt;end&lt;/span&gt;
       &lt;span class="k"&gt;end&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s1"&gt;'------------结束批量生成编码code---------------------'&lt;/span&gt;
     &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s1"&gt;'------------开始批量导入数据库---------------------'&lt;/span&gt;
     &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sql_line_array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;','&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="n"&gt;sql_line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"insert into qrcodes (code,digit,prefixion,webpage_jump,created_at,updated_at) values  &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
     &lt;span class="k"&gt;begin&lt;/span&gt;
        &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sql_line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s1"&gt;'------------批量编码code成功导入数据---------------------'&lt;/span&gt;
     &lt;span class="k"&gt;rescue&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;RecordNotUnique&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
       &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s1"&gt;'------------自动生成编码异常重新开始---------------------'&lt;/span&gt;
        &lt;span class="no"&gt;Qrcode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_qr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;digit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;prefixion&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="k"&gt;end&lt;/span&gt;
     &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s1"&gt;'------------结束批量导入数据库---------------------'&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;
   &lt;span class="k"&gt;end&lt;/span&gt;

   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;digit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'a'&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="s1"&gt;'z'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'A'&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="s1"&gt;'Z'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;)].&lt;/span&gt;&lt;span class="nf"&gt;shuffle&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="n"&gt;digit&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;
   &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;最后通过 benchmark 测试出现不稳定，之后查看了 code 的字段类型，
发现用 string varchar(10) 这个是问题的所在地，改用 binary 类型二进制就可以解决&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Fri, 21 Apr 2017 16:28:37 +0800</pubDate>
      <link>https://ruby-china.org/topics/32844</link>
      <guid>https://ruby-china.org/topics/32844</guid>
    </item>
    <item>
      <title>Rails 是否支持硬件的 dll 加载调用接口</title>
      <description>&lt;p&gt;本人现在准备开发学校多媒体教室管理系统，系统使用 b/s 架构。
现在提问 rails 是否支持加载硬件厂商提供的 dll 调用接口？&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Fri, 02 Sep 2016 18:34:41 +0800</pubDate>
      <link>https://ruby-china.org/topics/30976</link>
      <guid>https://ruby-china.org/topics/30976</guid>
    </item>
    <item>
      <title>module 在 controller 上使用出现错误</title>
      <description>&lt;p&gt;TypeError in Admin::SessionsController#new
Admin is not a module&lt;/p&gt;

&lt;p&gt;module Admin
  class SessionsController &amp;lt; Devise::SessionsController
    before_filter :verify_rucaptcha!, only: :create&lt;/p&gt;

&lt;p&gt;求教为啥会出现这个错误&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Sat, 21 May 2016 19:18:24 +0800</pubDate>
      <link>https://ruby-china.org/topics/30084</link>
      <guid>https://ruby-china.org/topics/30084</guid>
    </item>
    <item>
      <title>商城网站的 sku 怎么在 Rails 中实现</title>
      <description>&lt;p&gt;本人在做一套商城网站，现在做商品的 sku 遇到难题，求助&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Tue, 19 Apr 2016 11:43:39 +0800</pubDate>
      <link>https://ruby-china.org/topics/29771</link>
      <guid>https://ruby-china.org/topics/29771</guid>
    </item>
    <item>
      <title>七牛的图片处理谁可以指教下</title>
      <description>&lt;p&gt;七牛上的图片样式编辑格式 small 之后怎么访问 imageView2/1/w/50/h/50/q/75 &lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Tue, 05 Apr 2016 17:10:31 +0800</pubDate>
      <link>https://ruby-china.org/topics/29547</link>
      <guid>https://ruby-china.org/topics/29547</guid>
    </item>
    <item>
      <title>微信的开发</title>
      <description>&lt;p&gt;微信的开发 怎么做本地的代理&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Sat, 27 Jun 2015 12:30:01 +0800</pubDate>
      <link>https://ruby-china.org/topics/26204</link>
      <guid>https://ruby-china.org/topics/26204</guid>
    </item>
    <item>
      <title>在用户表 user 增加 attr_reader:name </title>
      <description>&lt;p&gt;在用户表 user 增加 attr_reader:name   为什么&lt;a href="/user.name" class="user-mention" title="@user.name"&gt;&lt;i&gt;@&lt;/i&gt;user.name&lt;/a&gt;  取不出数据&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Tue, 13 Jan 2015 12:00:18 +0800</pubDate>
      <link>https://ruby-china.org/topics/23702</link>
      <guid>https://ruby-china.org/topics/23702</guid>
    </item>
    <item>
      <title>devise 做用户名 和邮箱同时验证</title>
      <description>&lt;p&gt;devise 扩展了既可以用户名登录 有可以邮箱登录&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Mon, 22 Dec 2014 10:01:23 +0800</pubDate>
      <link>https://ruby-china.org/topics/23325</link>
      <guid>https://ruby-china.org/topics/23325</guid>
    </item>
    <item>
      <title>rails carrierwave-qiniu  </title>
      <description>&lt;p&gt;rails carrierwave-qiniu  七牛的数据处理怎么配置 求助&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Fri, 05 Sep 2014 16:49:12 +0800</pubDate>
      <link>https://ruby-china.org/topics/21403</link>
      <guid>https://ruby-china.org/topics/21403</guid>
    </item>
    <item>
      <title>simple_form html 在线编辑器 rich </title>
      <description>&lt;p&gt;&amp;lt;%= f.input :body, as: :rich  %&amp;gt;&lt;/p&gt;

&lt;p&gt;报错&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Wed, 20 Aug 2014 10:11:40 +0800</pubDate>
      <link>https://ruby-china.org/topics/21130</link>
      <guid>https://ruby-china.org/topics/21130</guid>
    </item>
    <item>
      <title>MQTT 怎么 gem 怎么使用 push 的功能</title>
      <description>&lt;p&gt;&lt;img src="//l.ruby-china.com/photo/2014/cb06ca226ece8c75415268a3eecf6dcf.png" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Thu, 08 May 2014 16:51:46 +0800</pubDate>
      <link>https://ruby-china.org/topics/19104</link>
      <guid>https://ruby-china.org/topics/19104</guid>
    </item>
    <item>
      <title>新浪微博的第三方登录本地的开发怎么弄？</title>
      <description>&lt;p&gt;求助！&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Wed, 07 May 2014 10:54:05 +0800</pubDate>
      <link>https://ruby-china.org/topics/19069</link>
      <guid>https://ruby-china.org/topics/19069</guid>
    </item>
    <item>
      <title>MQTT 这个 push 消息弄过嘛？</title>
      <description>&lt;p&gt;MQTT 这个 push 消息弄过嘛？&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Tue, 06 May 2014 13:38:15 +0800</pubDate>
      <link>https://ruby-china.org/topics/19045</link>
      <guid>https://ruby-china.org/topics/19045</guid>
    </item>
    <item>
      <title>ror 的工作流开发</title>
      <description>&lt;p&gt;现在要求做工作流不知道大家是怎么弄的？&lt;/p&gt;</description>
      <author>hrz3424</author>
      <pubDate>Tue, 04 Mar 2014 19:06:52 +0800</pubDate>
      <link>https://ruby-china.org/topics/17657</link>
      <guid>https://ruby-china.org/topics/17657</guid>
    </item>
  </channel>
</rss>
