MCPcopy Create free account
hub / github.com/BIT-DataLab/LakeBench / RedisStorage

Class RedisStorage

join/LSH/datasketch/storage.py:910–992  ·  view source on GitHub ↗

Base class for Redis-based storage containers. Args: config (dict): Redis storage units require a configuration of the form:: storage_config={ 'type': 'redis', 'redis': {'host': 'localhost', 'po

Source from the content-addressed store, hash-verified

908
909
910 class RedisStorage:
911 '''Base class for Redis-based storage containers.
912
913 Args:
914 config (dict): Redis storage units require a configuration
915 of the form::
916
917 storage_config={
918 'type': 'redis',
919 'redis': {'host': 'localhost', 'port': 6379},
920 'redis_buffer': {'transaction': True}
921 }
922
923 one can refer to system environment variables via::
924
925 storage_config={
926 'type': 'redis',
927 'redis': {
928 'host': {'env': 'REDIS_HOSTNAME',
929 'default':'localhost'},
930 'port': 6379}
931 },
932 'redis_buffer': {'transaction': True}
933 }
934
935 name (bytes, optional): A prefix to namespace all keys in
936 the database pertaining to this storage container.
937 If None, a random name will be chosen.
938 '''
939
940 def __init__(self, config, name=None):
941 self.config = config
942 self._buffer_size = 50000
943 redis_param = self._parse_config(self.config['redis'])
944 self._redis = redis.Redis(**redis_param)
945 redis_buffer_param = self._parse_config(self.config.get('redis_buffer', {}))
946 self._buffer = RedisBuffer(self._redis.connection_pool,
947 self._redis.response_callbacks,
948 transaction=redis_buffer_param.get('transaction', True),
949 buffer_size=self._buffer_size)
950 if name is None:
951 name = _random_name(11)
952 self._name = name
953
954 @property
955 def buffer_size(self):
956 return self._buffer_size
957
958 @buffer_size.setter
959 def buffer_size(self, value):
960 self._buffer_size = value
961 self._buffer.buffer_size = value
962
963 def redis_key(self, key):
964 return self._name + key
965
966 def _parse_config(self, config):
967 cfg = {}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected