Package redis.clients.jedis

Examples of redis.clients.jedis.Pipeline$MultiResponseBuilder


    {
        Object connection = getConnection();
        // Create a hashset and populate data into it
        //

        Pipeline pipeLine = null;
        try
        {
            if (isBoundTransaction())
            {
                pipeLine = ((Jedis) connection).pipelined();
                onPersist(entityMetadata, entity, id, rlHolders, pipeLine);
            }
            else
            {
                onPersist(entityMetadata, entity, id, rlHolders, connection);

            }

        }
        finally
        {
            //
            if (pipeLine != null)
            {
                pipeLine.sync(); // send I/O.. as persist call. so no need to
                                 // read
            } // response?

            onCleanup(connection);
        }
View Full Code Here


     */
    @Override
    public void delete(Object entity, Object pKey)
    {
        Object connection = getConnection();
        Pipeline pipeLine = null;
        try
        {
            if (isBoundTransaction())
            {
                pipeLine = ((Jedis) connection).pipelined();
                onDelete(entity, pKey, pipeLine);
            }
            else
            {
                onDelete(entity, pKey, connection);
            }
        }
        finally
        {
            if (pipeLine != null)
            {
                pipeLine.sync();
            }
            onCleanup(connection);
        }
    }
View Full Code Here

        String inverseJoinColumn = joinTableData.getInverseJoinColumnName();
        String joinColumn = joinTableData.getJoinColumnName();

        Map<Object, Set<Object>> joinTableRecords = joinTableData.getJoinTableRecords();
        Object connection = null;
        Pipeline pipeline = null;
        /**
         * Example: join table : PERSON_ADDRESS join column : PERSON_ID (1_p)
         * inverse join column : ADDRESS_ID (1_a) store in REDIS:
         * PERSON_ADDRESS:1_p_1_a PERSON_ID 1_p ADDRESS_ID 1_a
         */
        // String rowKey =
        try
        {
            connection = getConnection();
            if (isBoundTransaction())
            {
                pipeline = ((Jedis) connection).pipelined();
            }
            Set<Object> joinKeys = joinTableRecords.keySet();

            for (Object joinKey : joinKeys)
            {
                String joinKeyAsStr = PropertyAccessorHelper.getString(joinKey);

                Set<Object> inverseKeys = joinTableRecords.get(joinKey);

                for (Object inverseKey : inverseKeys)
                {
                    Map<byte[], byte[]> redisFields = new HashMap<byte[], byte[]>(1);
                    String inverseJoinKeyAsStr = PropertyAccessorHelper.getString(inverseKey);
                    String redisKey = getHashKey(tableName, joinKeyAsStr + "_" + inverseJoinKeyAsStr);
                    redisFields.put(getEncodedBytes(joinColumn), getEncodedBytes(joinKeyAsStr)); // put
                                                                                                 // join
                                                                                                 // column
                                                                                                 // field.
                    redisFields.put(getEncodedBytes(inverseJoinColumn), getEncodedBytes(inverseJoinKeyAsStr)); // put
                                                                                                               // inverse
                                                                                                               // join
                                                                                                               // column
                                                                                                               // field

                    // add to hash table.

                    if (resource != null && resource.isActive())
                    {
                        ((Transaction) connection).hmset(getEncodedBytes(redisKey), redisFields);
                        // add index
                        ((Transaction) connection).zadd(getHashKey(tableName, inverseJoinKeyAsStr),
                                getDouble(inverseJoinKeyAsStr), redisKey);
                        ((Transaction) connection).zadd(getHashKey(tableName, joinKeyAsStr), getDouble(joinKeyAsStr),
                                redisKey);

                    }
                    else
                    {
                        ((Jedis) connection).hmset(getEncodedBytes(redisKey), redisFields);
                        // add index
                        ((Jedis) connection).zadd(getHashKey(tableName, inverseJoinKeyAsStr),
                                getDouble(inverseJoinKeyAsStr), redisKey);
                        ((Jedis) connection).zadd(getHashKey(tableName, joinKeyAsStr), getDouble(joinKeyAsStr),
                                redisKey);

                    }
                    redisFields.clear();
                }

            }

        }
        finally
        {
            if (pipeline != null)
            {
                pipeline.sync();
            }
            onCleanup(connection);
        }

    }
View Full Code Here

    @Override
    public void deleteByColumn(String schemaName, String tableName, String columnName, Object columnValue)
    {
        Object connection = null;
        Pipeline pipeLine = null;
        try
        {

            connection = getConnection();

            if (isBoundTransaction())
            {
                pipeLine = ((Jedis) connection).pipelined();
            }

            String valueAsStr = PropertyAccessorHelper.getString(columnValue);
            Double score = getDouble(valueAsStr);
            Set<String> results = null;
            if (resource != null && resource.isActive())
            {
                Response response = ((Transaction) connection).zrangeByScore(getHashKey(tableName, valueAsStr), score,
                        score);
                // ((Transaction) connection).exec();
                ((RedisTransaction) resource).onExecute(((Transaction) connection));

                results = (Set<String>) response.get();
            }
            else
            {
                results = ((Jedis) connection).zrangeByScore(getHashKey(tableName, valueAsStr), score, score);
            }
            // Set<String> results =
            // connection.zrangeByScore(getHashKey(tableName, valueAsStr),
            // score, score);

            if (results != null)
            {
                for (String rowKey : results)
                {
                    // byte[] hashKey = getEncodedBytes(getHashKey(tableName,
                    // rowKey));

                    Map<byte[], byte[]> columns = null;
                    columns = getColumns(connection, rowKey, columns);

                    for (byte[] column : columns.keySet()) // delete each
                                                           // column(e.g.
                    // field)
                    {
                        // connection.get(key)
                        String colName = PropertyAccessorFactory.STRING.fromBytes(String.class, columns.get(column));

                        if (resource != null && resource.isActive())
                        {
                            ((Transaction) connection).hdel(getEncodedBytes(rowKey), column); // delete
                            // record
                            ((Transaction) connection).zrem(getHashKey(tableName, colName), rowKey); // delete
                            // inverted
                            // index.

                        }
                        else
                        {
                            ((Jedis) connection).hdel(getEncodedBytes(rowKey), column); // delete
                            // record
                            ((Jedis) connection).zrem(getHashKey(tableName, colName), rowKey); // delete
                            // inverted
                            // index.

                        }
                    }
                }

            }
        }
        finally
        {
            if (pipeLine != null)
            {
                pipeLine.sync();
            }
            onCleanup(connection);
        }
    }
View Full Code Here

    @Override
    public int executeBatch()
    {
        Object connection = getConnection();
        // Create a hashset and populate data into it
        Pipeline pipeLine = null;
        if (isBoundTransaction())
        {
            pipeLine = ((Jedis) connection).pipelined();
        }
        try
        {
            for (Node node : nodes)
            {
                if (node.isDirty())
                {
                    node.handlePreEvent();
                    // delete can not be executed in batch
                    if (node.isInState(RemovedState.class))
                    {
                        onDelete(node.getData(), node.getEntityId(), pipeLine != null ? pipeLine : connection);
                    }
                    else
                    {

                        List<RelationHolder> relationHolders = getRelationHolders(node);
                        EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata,
                                node.getDataClass());

                        onPersist(metadata, node.getData(), node.getEntityId(), relationHolders,
                                pipeLine != null ? pipeLine : connection);
                    }
                    node.handlePostEvent();
                }
            }
        }
        finally
        {
            //
            if (pipeLine != null)
            {
                pipeLine.sync(); // send I/O.. as persist call. so no need to
                                 // read
                // response?
            }
            onCleanup(connection);
        }
View Full Code Here

    {
        Set<String> indexNames = values.keySet();
        for (String idx_Name : indexNames)
        {
            Double value = (Double) values.get(idx_Name);
            Pipeline pipeLine = null;
            try
            {
            if (this.pipeLineOrConnection.getClass().isAssignableFrom(Jedis.class))
            {
                pipeLine = ((Jedis) this.pipeLineOrConnection).pipelined();
                pipeLine.zadd(idx_Name, value, parentId.toString());
//                pipeLine.sync();
            }
            else
            {
                ((Transaction) this.pipeLineOrConnection).zadd(idx_Name, value, parentId.toString());
            }
            }finally
            {
                if(pipeLine != null)
                {
                    pipeLine.sync();
                }
            }
        }

    }
View Full Code Here

          String dateAsIntText = Integer.toString(LocalDateToIntConverter.convertToInt(entry.getKey()));
          htsMap.put(dateAsIntText, Double.toString(entry.getValue()));
          dates.put(Double.valueOf(dateAsIntText), dateAsIntText);
        }
       
        Pipeline pipeline = jedis.pipelined();
        pipeline.multi();
        String redisHtsDatapointKey = toRedisHtsDatapointKey(redisKey);
        pipeline.hmset(redisHtsDatapointKey, htsMap);
       
        String redisHtsDaysKey = toRedisHtsDaysKey(redisKey);
        for (String dateAsIntText : dates.inverse().keySet()) {
          pipeline.zrem(redisHtsDaysKey, dateAsIntText);
        }
       
        for (Entry<Double, String> entry : dates.entrySet()) {
          pipeline.zadd(redisHtsDaysKey, entry.getKey(), entry.getValue());
        }
            
        pipeline.exec();
        pipeline.sync();
        getJedisPool().returnResource(jedis);
      } catch (Exception e) {
        s_logger.error("Unable to put timeseries with id: " + redisKey, e);
        getJedisPool().returnBrokenResource(jedis);
        throw new OpenGammaRuntimeException("Unable to put timeseries with id: " + redisKey, e);
View Full Code Here

  @SuppressWarnings("unchecked")
  public Map<ExternalId, Map<String, String>> getLastKnownValues(final List<ExternalId> securities) {
    Map<ExternalId, Map<String, String>> result = Maps.newHashMap();
    JedisPool jedisPool = _redisConnector.getJedisPool();
    Jedis jedis = jedisPool.getResource();
    Pipeline pipeline = jedis.pipelined();
    //start transaction
    pipeline.multi();
    for (ExternalId identifier : securities) {
      String redisKey = generateRedisKey(identifier.getScheme().getName(), identifier.getValue(), getNormalizationRuleSetId());
      pipeline.hgetAll(redisKey);
    }
    Response<List<Object>> response = pipeline.exec();
    pipeline.sync();
   
    final Iterator<ExternalId> allSecItr = securities.iterator();
    final Iterator<Object> responseItr = response.get().iterator();
    while (responseItr.hasNext() && allSecItr.hasNext()) {
      result.put(allSecItr.next(), filterBlackListedTicks((Map<String, String>) responseItr.next()));
View Full Code Here

        Jedis shard = jedis.getShard(idx.key());
        try {
            if (shard.exists(idx.cat(id).key())) {
                seek.remove(id, sfields);
            }
            Pipeline p = shard.pipelined();
            for (Map.Entry<String, String> field : fields.entrySet()) {
                idx.cat(field.getKey()).cat(field.getValue());
                String key = idx.key();
                p.zadd(key, order, id);
                p.rpush(idx.cat(id).key(), key);
                p.hset(idx.cat(id).cat(Seek.FIELDS).key(), field.getKey(),
                        field.getValue());

                // adds on facets
                p.hincrBy(idx.cat(Seek.INFO).cat(field.getKey()).key(), field
                        .getValue(), 1);
                p.hincrBy(idx.cat(Seek.INFO).key(), field.getKey(), 1);
            }
            for (String tag : tags) {
                idx.cat(tag);
                String key = idx.key();
                p.zadd(key, order, id);
                p.rpush(idx.cat(id).key(), key);
                p.rpush(idx.cat(id).cat(Seek.TAGS).key(), tag);

                // adds on facets
                p.hincrBy(idx.cat(Seek.INFO).cat(Seek.TAGS).key(), tag, 1);
                p.hincrBy(idx.cat(Seek.INFO).key(), Seek.TAGS, 1);
            }
            for (Map.Entry<String, Set<String>> field : textFields.entrySet()) {
                for (String word : field.getValue()) {
                    idx.cat(field.getKey()).cat(word);
                    String key = idx.key();
                    p.zadd(key, order, id);
                    p.rpush(idx.cat(id).key(), key);
                }
            }
            p.incr(idx.cat(Seek.INFO).cat(Seek.TOTAL).key());
            p.execute();
            Seek.getPool().returnResource(jedis);
        } catch (Exception e) {
            Seek.getPool().returnResource(jedis);
            throw new SeekException(e);
        }
View Full Code Here

            } catch (NumberFormatException e) {
                info.setTotal(0);
            }
            final Map<String, String> facets = shard.hgetAll(idx.cat(Seek.INFO)
                    .key());
            Pipeline p = shard.pipelined();
            for (String facetField : facets.keySet()) {
                p.hgetAll(idx.cat(Seek.INFO).cat(facetField).key());
            }
            List<Object> data = p.execute();
            getPool().returnResource(jedis);
            Iterator<Object> iterator = data.iterator();
            for (String facetField : facets.keySet()) {
                List<Object> next = (List<Object>) iterator.next();
                Iterator<Object> it = next.iterator();
View Full Code Here

TOP

Related Classes of redis.clients.jedis.Pipeline$MultiResponseBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.