0
我有非常大的数据集,我正在研究使用Redis。我的数据集包含:sha1
散列值以及与该散列值关联的其他n
值。redis中的关键压缩python
我使用我的sha1
散列作为Redis
中的关键字,我的目标是以某种方式压缩它)。我试图用zlib然后base64,但新的哈希甚至更长则原sha1
哈希:
[[email protected] ~]$ python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hashlib
>>> hashlib.sha1('test').hexdigest()
'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'
>>> len(hashlib.sha1('test').hexdigest())
40
>>> import zlib
>>> len(zlib.compress(hashlib.sha1('test').hexdigest()))
46
>>> import base64
>>> base64.b64encode(zlib.compress(hashlib.sha1('test').hexdigest()))
'eJwFwQkBACAIA8BKIihbHB7pH8G7oAXmnaoUZlwpqwXXVsojnNiT2foB7msLYg=='
>>> len(base64.b64encode(zlib.compress(hashlib.sha1('test').hexdigest())))
64
>>>
任何想法如何做呢?
我寻找到以下还有:哈希函数的
- Redis memory-optimization
- How we cut down memory usage by 82% - Octivi Labs
- Storing hundreds of millions of simple key-value pairs in Redis - Instagram Engineering
谢谢你的回复!在碰撞方面,'SHA1'对我来说很好,不幸的是,我不能使用部分散列,并且就“非常大”的数据集而言,在我的情况下,它现在是大约1B的散列。 – alexus
怎么没有部分哈希?是否有可能更多地描述你的用例? – a2800276
虽然我可以肯定地认为思考“盒子外”的方法)这让我想知道,在引入碰撞之前,我可能会散布多少个散列字符...... – alexus