redis.clients.jedis.exceptions.JedisDataException Java Examples
The following examples show how to use
redis.clients.jedis.exceptions.JedisDataException.
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 check out the related API usage on the sidebar.
Example #1
Source File: RedisDataSet.java From jmeter-plugins with Apache License 2.0 | 6 votes |
private void addDataToConnection(Jedis conn, String key, String data) { try { if (redisDataType == RedisDataType.REDIS_DATA_TYPE_LIST) { log.debug("Executing rpush against redis list"); // Add data string to list's tail conn.rpush(redisKey, data); } else if (redisDataType == RedisDataType.REDIS_DATA_TYPE_SET) { log.debug("Executing sadd against redis set"); conn.sadd(key, data); } else { log.warn("Unexpected redis datatype: {0}".format(key)); } } catch (JedisDataException jde) { log.error("Exception when adding data to Redis: " + jde); } }
Example #2
Source File: ClientTest.java From JRediSearch with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testLanguage() throws Exception { Client cl = getClient(); Schema sc = new Schema().addTextField("text", 1.0); cl.createIndex(sc, Client.IndexOptions.defaultOptions()); Document d = new Document("doc1").set("text", "hello"); AddOptions options = new AddOptions().setLanguage("spanish"); assertTrue(cl.addDocument(d, options)); boolean caught = false; options.setLanguage("ybreski"); cl.deleteDocument(d.getId()); try { cl.addDocument(d, options); } catch (JedisDataException t) { caught = true; } assertTrue(caught); }
Example #3
Source File: Client.java From JRediSearch with BSD 2-Clause "Simplified" License | 6 votes |
/** * Add a batch of documents to the index * @param options Options for the operation * @param docs The documents to add * @return true on success for each document */ @Override public boolean[] addDocuments(AddOptions options, Document... docs){ try (Jedis conn = _conn()) { for(Document doc : docs) { addDocument(doc, options, conn); } List<Object> objects = conn.getClient().getMany(docs.length); boolean[] results = new boolean[docs.length]; int i=0; for(Object obj : objects) { results[i++] = !(obj instanceof JedisDataException) && SafeEncoder.encode((byte[]) obj).equals("OK"); } return results; } }
Example #4
Source File: Transaction.java From cachecloud with Apache License 2.0 | 6 votes |
public List<Object> exec() { // Discard QUEUED or ERROR client.getMany(getPipelinedResponseLength()); client.exec(); inTransaction = false; List<Object> unformatted = client.getObjectMultiBulkReply(); if (unformatted == null) { return null; } List<Object> formatted = new ArrayList<Object>(); for (Object o : unformatted) { try { formatted.add(generateResponse(o).get()); } catch (JedisDataException e) { formatted.add(e); } } return formatted; }
Example #5
Source File: Protocol.java From cachecloud with Apache License 2.0 | 6 votes |
private static void processError(final RedisInputStream is) { String message = is.readLine(); // TODO: I'm not sure if this is the best way to do this. // Maybe Read only first 5 bytes instead? if (message.startsWith(MOVED_RESPONSE)) { String[] movedInfo = parseTargetHostAndSlot(message); throw new JedisMovedDataException(message, new HostAndPort(movedInfo[1], Integer.valueOf(movedInfo[2])), Integer.valueOf(movedInfo[0])); } else if (message.startsWith(ASK_RESPONSE)) { String[] askInfo = parseTargetHostAndSlot(message); throw new JedisAskDataException(message, new HostAndPort(askInfo[1], Integer.valueOf(askInfo[2])), Integer.valueOf(askInfo[0])); } else if (message.startsWith(CLUSTERDOWN_RESPONSE)) { throw new JedisClusterException(message); } throw new JedisDataException(message); }
Example #6
Source File: RedisProtocolTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void testWrongAuthRedis() { String password = "1234567"; this.registryUrl = this.registryUrl.setPassword(password); Invoker<IDemoService> refer = protocol.refer(IDemoService.class, registryUrl .addParameter("max.idle", 10) .addParameter("max.active", 20)); IDemoService demoService = this.proxy.getProxy(refer); try { String value = demoService.get("key"); assertThat(value, is(nullValue())); } catch (RpcException e) { if (e.getCause() instanceof JedisConnectionException && e.getCause().getCause() instanceof JedisDataException) { Assert.assertEquals("ERR invalid password" , e.getCause().getCause().getMessage()); } else { Assert.fail("no invalid password exception!"); } } refer.destroy(); }
Example #7
Source File: Response.java From cachecloud with Apache License 2.0 | 6 votes |
public T get() { // if response has dependency response and dependency is not built, // build it first and no more!! if (dependency != null && dependency.set && !dependency.built) { dependency.build(); } if (!set) { throw new JedisDataException( "Please close pipeline or multi block before calling this method."); } if (!built) { build(); } if (exception != null) { throw exception; } return response; }
Example #8
Source File: Response.java From cachecloud with Apache License 2.0 | 6 votes |
private void build() { // check build state to prevent recursion if (building) { return; } building = true; try { if (data != null) { if (data instanceof JedisDataException) { exception = (JedisDataException) data; } else { response = builder.build(data); } } data = null; } finally { building = false; built = true; } }
Example #9
Source File: Pipeline.java From cachecloud with Apache License 2.0 | 6 votes |
@Override public List<Object> build(Object data) { @SuppressWarnings("unchecked") List<Object> list = (List<Object>) data; List<Object> values = new ArrayList<Object>(); if (list.size() != responses.size()) { throw new JedisDataException("Expected data size " + responses.size() + " but was " + list.size()); } for (int i = 0; i < list.size(); i++) { Response<?> response = responses.get(i); response.set(list.get(i)); Object builtResponse; try { builtResponse = response.get(); } catch (JedisDataException e) { builtResponse = e; } values.add(builtResponse); } return values; }
Example #10
Source File: Pipeline.java From cachecloud with Apache License 2.0 | 6 votes |
/** * Synchronize pipeline by reading all responses. This operation close the pipeline. Whenever * possible try to avoid using this version and use Pipeline.sync() as it won't go through all the * responses and generate the right response type (usually it is a waste of time). * @return A list of all the responses in the order you executed them. */ public List<Object> syncAndReturnAll() { if (getPipelinedResponseLength() > 0) { List<Object> unformatted = client.getMany(getPipelinedResponseLength()); List<Object> formatted = new ArrayList<Object>(); for (Object o : unformatted) { try { formatted.add(generateResponse(o).get()); } catch (JedisDataException e) { formatted.add(e); } } return formatted; } else { return java.util.Collections.<Object> emptyList(); } }
Example #11
Source File: TransactionCommandsTest.java From cachecloud with Apache License 2.0 | 6 votes |
@Test public void execGetResponse() { Transaction t = jedis.multi(); t.set("foo", "bar"); t.smembers("foo"); t.get("foo"); List<Response<?>> lr = t.execGetResponse(); try { lr.get(1).get(); fail("We expect exception here!"); } catch (JedisDataException e) { // that is fine we should be here } assertEquals("bar", lr.get(2).get()); }
Example #12
Source File: TransactionCommandsTest.java From cachecloud with Apache License 2.0 | 6 votes |
@Test public void testCloseable() throws IOException { // we need to test with fresh instance of Jedis Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500); jedis2.auth("foobared"); Transaction transaction = jedis2.multi(); transaction.set("a", "1"); transaction.set("b", "2"); transaction.close(); try { transaction.exec(); fail("close should discard transaction"); } catch (JedisDataException e) { assertTrue(e.getMessage().contains("EXEC without MULTI")); // pass } }
Example #13
Source File: JedisSentinelTest.java From cachecloud with Apache License 2.0 | 6 votes |
@Test public void sentinelMonitor() { Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); try { // monitor new master String result = j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, master.getPort(), 1); assertEquals("OK", result); // already monitored try { j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, master.getPort(), 1); fail(); } catch (JedisDataException e) { // pass } } finally { j.close(); } }
Example #14
Source File: TransactionCommandsTest.java From cachecloud with Apache License 2.0 | 6 votes |
@Test public void transactionResponseWithError() { Transaction t = jedis.multi(); t.set("foo", "bar"); Response<Set<String>> error = t.smembers("foo"); Response<String> r = t.get("foo"); List<Object> l = t.exec(); assertEquals(JedisDataException.class, l.get(1).getClass()); try { error.get(); fail("We expect exception here!"); } catch (JedisDataException e) { // that is fine we should be here } assertEquals(r.get(), "bar"); }
Example #15
Source File: JedisSentinelTest.java From cachecloud with Apache License 2.0 | 6 votes |
@Test public void sentinelRemove() { Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); try { ensureMonitored(sentinel, REMOVE_MASTER_NAME, MASTER_IP, master.getPort(), 1); String result = j.sentinelRemove(REMOVE_MASTER_NAME); assertEquals("OK", result); // not exist try { result = j.sentinelRemove(REMOVE_MASTER_NAME); assertNotEquals("OK", result); fail(); } catch (JedisDataException e) { // pass } } finally { j.close(); } }
Example #16
Source File: RedisAuthenticationIntegrationTest.java From dyno with Apache License 2.0 | 6 votes |
@Test public void testJedisConnFactory_authenticationRequired() throws Exception { redisServer = new RedisServerBuilder() .port(REDIS_PORT) .setting("requirepass password") .build(); redisServer.start(); Host noAuthHost = new HostBuilder().setHostname("localhost").setPort(REDIS_PORT).setRack(REDIS_RACK).setStatus(Status.Up).createHost(); JedisConnectionFactory conFactory = new JedisConnectionFactory(new DynoOPMonitor("some-application-name"), null); ConnectionPoolConfiguration cpConfig = new ConnectionPoolConfigurationImpl("some-name"); CountingConnectionPoolMonitor poolMonitor = new CountingConnectionPoolMonitor(); HostConnectionPool<Jedis> hostConnectionPool = new HostConnectionPoolImpl<>(noAuthHost, conFactory, cpConfig, poolMonitor); Connection<Jedis> connection = conFactory .createConnection(hostConnectionPool); try { connection.execPing(); Assert.fail("expected to throw"); } catch (JedisDataException e) { Assert.assertEquals("NOAUTH Authentication required.", e.getMessage()); } }
Example #17
Source File: LuaManager.java From RedisBungee with Eclipse Public License 1.0 | 6 votes |
public Object eval(List<String> keys, List<String> args) { Object data; try (Jedis jedis = plugin.getPool().getResource()) { try { data = jedis.evalsha(hashed, keys, args); } catch (JedisDataException e) { if (e.getMessage().startsWith("NOSCRIPT")) { data = jedis.eval(script, keys, args); } else { throw e; } } } return data; }
Example #18
Source File: RedisDataSet.java From jmeter-plugins with Apache License 2.0 | 6 votes |
private String getDataFromConnection(Jedis conn, String key) { String line = null; try { if (redisDataType == RedisDataType.REDIS_DATA_TYPE_LIST) { log.debug("Executing lpop against redis list"); // Get data from list's head line = conn.lpop(key); } else if (redisDataType.equals(RedisDataType.REDIS_DATA_TYPE_SET)) { log.debug("Executing spop against redis set"); line = conn.spop(key); } else { log.warn("Unexpected redis datatype: {0}".format(key)); } } catch (JedisDataException jde) { log.error("Exception when retrieving data from Redis: " + jde); } return line; }
Example #19
Source File: ResultSetImpl.java From JRedisGraph with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @param rawResponse the raw representation of response is at most 3 lists of objects. * The last list is the statistics list. * @param redisGraph, the graph local cache */ public ResultSetImpl(List<Object> rawResponse, RedisGraph redisGraph, GraphCache cache) { this.redisGraph = redisGraph; this.cache = cache; // If a run-time error occured, the last member of the rawResponse will be a JedisDataException. if (rawResponse.get(rawResponse.size()-1) instanceof JedisDataException) { throw new JRedisGraphRunTimeException((Throwable) rawResponse.get(rawResponse.size() - 1)); } if (rawResponse.size() != 3) { header = parseHeader(new ArrayList<>()); results = new ArrayList<>(); statistics = rawResponse.size()> 0 ? parseStatistics(rawResponse.get(rawResponse.size() - 1)) : parseStatistics(new ArrayList<Objects>()); } else { header = parseHeader((List<List<Object>>) rawResponse.get(0)); results = parseResult((List<List<Object>>) rawResponse.get(1)); statistics = parseStatistics(rawResponse.get(2)); } }
Example #20
Source File: RedisAuthenticationIntegrationTest.java From dyno with Apache License 2.0 | 5 votes |
@Test public void testJedisConnFactory_invalidPassword() throws Exception { redisServer = new RedisServerBuilder() .port(REDIS_PORT) .setting("requirepass password") .build(); redisServer.start(); Host authHost = new HostBuilder().setHostname("localhost").setPort(REDIS_PORT).setRack(REDIS_RACK).setStatus(Status.Up).setHashtag(null).setPassword("invalid-password").createHost(); JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(new DynoOPMonitor("some-application-name"), null); ConnectionPoolConfiguration connectionPoolConfiguration = new ConnectionPoolConfigurationImpl( "some-name"); HostConnectionPool<Jedis> hostConnectionPool = new HostConnectionPoolImpl<>(authHost, jedisConnectionFactory, connectionPoolConfiguration, new CountingConnectionPoolMonitor()); Connection<Jedis> connection = jedisConnectionFactory .createConnection(hostConnectionPool); try { connection.execPing(); Assert.fail("expected to throw"); } catch (JedisDataException e) { Assert.assertEquals("ERR invalid password", e.getMessage()); } }
Example #21
Source File: Client.java From JRediSearch with BSD 2-Clause "Simplified" License | 5 votes |
/** * Drop the index and associated keys, including documents * * @param missingOk If the index does not exist, don't throw an exception, but return false instead * @return True if the index was dropped, false if it did not exist (or some other error occurred). */ @Override public boolean dropIndex(boolean missingOk) { try (Jedis conn = _conn()) { String res = sendCommand(conn, commands.getDropCommand(), this.endocdedIndexName).getStatusCodeReply(); return res.equals("OK"); } catch (JedisDataException ex) { if (missingOk && ex.getMessage().toLowerCase().contains("unknown")) { return false; } throw ex; } }
Example #22
Source File: DefaultRedis.java From craft-atom with MIT License | 5 votes |
RedisException handleException(Exception e, Jedis j, Object... args) { unbind(); if (e instanceof JedisConnectionException) { return new RedisConnectionException(String.format("Connect to redis server<host=%s, port=%s> failed.", host, port), e); } if (e instanceof JedisDataException) { return new RedisDataException(String.format("Redis data <args=%s> process failed.", Arrays.toString(args)), e); } return new RedisException(e); }
Example #23
Source File: ClientTest.java From JRediSearch with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testPhoneticMatch() throws Exception { Client cl = getClient(); cl._conn().flushDB(); Schema sc = new Schema() .addTextField("noPhonetic", 1.0) .addField(new Schema.TextField("withPhonetic", 1.0, false, false, false, "dm:en")); assertTrue(cl.createIndex(sc, Client.IndexOptions.defaultOptions())); Map<String, Object> doc = new HashMap<>(); doc.put("noPhonetic", "morfix"); doc.put("withPhonetic", "morfix"); // Store it assertTrue(cl.addDocument("doc", doc)); // Query SearchResult res = cl.search(new Query("@withPhonetic:morphix=>{$phonetic:true}")); assertEquals(1, res.totalResults); try { cl.search(new Query("@noPhonetic:morphix=>{$phonetic:true}")); Assert.fail(); }catch( JedisDataException e) {/*field does not support phonetics*/} SearchResult res3 = cl.search(new Query("@withPhonetic:morphix=>{$phonetic:false}")); assertEquals(0, res3.totalResults); }
Example #24
Source File: PipeliningTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Test public void testCloseableWithMulti() throws IOException { // we need to test with fresh instance of Jedis Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500); jedis2.auth("foobared"); Pipeline pipeline = jedis2.pipelined(); Response<String> retFuture1 = pipeline.set("a", "1"); Response<String> retFuture2 = pipeline.set("b", "2"); pipeline.multi(); pipeline.set("a", "a"); pipeline.set("b", "b"); pipeline.close(); try { pipeline.exec(); fail("close should discard transaction"); } catch (JedisDataException e) { assertTrue(e.getMessage().contains("EXEC without MULTI")); // pass } // it shouldn't meet any exception retFuture1.get(); retFuture2.get(); }
Example #25
Source File: PipeliningTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Test(expected = JedisDataException.class) public void testJedisThowExceptionWhenInPipeline() { Pipeline pipeline = jedis.pipelined(); pipeline.set("foo", "3"); jedis.get("somekey"); fail("Can't use jedis instance when in Pipeline"); }
Example #26
Source File: PipeliningTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Test(expected = JedisDataException.class) public void pipelineMultiShoudThrowJedisDataExceptionWhenAlreadyInMulti() { Pipeline pipeline = jedis.pipelined(); pipeline.multi(); pipeline.set("foo", "3"); pipeline.multi(); }
Example #27
Source File: PipeliningTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Test public void piplineWithError() { Pipeline p = jedis.pipelined(); p.set("foo", "bar"); Response<Set<String>> error = p.smembers("foo"); Response<String> r = p.get("foo"); p.sync(); try { error.get(); fail(); } catch (JedisDataException e) { // that is fine we should be here } assertEquals(r.get(), "bar"); }
Example #28
Source File: PipeliningTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Test(expected = JedisDataException.class) public void pipelineResponseWithinPipeline() { jedis.set("string", "foo"); Pipeline p = jedis.pipelined(); Response<String> string = p.get("string"); string.get(); p.sync(); }
Example #29
Source File: BinaryJedis.java From cachecloud with Apache License 2.0 | 5 votes |
protected void checkIsInMultiOrPipeline() { if (client.isInMulti()) { throw new JedisDataException( "Cannot use Jedis when in Multi. Please use Transation or reset jedis state."); } else if (pipeline != null && pipeline.hasPipelinedResponse()) { throw new JedisDataException( "Cannot use Jedis when in Pipeline. Please use Pipeline or reset jedis state ."); } }
Example #30
Source File: ScriptingCommandsTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Test public void scriptKill() { try { jedis.scriptKill(); } catch (JedisDataException e) { assertTrue(e.getMessage().contains("No scripts in execution right now.")); } }