Java Code Examples for redis.clients.jedis.util.SafeEncoder#encode()
The following examples show how to use
redis.clients.jedis.util.SafeEncoder#encode() .
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: Client.java From JRediSearch with BSD 2-Clause "Simplified" License | 6 votes |
/** * Get runtime configuration option value * * @param option the name of the configuration option * @return */ @Override public String getConfig(ConfigOption option) { try (Jedis conn = _conn()) { List<Object> objects = sendCommand(conn, commands.getConfigCommand(), Keywords.GET.getRaw(), option.getRaw()) .getObjectMultiBulkReply(); if (objects != null && !objects.isEmpty()) { List<byte[]> kvs = (List<byte[]>) objects.get(0); byte[] val = kvs.get(1); return val == null ? null : SafeEncoder.encode(val); } } return null; }
Example 2
Source File: ContextedRedisGraph.java From JRedisGraph with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Deletes the entire graph * @param graphId graph to delete * @return delete running time statistics */ @Override public String deleteGraph(String graphId) { Jedis conn = getConnection(); Object response; try { response = conn.sendCommand(RedisGraphCommand.DELETE, graphId); } catch (Exception e) { conn.close(); throw e; } //clear local state caches.removeGraphCache(graphId); return SafeEncoder.encode((byte[]) response); }
Example 3
Source File: JReJSON.java From JRedisJSON with BSD 2-Clause "Simplified" License | 6 votes |
/** * Gets an object * @param key the key name * @param clazz * @param paths optional one ore more paths in the object * @return the requested object */ public <T> T get(String key, Class<T> clazz, Path... paths) { byte[][] args = new byte[1 + paths.length][]; int i=0; args[i] = SafeEncoder.encode(key); for (Path p :paths) { args[++i] = SafeEncoder.encode(p.toString()); } String rep; try (Jedis conn = getConnection()) { conn.getClient().sendCommand(Command.GET, args); rep = conn.getClient().getBulkReply(); } assertReplyNotError(rep); return gson.fromJson(rep, clazz); }
Example 4
Source File: ResultSetImpl.java From JRedisGraph with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param rawScalarData - a list of object. list[0] is the scalar type, list[1] is the scalar value * @return value of the specific scalar type */ private Object deserializeScalar(List<Object> rawScalarData) { ResultSetScalarTypes type = getValueTypeFromObject(rawScalarData.get(0)); Object obj = rawScalarData.get(1); switch (type) { case VALUE_NULL: return null; case VALUE_BOOLEAN: return Boolean.parseBoolean(SafeEncoder.encode((byte[]) obj)); case VALUE_DOUBLE: return Double.parseDouble(SafeEncoder.encode((byte[]) obj)); case VALUE_INTEGER: return (Long) obj; case VALUE_STRING: return SafeEncoder.encode((byte[]) obj); case VALUE_ARRAY: return deserializeArray(obj); case VALUE_NODE: return deserializeNode((List<Object>) obj); case VALUE_EDGE: return deserializeEdge((List<Object>) obj); case VALUE_PATH: return deserializePath(obj); case VALUE_UNKNOWN: default: return obj; } }
Example 5
Source File: Client.java From JRediSearch with BSD 2-Clause "Simplified" License | 5 votes |
/** * Get a documents from the index * * @param docIds The document IDs to retrieve * @param decode <code>false</code> - keeps the fields value as byte[] * @return The document as stored in the index. If the document does not exist, null is returned. */ @Override public List<Document> getDocuments(boolean decode, String ...docIds) { int len = docIds.length; if(len == 0) { return new ArrayList<>(0); } byte[][] args = new byte[docIds.length+1][]; args[0] = endocdedIndexName; for(int i=0 ; i<len ; ++i) { args[i+1] = SafeEncoder.encode(docIds[i]); } List<Document> documents = new ArrayList<>(len); try (Jedis conn = _conn()) { List<Object> res = sendCommand(conn, commands.getMGetCommand(), args).getObjectMultiBulkReply(); for(int i=0; i<len; ++i) { List<Object> line = (List<Object>)res.get(i); if (line == null) { documents.add(null); } else { Document doc = new Document(docIds[i]); handleListMapping(line, doc::set, decode); documents.add(doc); } } return documents; } }
Example 6
Source File: Client.java From JRediSearch with BSD 2-Clause "Simplified" License | 5 votes |
private static void handleListMapping(List<Object> items, KVHandler handler, boolean decode) { for (int i = 0; i < items.size(); i += 2) { String key = SafeEncoder.encode((byte[]) items.get(i)); Object val = items.get(i + 1); if (decode && val instanceof byte[]) { val = SafeEncoder.encode((byte[]) val); } handler.apply(key, val); } }
Example 7
Source File: Client.java From JRediSearch with BSD 2-Clause "Simplified" License | 5 votes |
/** * Create a new client to a RediSearch index * * @param indexName the name of the index we are connecting to or creating * @param pool jedis connection pool to be used */ public Client(String indexName, Pool<Jedis> pool) { this.indexName = indexName; this.endocdedIndexName = SafeEncoder.encode(indexName); this.pool = pool; this.commands = new Commands.SingleNodeCommands(); }
Example 8
Source File: Query.java From JRediSearch with BSD 2-Clause "Simplified" License | 5 votes |
private byte[] formatNum(double num, boolean exclude) { if (num == Double.POSITIVE_INFINITY) { return Keywords.POSITIVE_INFINITY.getRaw(); } if (num == Double.NEGATIVE_INFINITY) { return Keywords.NEGATIVE_INFINITY.getRaw(); } return exclude ? SafeEncoder.encode("(" + num) : Protocol.toByteArray(num); }
Example 9
Source File: Document.java From JRediSearch with BSD 2-Clause "Simplified" License | 5 votes |
/** * return the property value inside a key * * @param key key of the property * * @return the property value */ public String getString(String key) { Object value = properties.get(key); if(value instanceof String) { return (String)value; } return value instanceof byte[] ? SafeEncoder.encode((byte[])value) : value.toString(); }
Example 10
Source File: RedisGraph.java From JRedisGraph with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Deletes the entire graph * @param graphId graph to delete * @return delete running time statistics */ @Override public String deleteGraph(String graphId) { try (Jedis conn = getConnection()) { Object response = conn.sendCommand(RedisGraphCommand.DELETE, graphId); //clear local state caches.removeGraphCache(graphId); return SafeEncoder.encode((byte[]) response); } }
Example 11
Source File: HeaderImpl.java From JRedisGraph with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Extracts schema names and types from the raw representation */ private void buildSchema() { for (List<Object> tuple : this.raw) { //get type ResultSetColumnTypes type = ResultSetColumnTypes.values()[((Long) tuple.get(0)).intValue()]; //get text String text = SafeEncoder.encode((byte[]) tuple.get(1)); if (type != null) { schemaTypes.add(type); schemaNames.add(text); } } }
Example 12
Source File: StatisticsImpl.java From JRedisGraph with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Map<Statistics.Label, String> getStatistics(){ if(statistics.size() == 0) { for(byte[] tuple : this.raw) { String text = SafeEncoder.encode(tuple); String[] rowTuple = text.split(":"); if(rowTuple.length == 2) { Statistics.Label label = Statistics.Label.getEnum(rowTuple[0]); if(label != null) { this.statistics.put( label, rowTuple[1].trim()); } } } } return statistics; }
Example 13
Source File: JedisGenericOperation.java From dyno with Apache License 2.0 | 4 votes |
public JedisGenericOperation(String key, String opName) { this.stringKey = key; this.binaryKey = SafeEncoder.encode(key); this.name = opName; }
Example 14
Source File: JReJSON.java From JRedisJSON with BSD 2-Clause "Simplified" License | 4 votes |
ExistenceModifier(String alt) { raw = SafeEncoder.encode(alt); }
Example 15
Source File: Commands.java From JRediSearch with BSD 2-Clause "Simplified" License | 4 votes |
Command(String alt) { raw = SafeEncoder.encode(alt); }
Example 16
Source File: Commands.java From JRediSearch with BSD 2-Clause "Simplified" License | 4 votes |
ClusterCommand(String alt) { raw = SafeEncoder.encode(alt); }
Example 17
Source File: JReJSON.java From JRedisJSON with BSD 2-Clause "Simplified" License | 4 votes |
Command(String alt) { raw = SafeEncoder.encode(alt); }
Example 18
Source File: AutoCompleter.java From JRediSearch with BSD 2-Clause "Simplified" License | 4 votes |
Command(String alt) { raw = SafeEncoder.encode(alt); }
Example 19
Source File: Client.java From JRedisBloom with BSD 2-Clause "Simplified" License | 4 votes |
private Connection sendCommand(Jedis conn, String key, ProtocolCommand command, String ...args) { byte[][] fullArgs = new byte[args.length + 1][]; fullArgs[0] = SafeEncoder.encode(key); System.arraycopy( SafeEncoder.encodeMany(args), 0, fullArgs, 1, args.length); return sendCommand(conn, command, fullArgs); }
Example 20
Source File: JedisClusterPipeline.java From AutoLoadCache with Apache License 2.0 | 4 votes |
@Override protected Client getClient(String key) { byte[] bKey = SafeEncoder.encode(key); return getClient(bKey); }