def get_cluster_from_options(setting, options, cluster_manager=clusters): cluster_option_name = "cluster" default_cluster_name = "default" cluster_constructor_option_names = frozenset(("hosts",)) options = options.copy() cluster_options = { key: options.pop(key) for key in set(options.keys()).intersection(cluster_constructor_option_names) } if cluster_options: if cluster_option_name in options: raise InvalidConfiguration( "Cannot provide both named cluster ({!r}) and cluster configuration ({}) options.".format( cluster_option_name, ", ".join(map(repr, cluster_constructor_option_names)) ) ) else: warnings.warn( DeprecatedSettingWarning( "{} parameter of {}".format( ", ".join(map(repr, cluster_constructor_option_names)), setting ), f'{setting}["{cluster_option_name}"]', removed_in_version="8.5", ), stacklevel=2, ) cluster = rb.Cluster(pool_cls=_shared_pool, **cluster_options) else: cluster = cluster_manager.get(options.pop(cluster_option_name, default_cluster_name)) return cluster, options
def get_cluster_from_options(setting, options, cluster_manager=clusters): cluster_option_name = 'cluster' default_cluster_name = 'default' cluster_constructor_option_names = frozenset(('hosts',)) options = options.copy() cluster_options = {key: options.pop(key) for key in set(options.keys()).intersection(cluster_constructor_option_names)} if cluster_options: if cluster_option_name in options: raise InvalidConfiguration( 'Cannot provide both named cluster ({!r}) and cluster configuration ({}) options.'.format( cluster_option_name, ', '.join(map(repr, cluster_constructor_option_names)), ) ) else: warnings.warn( DeprecatedSettingWarning( '{} parameter of {}'.format( ', '.join(map(repr, cluster_constructor_option_names)), setting, ), '{}["{}"]'.format( setting, cluster_option_name, ), removed_in_version='8.5', ), stacklevel=2 ) cluster = rb.Cluster(pool_cls=_shared_pool, **cluster_options) else: cluster = cluster_manager.get(options.pop(cluster_option_name, default_cluster_name)) return cluster, options
def get_cluster_from_options(backend, options, cluster_manager=clusters): cluster_option_name = 'cluster' default_cluster_name = 'default' cluster_constructor_option_names = frozenset(('hosts', )) options = options.copy() cluster_options = { key: options.pop(key) for key in set(options.keys()).intersection( cluster_constructor_option_names) } if cluster_options: if cluster_option_name in options: raise InvalidConfiguration( 'Cannot provide both named cluster ({!r}) and cluster configuration ({}) options.' .format( cluster_option_name, ', '.join(map(repr, cluster_constructor_option_names)), )) else: warnings.warn( 'Providing Redis cluster configuration options ({}) to {!r} is ' 'deprecated, please update your configuration to use named Redis ' 'clusters ({!r}).'.format( ', '.join(map(repr, cluster_constructor_option_names)), backend, cluster_option_name, ), DeprecationWarning, stacklevel=2) cluster = rb.Cluster(pool_cls=_shared_pool, **cluster_options) else: cluster = cluster_manager.get( options.pop(cluster_option_name, default_cluster_name)) return cluster, options
def init(): global cluster cluster = rb.Cluster(hosts=redis_map.nodes, host_defaults=redis_map.node_options, router_cls=KitsuneRouter, pool_options={"encoding": "utf-8", "decode_responses": True}) return cluster
def make_rb_cluster(hosts): """Returns a rb cluster that internally shares the pools more intelligetly. """ return rb.Cluster(hosts, pool_cls=_shared_pool)
import rb cluster = rb.Cluster( hosts={ 0: { 'port': 6379 }, 1: { 'port': 6380 }, # 2: {'port': 6381}, }, host_defaults={ 'host': 'localhost', }) if raw_input('Flush? [y/N]').lower() == 'y': with cluster.all() as client: client.flushdb() if raw_input('Write? [y/N]').lower() == 'y': with cluster.map() as client: for key, value in [ ('foo', 1), ('bar', 2), ('baz', 3), ]: client.set(key, value) stop = False while not stop: