Python redis.exceptions.ResponseError() Examples
The following are 22
code examples of redis.exceptions.ResponseError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
redis.exceptions
, or try the search function
.
Example #1
Source File: GlobalKeySpace.py From redis-memory-analyzer with MIT License | 6 votes |
def analyze(self): total_keys = self.redis.dbsize() used = {} info = {} try: for key, value in self.redis.config_get("*max-*-*").items(): used[key] = value except ResponseError as e: self.logger.warning("*max* option skipped: %s", repr(e)) for key, value in self.redis.info('memory').items(): info[key] = value return { "info": info, "used": used, "totalKeys": total_keys, "redisKeySpaceOverhead": dict_overhead(total_keys), }
Example #2
Source File: scanner.py From redis-memory-analyzer with MIT License | 6 votes |
def resolve_types(self, ret): if not self.pipeline_mode: try: key_with_types = msgpack.unpackb(self.resolve_types_script(ret)) except ResponseError as e: if "CROSSSLOT" not in repr(e): raise e key_with_types = self.resolve_with_pipe(ret) self.pipeline_mode = True else: key_with_types = self.resolve_with_pipe(ret) for i in range(0, len(ret)): yield key_with_types[i], ret[i] ret.clear()
Example #3
Source File: application.py From redis-memory-analyzer with MIT License | 6 votes |
def connect_to_redis(host, port, db=0, password=None, ssl=False): """ :param host: :param port: :param db: :param password: :return RmaRedis: """ try: redis = RmaRedis(host=host, port=port, db=db, password=password, ssl=ssl) if not check_redis_version(redis): sys.stderr.write('This script only works with Redis Server version 2.6.x or higher\n') sys.exit(-1) except ConnectionError as e: sys.stderr.write('Could not connect to Redis Server : %s\n' % e) sys.exit(-1) except ResponseError as e: sys.stderr.write('Could not connect to Redis Server : %s\n' % e) sys.exit(-1) return redis
Example #4
Source File: test.py From redisai-py with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_dagrun_without_load_and_persist(self): con = self.get_client() dag = con.dag(load='wrongkey') with self.assertRaises(ResponseError): dag.tensorget('wrongkey').run() dag = con.dag() dag.tensorset('a', [2, 3, 2, 3], shape=(2, 2), dtype='float') dag.tensorset('b', [2, 3, 2, 3], shape=(2, 2), dtype='float') dag.modelrun("pt_model", ["a", "b"], ["output"]) dag.tensorget('output') result = dag.run() expected = ['OK', 'OK', 'OK', np.array([[4., 6.], [4., 6.]], dtype=np.float32)] self.assertTrue(np.allclose(expected.pop(), result.pop())) self.assertEqual(expected, result)
Example #5
Source File: test_disque.py From pydisque with MIT License | 6 votes |
def _test_pause(self): """ TODO: """ """Test that a PAUSE message is acknowledged.""" queuename = "test_show-%s" % self.testID test_job = "Jerbs, they are a thing" self.client.pause(queuename, kw_in=True) try: job_id = self.client.add_job(queuename, test_job) except ResponseError: pass # can we add a job again? self.client.pause(queuename, kw_none=True) job_id = self.client.add_job(queuename, test_job) jobs = self.client.get_job([queuename]) # TODO(canardleteer): add a test of PAUSE SHOW
Example #6
Source File: test.py From redisai-py with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_scripts(self): con = self.get_client() self.assertRaises(ResponseError, con.scriptset, 'ket', 'cpu', 'return 1') con.scriptset('ket', 'cpu', script) con.tensorset('a', (2, 3), dtype='float') con.tensorset('b', (2, 3), dtype='float') # try with bad arguments: self.assertRaises(ResponseError, con.scriptrun, 'ket', 'bar', inputs=['a'], outputs=['c']) con.scriptrun('ket', 'bar', inputs=['a', 'b'], outputs=['c']) tensor = con.tensorget('c', as_numpy=False) self.assertEqual([4, 6], tensor['values']) script_det = con.scriptget('ket') self.assertTrue(script_det['device'] == 'cpu') self.assertTrue(script_det['source'] == script) script_det = con.scriptget('ket', meta_only=True) self.assertTrue(script_det['device'] == 'cpu') self.assertNotIn('source', script_det) con.scriptdel('ket') self.assertRaises(ResponseError, con.scriptget, 'ket')
Example #7
Source File: redis_utils.py From taskflow with Apache License 2.0 | 6 votes |
def is_server_new_enough(client, min_version, default=False, prior_version=None): """Checks if a client is attached to a new enough redis server.""" if not prior_version: try: server_info = client.info() except redis_exceptions.ResponseError: server_info = {} version_text = server_info.get('redis_version', '') else: version_text = prior_version version_pieces = [] for p in version_text.split("."): try: version_pieces.append(int(p)) except ValueError: break if not version_pieces: return (default, version_text) else: version_pieces = tuple(version_pieces) return (version_pieces >= min_version, version_text)
Example #8
Source File: redis_db_driver.py From dragonflow with Apache License 2.0 | 5 votes |
def populate_cluster(self): for node in self._configured_nodes: client = node.client try: slots = client.execute_command('CLUSTER', 'SLOTS') except exceptions.ConnectionError: LOG.exception('Error connecting to cluster node %s:%s', node.ip, node.port) continue except exceptions.ResponseError as e: if str(e).find('cluster support disabled') != -1: LOG.info('Using a single non-cluster node %s:%s', node.ip, node.port) self._nodes_by_host = node self._is_cluster = False return LOG.exception('Response error from node %s:%s') continue self._is_cluster = True for slot_info in slots: (range_begin, range_end, master_info) = slot_info[0:3] master = Node(*master_info) self._nodes_by_host[master.key] = master for slot in range(int(range_begin), int(range_end) + 1): self._nodes_by_slot[slot] = master if self.is_cluster_covered(): self._covered = True break if not self._covered: LOG.error('Redis cluster not covering slot space') for node in self._nodes_by_host.values(): LOG.info('Cluster node: %s:%s', node.ip, node.port)
Example #9
Source File: sentinel.py From Flask with Apache License 2.0 | 5 votes |
def discover_slaves(self, service_name): "Returns a list of alive slaves for service ``service_name``" for sentinel in self.sentinels: try: slaves = sentinel.sentinel_slaves(service_name) except (ConnectionError, ResponseError): continue slaves = self.filter_slaves(slaves) if slaves: return slaves return []
Example #10
Source File: types.py From zyredis with MIT License | 5 votes |
def __setitem__(self, index, value): """``x.__setitem__(index, value) <==> x[index] = value``""" try: self.client.lset(self.name, index, value) except ResponseError, exc: if "index out of range" in exc.args: raise IndexError("list assignment index out of range") raise
Example #11
Source File: client.py From zyredis with MIT License | 5 votes |
def rename(self, old_name, new_name): """重命名redis的key Args: old_name: 旧版本key new_name: 新key Returns: False: 如果key不存在 True: key存在并且设置成功 """ try: self.api.rename(mkey(old_name), mkey(new_name)) return True except ResponseError as exc: LOG.error("zyredis rename error, error info=%s", exc) return False
Example #12
Source File: 0002_store_all_tags.py From canvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def forwards(self, orm): "Write your forwards methods here." for comment in Comment.all_objects.all(): print comment.tags.smembers() tags = comment.tags.smembers() if len(tags) > 0: try: all_tags.sadd(*tags) except ResponseError: pass
Example #13
Source File: test.py From redisai-py with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_dagrun_with_load(self): con = self.get_client() con.tensorset('a', [2, 3, 2, 3], shape=(2, 2), dtype='float') dag = con.dag(load='a') dag.tensorset('b', [2, 3, 2, 3], shape=(2, 2), dtype='float') dag.modelrun("pt_model", ["a", "b"], ["output"]) dag.tensorget('output') result = dag.run() expected = ['OK', 'OK', np.array([[4., 6.], [4., 6.]], dtype=np.float32)] self.assertTrue(np.allclose(expected.pop(), result.pop())) self.assertEqual(expected, result) self.assertRaises(ResponseError, con.tensorget, 'b')
Example #14
Source File: redis_db_driver.py From dragonflow with Apache License 2.0 | 5 votes |
def _key_command(self, command, key, *args): node = self._cluster.get_node(key) ask = False retry = 0 command_pcs = [command, key] command_pcs.extend(args) while retry < self.RETRY_COUNT: LOG.debug('Executing command "%s" (retry %s)', command_pcs, retry) if node is None: LOG.error('Error finding node for key %s in cluster', key) self._cluster.populate_cluster() try: if ask: node.client.execute_command('ASKING') ask = False return node.client.execute_command(*command_pcs) except exceptions.ResponseError as e: (reason, slot, ip_port) = str(e).split(' ') (ip, port) = ip_port.split(':') if reason == 'MOVED': self._cluster.populate_cluster() node = self._cluster.get_node(key) if reason == 'ASK': node = self._cluster.get_node_by_host(ip, port) ask = True except exceptions.ConnectionError as e: LOG.exception('Connection to node %s:%s failed, refreshing', node.ip, node.port) self._cluster.populate_cluster() node = self._cluster.get_node(key) retry += 1 raise df_exceptions.DBKeyNotFound(key=key)
Example #15
Source File: test_cluster.py From rb with Apache License 2.0 | 5 votes |
def test_routing_client_releases_connection_on_error(cluster): client = cluster.get_routing_client() with pytest.raises(ResponseError): client.sadd('key') host = cluster.get_router().get_host_for_command('sadd', ['key']) pool = cluster.get_pool_for_host(host) assert len(pool._available_connections) == pool._created_connections
Example #16
Source File: containers.py From walrus with MIT License | 5 votes |
def create(self, ensure_keys_exist=True, mkstream=False): """ Create the consumer group and register it with the group's stream keys. :param ensure_keys_exist: Ensure that the streams exist before creating the consumer group. Streams that do not exist will be created. :param mkstream: Use the "MKSTREAM" option to ensure stream exists (may require unstable version of Redis). """ if ensure_keys_exist: for key in self.keys: if not self.database.exists(key): msg_id = self.database.xadd(key, {'': ''}, id=b'0-1') self.database.xdel(key, msg_id) elif self.database.type(key) != b'stream': raise ValueError('Consumer group key "%s" exists and is ' 'not a stream. To prevent data-loss ' 'this key will not be deleted.' % key) resp = {} # Mapping of key -> last-read message ID. for key, value in self.keys.items(): try: resp[key] = self.database.xgroup_create(key, self.name, value, mkstream) except ResponseError as exc: if exception_message(exc).startswith('BUSYGROUP'): resp[key] = False else: raise return resp
Example #17
Source File: sentinel.py From gimel with MIT License | 5 votes |
def discover_slaves(self, service_name): "Returns a list of alive slaves for service ``service_name``" for sentinel in self.sentinels: try: slaves = sentinel.sentinel_slaves(service_name) except (ConnectionError, ResponseError): continue slaves = self.filter_slaves(slaves) if slaves: return slaves return []
Example #18
Source File: ValueString.py From redis-memory-analyzer with MIT License | 5 votes |
def get_int_encoded_bytes(redis, key_name): try: num_value = int(redis.get(key_name)) if num_value < REDIS_SHARED_INTEGERS: return 0 else: return size_of_pointer_fn() except ValueError: pass except ResponseError: pass except TypeError: pass return size_of_pointer_fn()
Example #19
Source File: sentinel.py From satori with Apache License 2.0 | 5 votes |
def discover_slaves(self, service_name): "Returns a list of alive slaves for service ``service_name``" for sentinel in self.sentinels: try: slaves = sentinel.sentinel_slaves(service_name) except (ConnectionError, ResponseError): continue slaves = self.filter_slaves(slaves) if slaves: return slaves return []
Example #20
Source File: test_cluster.py From rb with Apache License 2.0 | 5 votes |
def test_managed_mapping_client_releases_connection_on_error(cluster): with pytest.raises(ResponseError): with cluster.get_routing_client().map() as client: client.sadd('key') host = cluster.get_router().get_host_for_command('sadd', ['key']) pool = cluster.get_pool_for_host(host) assert len(pool._available_connections) == pool._created_connections
Example #21
Source File: test_cluster.py From rb with Apache License 2.0 | 5 votes |
def test_mapping_client_releases_connection_on_error(cluster): client = cluster.get_routing_client().get_mapping_client() client.sadd('key') with pytest.raises(ResponseError): client.join() host = cluster.get_router().get_host_for_command('sadd', ['key']) pool = cluster.get_pool_for_host(host) assert len(pool._available_connections) == pool._created_connections
Example #22
Source File: test.py From redisai-py with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_run_tf_model(self): model_path = os.path.join(MODEL_DIR, 'graph.pb') bad_model_path = os.path.join(MODEL_DIR, 'pt-minimal.pt') model_pb = load_model(model_path) wrong_model_pb = load_model(bad_model_path) con = self.get_client() con.modelset('m', 'tf', 'cpu', model_pb, inputs=['a', 'b'], outputs=['mul'], tag='v1.0') con.modeldel('m') self.assertRaises(ResponseError, con.modelget, 'm') con.modelset('m', 'tf', 'cpu', model_pb, inputs=['a', 'b'], outputs='mul', tag='v1.0') # wrong model self.assertRaises(ResponseError, con.modelset, 'm', 'tf', 'cpu', wrong_model_pb, inputs=['a', 'b'], outputs=['mul']) # missing inputs/outputs self.assertRaises(ValueError, con.modelset, 'm', 'tf', 'cpu', wrong_model_pb) # wrong backend self.assertRaises(ResponseError, con.modelset, 'm', 'torch', 'cpu', model_pb, inputs=['a', 'b'], outputs=['mul']) con.tensorset('a', (2, 3), dtype='float') con.tensorset('b', (2, 3), dtype='float') con.modelrun('m', ['a', 'b'], ['c']) tensor = con.tensorget('c') self.assertTrue(np.allclose([4, 9], tensor)) model_det = con.modelget('m') self.assertTrue(model_det['backend'] == 'TF') self.assertTrue(model_det['device'] == 'cpu') # TODO; RedisAI returns small letter self.assertTrue(model_det['tag'] == 'v1.0') con.modeldel('m') self.assertRaises(ResponseError, con.modelget, 'm')