2014-12-05 67 views
0

我已經設定的Redis-PY一個pipeline保存2 diferent哈希Redis的-PY管道HSET的不節能

p = self.app.redis.pipeline() 
key_id = '{}{}'.format(self.prefix,article.id) 
key_url = '{}{}'.format(self.prefix,article.url) 

# add the common fields from the ArticleModel 
p.hset(key_id, 'shortUrl', shortUrl) 
p.hset(key_url,'shortUrl', shortUrl) 
for k in article.__table__.columns: 
    k = k.name 
    if k not in ['url','id']: 
     p.hset(key_id, k, article.__getattribute__(k)) 
     p.hset(key_url, k, article.__getattribute__(k)) 

# add the different fields and finish the transaction 
p.hset(key_id, 'url', article.url) 
p.hset(key_url, 'id', article.id) 
p.expireat(key_id, self.expiration_window) 
p.expireat(key_url, self.expiration_window) 
p.execute() 

執行前的管道是:

[(('HSET', 'article/1', 'shortUrl', 'qp'), {}), (('HSET', 'article/http://pytest.org/latest/contents.html', 'shortUrl', 'qp'), {}), (('HSET', 'article/1', 'title', u'Full pytest documentation'), {}), (('HSET', 'article/http://pytest.org/latest/contents.html', 'title', u'Full pytest documentation'), {}), (('HSET', 'article/1', 'authors', u''), {}), (('HSET', 'article/http://pytest.org/latest/contents.html', 'authors', u''), {}), (('HSET', 'article/1', 'html', u'<p>Enter search terms or a module, class or function name.</p>\n'), {}), (('HSET', 'article/http://pytest.org/latest/contents.html', 'html', u'<p>Enter search terms or a module, class or function name.</p>\n'), {}), (('HSET', 'article/1', 'plaintext', u'Enter search terms or a module, class or function name. '), {}), (('HSET', 'article/http://pytest.org/latest/contents.html', 'plaintext', u'Enter search terms or a module, class or function name. '), {}), (('HSET', 'article/1', 'markdown', u'Enter search terms or a module, class or function name.\n\n'), {}), (('HSET', 'article/http://pytest.org/latest/contents.html', 'markdown', u'Enter search terms or a module, class or function name.\n\n'), {}), (('HSET', 'article/1', 'date', datetime.datetime(2014, 12, 5, 19, 2, 30, 752183)), {}), (('HSET', 'article/http://pytest.org/latest/contents.html', 'date', datetime.datetime(2014, 12, 5, 19, 2, 30, 752183)), {}), (('HSET', 'article/1', 'url', u'http://pytest.org/latest/contents.html'), {}), (('HSET', 'article/http://pytest.org/latest/contents.html', 'id', 1), {}), (('EXPIREAT', 'article/1', 604800), {}), (('EXPIREAT', 'article/http://pytest.org/latest/contents.html', 604800), {})] 

答案是:

[1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, True, True] 

所以看來它是保存16個鍵。

當執行self.app.redis.hget('article/1')

任何事情我失蹤時執行self.app.redis.keys('*')它不帶任何按鍵,也沒有?

回答

0

發現問題

基本上它是隻考慮7日屆滿窗口,而不是從現在開始。從1970年左右開始......