我pipeline
在 redis-py 上设置了一个来保存 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')
有什么我想念的吗?