我在redis-py上设置pipeline
以保存2个不同的哈希值
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.keys('*')
时,它不带任何密钥,也不执行self.app.redis.hget('article/1')
我遗失的任何东西?
答案 0 :(得分:0)
发现问题
基本上是过期窗口只考虑了7天,但现在不是。这是从1970年左右开始的时间......