# coding: utf-8
import requests
from redis_wrap import get_hash
from rq.decorators import job

def vimtips(msg=None):
    try:
        existing_tips = get_hash('vimtips')
        _len = len(existing_tips)
        if _len > 0:
            _index = randint(0, _len - 1)
            _k = existing_tips.keys()[_index]
            _v = existing_tips[_k]
            tip = {
                'Content': _k, 
                'Comment': _v
            }
        else:
            tip = requests.get('http://vim-tips.com/random_tips/json').json()
            existing_tips.update({
                tip['Content']: tip['Comment']
            })
        collect_tip()
    except Exception as e:
        return u'哦，不小心玩坏了……'
    return u'%s\n%s' % (tip['Content'], tip['Comment'], )

@job('default')
def collect_tip():
    tip = requests.get('http://vim-tips.com/random_tips/json').json()
    get_hash('vimtips').update({
        tip['Content']: tip['Comment']
    })

@@ -9,16 +9,44 @@
 : utf-8%0A
+from random import randint%0A%0A
 import r
@@ -84,16 +84,25 @@
 get_hash
+, SYSTEMS
 %0Afrom rq
@@ -683,16 +683,22 @@
 lect_tip
+.delay
 ()%0A    e
@@ -734,17 +734,16 @@
  return 
-u
 '%E5%93%A6%EF%BC%8C%E4%B8%8D%E5%B0%8F%E5%BF%83%E7%8E%A9%E5%9D%8F
@@ -758,17 +758,16 @@
  return 
-u
 '%25s%5Cn%25s'
@@ -809,22 +809,97 @@
  )%0A%0A
-@job('default'
+# Fetch a new tip in RQ queue%0A@job('default', connection=SYSTEMS%5B'default'%5D, result_ttl=5
 )%0Ade

Fix import and use queue the right way