繁体   English   中英

redis-py管道hset不保存

[英]redis-py pipeline hset not saving

我在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')

我有什么想念的吗?

发现问题

基本上是仅考虑7天而不是现在的过期时间。 从那时开始,大约是1970年...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM