@SuppressWarnings("unchecked") private BytesKeyObjectMap<byte[]> _gethash(byte[] key0, boolean create) throws RedisException { Object o = _get(key0); if (o == null) { o = new BytesKeyObjectMap(); if (create) { data.put(key0, o); } } if (!(o instanceof HashMap)) { throw invalidValue(); } return (BytesKeyObjectMap<byte[]>) o; }
public ZSetEntry get(byte[] member2) { return map.get(member2); }
@Override public boolean containsKey(Object o) { return containsKey(makeKey(o)); }
/** * Set the value of a hash field, only if the field does not exist * Hash * * @param key0 * @param field1 * @param value2 * @return IntegerReply */ @Override public IntegerReply hsetnx(byte[] key0, byte[] field1, byte[] value2) throws RedisException { BytesKeyObjectMap<byte[]> hash = _gethash(key0, true); byte[] bytes = hash.get(field1); if (bytes == null) { hash.put(field1, value2); return integer(1); } else { return integer(0); } }
public boolean add(BytesKey key, double score) { ZSetEntry current = map.get(key); if (current != null) { map.remove(key); int index = Collections.binarySearch(list, current); list.remove(index); } ZSetEntry entry = new ZSetEntry(key, score); map.put(key, entry); int index = find(Collections.binarySearch(list, entry)); list.add(index, entry); return current == null; }
/** * Delete a key * Generic * * @param key0 * @return IntegerReply */ @Override public IntegerReply del(byte[][] key0) throws RedisException { int total = 0; for (byte[] bytes : key0) { Object remove = data.remove(bytes); if (remove != null) { total++; } expires.remove(bytes); } return integer(total); }
/** * Get all the fields in a hash * Hash * * @param key0 * @return MultiBulkReply */ @Override public MultiBulkReply hkeys(byte[] key0) throws RedisException { BytesKeyObjectMap<byte[]> hash = _gethash(key0, false); int size = hash.size(); Reply[] replies = new Reply[size]; int i = 0; for (Object hkey : hash.keySet()) { replies[i++] = new BulkReply(((BytesKey) hkey).getBytes()); } return new MultiBulkReply(replies); }
/** * Get all the fields and values in a hash * Hash * * @param key0 * @return MultiBulkReply */ @Override public MultiBulkReply hgetall(byte[] key0) throws RedisException { BytesKeyObjectMap<byte[]> hash = _gethash(key0, false); int size = hash.size(); Reply[] replies = new Reply[size * 2]; int i = 0; for (Map.Entry<Object, byte[]> entry : hash.entrySet()) { replies[i++] = new BulkReply(((BytesKey) entry.getKey()).getBytes()); replies[i++] = new BulkReply(entry.getValue()); } return new MultiBulkReply(replies); }
private BytesKeyObjectMap<ZSetEntry> getMap() { if (map == null) { map = new BytesKeyObjectMap<ZSetEntry>(); } return map; }
/** * Remove all keys from the current database * Server * * @return StatusReply */ @Override public StatusReply flushdb() throws RedisException { data.clear(); return OK; }
public ZSet(ZSet destination) { map.putAll(destination.map); list.addAll(destination.list); }
public boolean containsKey(byte[] bytes) { return containsKey(new BytesKey(bytes)); }