Return an unordered storage system based on the specified config. The canonical example of such a storage container is ``defaultdict(set)``. Thus, the return value of this method contains keys and values. The values are unordered sets. Args: config (dict): Defines the confi
(config, name=None)
| 63 | |
| 64 | |
| 65 | def unordered_storage(config, name=None): |
| 66 | '''Return an unordered storage system based on the specified config. |
| 67 | |
| 68 | The canonical example of such a storage container is |
| 69 | ``defaultdict(set)``. Thus, the return value of this method contains |
| 70 | keys and values. The values are unordered sets. |
| 71 | |
| 72 | Args: |
| 73 | config (dict): Defines the configurations for the storage. |
| 74 | For in-memory storage, the config ``{'type': 'dict'}`` will |
| 75 | suffice. For Redis storage, the type should be ``'redis'`` and |
| 76 | the configurations for the Redis database should be supplied |
| 77 | under the key ``'redis'``. These parameters should be in a form |
| 78 | suitable for `redis.Redis`. The parameters may alternatively |
| 79 | contain references to environment variables, in which case |
| 80 | literal configuration values should be replaced by dicts of |
| 81 | the form:: |
| 82 | |
| 83 | {'env': 'REDIS_HOSTNAME', |
| 84 | 'default': 'localhost'} |
| 85 | |
| 86 | For a full example, see :ref:`minhash_lsh_at_scale` |
| 87 | |
| 88 | name (bytes, optional): A reference name for this storage container. |
| 89 | For dict-type containers, this is ignored. For Redis containers, |
| 90 | this name is used to prefix keys pertaining to this storage |
| 91 | container within the database. |
| 92 | ''' |
| 93 | tp = config['type'] |
| 94 | if tp == 'dict': |
| 95 | return DictSetStorage(config) |
| 96 | if tp == 'redis': |
| 97 | return RedisSetStorage(config, name=name) |
| 98 | if tp == 'cassandra': |
| 99 | return CassandraSetStorage(config, name=name) |
| 100 | |
| 101 | |
| 102 | def _random_name(length): |
no test coverage detected