I have set a pipeline
on redis-py to save 2 diferent hashes
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()
The pipeline before executing is:
[(('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), {})]
And the answer is:
[1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, True, True]
So it seems that it is saving the 16 keys.
When executing self.app.redis.keys('*')
it does not bring any key nor when executing self.app.redis.hget('article/1')
Any thing I am missing?
Found the problem
basically it was the expiration window that was only considering 7 days, but not from now. It was from the beginning of the time, around 1970...