@Override protected void work() { try { for(int i=0; i<reqCnt; i++){ jredis.get("fixedbytes_"+id); } } catch (RedisException e) { e.printStackTrace(); } } };
private static void useMSetNX (JRedis jredis) { // Here we are using a mixed set of value types Map<String, byte[]> kvMap = new HashMap<String, byte[]>(); kvMap.put("foo", "bar".getBytes()); kvMap.put("cat", "meow".getBytes()); kvMap.put("dog", "woof".getBytes()); kvMap.put("bird", "whale fail".getBytes()); kvMap.put("pi", String.valueOf(3.141592653589793).getBytes()); try { jredis.flushdb(); jredis.set("bird", "tweet"); // <= force an error on msetnx boolean stat = jredis.msetnx(kvMap); if(!stat) { System.out.format("Couldn't msetnx - one of these already exists: %s\n", kvMap.keySet()); } // and now we can find out which one existed: for(String key : kvMap.keySet()){ if(jredis.exists(key)){ System.out.format("key '%s' [value: %s] already existed!\n", key, new String(jredis.get(key))); } } } catch (RedisException e) { e.printStackTrace(); } }
private void basicStuff () throws RedisException { jredis.flushdb(); String key = "foo" ; jredis.set(key, "bar"); String value = toStr(jredis.get(key)); System.out.format("%s => %s\n", key, value); }
@Override public void run() { final String wkey = "foo" + j; String wvalue = null; for(int i=0; i< opcnt; i++) { try { client.incr(wkey); wvalue = toStr(client.get(wkey)); } catch (RedisException e) { e.printStackTrace(); break; } } System.out.format("%s => %s\n", wkey, wvalue); } });
private void run(String password) { try { ConnectionSpec spec = DefaultConnectionSpec.newSpec().setCredentials(password); JRedis jredis = new JRedisClient(spec); jredis.ping(); if(!jredis.exists(bkey)) { jredis.set(bkey, "Hello Again!"); System.out.format("Hello! You should run me again!\n"); } else { String msg = toStr ( jredis.get(bkey) ); System.out.format("%s\n", msg); } jredis.quit(); } catch (RedisException e){ if (e.getCommand()==Command.PING){ System.out.format("I'll need that password! Try again with password as command line arg for this program.\n"); } } catch (ProviderException e){ System.out.format("Oh no, an 'un-documented feature': %s\nKindly report it.", e.getMessage()); } catch (ClientRuntimeException e){ System.out.format("%s\n", e.getMessage()); } } }