@Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { Record record; if (fields != null) { record = client.get(readPolicy, new Key(namespace, table, key), fields.toArray(new String[fields.size()])); } else { record = client.get(readPolicy, new Key(namespace, table, key)); } if (record == null) { System.err.println("Record key " + key + " not found (read)"); return Status.ERROR; } for (Map.Entry<String, Object> entry: record.bins.entrySet()) { result.put(entry.getKey(), new ByteArrayByteIterator((byte[])entry.getValue())); } return Status.OK; } catch (AerospikeException e) { System.err.println("Error while reading key " + key + ": " + e); return Status.ERROR; } }
@Override protected void get(Key key, String binName) { if (useLatency) { begin = System.nanoTime(); } client.get(eventLoop, recordListener, args.readPolicy, key, binName); }
@Override protected void get(Key key) throws AerospikeException { if (useLatency) { begin = System.nanoTime(); } client.get(eventLoop, recordListener, args.readPolicy, key); }
@Override protected void get(Key[] keys, String binName) throws AerospikeException { if (useLatency) { begin = System.nanoTime(); } client.get(eventLoop, recordArrayListener, args.batchPolicy, keys, binName); }
@Override protected void get(Key[] keys) throws AerospikeException { if (useLatency) { begin = System.nanoTime(); } client.get(eventLoop, recordArrayListener, args.batchPolicy, keys); }
@SuppressWarnings("unchecked") @Override public <T> T get(Object key, Class<T> type) { return (T) client.get(null, getKey(key)); }
@Override protected void get(Key key, String binName) { Record record; if (counters.read.latency != null) { long begin = System.nanoTime(); record = client.get(args.readPolicy, key, binName); long elapsed = System.nanoTime() - begin; counters.read.latency.add(elapsed); } else { record = client.get(args.readPolicy, key, binName); } processRead(key, record); }
@Override protected void get(Key key) { Record record; if (counters.read.latency != null) { long begin = System.nanoTime(); record = client.get(args.readPolicy, key); long elapsed = System.nanoTime() - begin; counters.read.latency.add(elapsed); } else { record = client.get(args.readPolicy, key); } processRead(key, record); }
@Override protected void get(Key[] keys, String binName) { Record[] records; if (counters.read.latency != null) { long begin = System.nanoTime(); records = client.get(args.batchPolicy, keys, binName); long elapsed = System.nanoTime() - begin; counters.read.latency.add(elapsed); } else { records = client.get(args.batchPolicy, keys, binName); } if (records == null) { System.out.println("Batch records returned is null"); } processBatchRead(); }
/** * Does the key exist in the member * @param key Object. The key we are looking for. * @return Boolean. Returns the object if the object exists in the membership, otherwise returns null. */ @Override public Object query(Object tkey) { if (client == null) { if (tree.contains(tkey)) return tkey; } else { Record record = client.get(null, key); Set<String> receivedList = (Set<String>) record.getValue(name); return receivedList.contains(tkey); } return null; }
@Override protected void get(Key[] keys) { Record[] records; if (counters.read.latency != null) { long begin = System.nanoTime(); records = client.get(args.batchPolicy, keys); long elapsed = System.nanoTime() - begin; counters.read.latency.add(elapsed); } else { records = client.get(args.batchPolicy, keys); } if (records == null) { System.out.println("Batch records returned is null"); } processBatchRead(); } }
public static void main(String args[]) throws Exception { AerospikeClient client = new AerospikeClient(args[0], 3000); String skey = "accountingsystem"; Key key = new Key("test", "cache", skey); while(true) { Record record = null; record = client.get(null, key); String value = (String)record.bins.get("value"); System.out.println(value); Thread.sleep(1000); } } }
/** * Given a key, return the string value. * @param skey String. * @return String. The value of the key. */ public Object get(String set, String skey) throws Exception { Key key = new Key("test", set, skey); Record record = null; record = ae.getClient().get(null, key); if (record == null) { return null; } return record.bins.get("value"); }
@Override public Object get(Serializable id, Serializable keyspace) { Key key = makeKey(keyspace.toString(), id.toString()); Record record = client.get(null, key); if(record == null){ return null; } AerospikeReadData data = AerospikeReadData.forRead(key, record); return converter.read(Object.class, data); }
@Override public ValueWrapper get(Object key) { Record record = client.get(null, getKey(key)); ValueWrapper vr = toWrapper(record); return vr; }
public void onSuccess(final Key key) { try { // Write succeeded. Now call read. console.info("Get inline: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey); client.get(eventLoop, new RecordListener() { public void onSuccess(final Key key, final Record record) { validateBin(key, bin, record, "inline"); } public void onFailure(AerospikeException e) { console.error("Failed to get: namespace=%s set=%s key=%s exception=%s", key.namespace, key.setName, key.userKey, e.getMessage()); } }, policy, key); } catch (Exception e) { console.error("Failed to get: namespace=%s set=%s key=%s exception=%s", key.namespace, key.setName, key.userKey, e.getMessage()); } }
public void onSuccess(Key key) { try { // Write succeeded. Now call read. console.info("Get with retry: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey); client.get(eventLoop, new ReadHandler(client, eventLoop, key, bin), policy, key); } catch (Exception e) { console.error("Failed to get: namespace=%s set=%s key=%s exception=%s", key.namespace, key.setName, key.userKey, e.getMessage()); } }
@Override public <T> T get(Object key, Class<T> type) { Key dbKey = getKey(key); Record record = client.get(null, dbKey); if (record != null) { AerospikeReadData data = AerospikeReadData.forRead(dbKey, record); T value = aerospikeConverter.read(type, data); return value; } return null; }
/** * Execute put and get on a server configured as single-bin. */ private void runSingleBinTest(AerospikeClient client, Parameters params) throws Exception { Key key = new Key(params.namespace, params.set, "putgetkey"); Bin bin = new Bin("", "value"); console.info("Single Bin Put: namespace=%s set=%s key=%s value=%s", key.namespace, key.setName, key.userKey, bin.value); client.put(params.writePolicy, key, bin); console.info("Single Bin Get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey); Record record = client.get(params.policy, key); if (record == null) { throw new Exception(String.format( "Failed to get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey)); } validateBin(key, bin, record); }
private void writeUsingUdf(AerospikeClient client, Parameters params) throws Exception { Key key = new Key(params.namespace, params.set, "udfkey1"); Bin bin = new Bin(params.getBinName("udfbin1"), "string value"); client.execute(params.writePolicy, key, "record_example", "writeBin", Value.get(bin.name), bin.value); Record record = client.get(params.policy, key, bin.name); String expected = bin.value.toString(); String received = record.getString(bin.name); if (received != null && received.equals(expected)) { console.info("Data matched: namespace=%s set=%s key=%s bin=%s value=%s", key.namespace, key.setName, key.userKey, bin.name, received); } else { console.error("Data mismatch: Expected %s. Received %s.", expected, received); } }