Search in sources :

Example 51 with JedisPool

use of redis.clients.jedis.JedisPool in project tech by ffyyhh995511.

the class JedisService method mset.

/**
 * 批量字符串存储
 * @param keysvalues
 */
public String mset(String... keysvalues) {
    String rs = null;
    Jedis jedis = null;
    JedisPool jedisPool = null;
    try {
        jedisPool = getJedisPool();
        jedis = jedisPool.getResource();
        if (jedis != null) {
            rs = jedis.mset(keysvalues);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
    return rs;
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool)

Example 52 with JedisPool

use of redis.clients.jedis.JedisPool in project grakn by graknlabs.

the class EngineContext method before.

@Override
protected final void before() throws Throwable {
    RestAssured.baseURI = uri().toURI().toString();
    if (!config.getProperty(GraknConfigKey.TEST_START_EMBEDDED_COMPONENTS)) {
        return;
    }
    SimpleURI redisURI = new SimpleURI(Iterables.getOnlyElement(config.getProperty(GraknConfigKey.REDIS_HOST)));
    jedisPool = new JedisPool(redisURI.getHost(), redisURI.getPort());
    // To ensure consistency b/w test profiles and configuration files, when not using Janus
    // for a unit tests in an IDE, add the following option:
    // -Dgrakn.conf=../conf/test/tinker/grakn.properties
    // 
    // When using janus, add -Dgrakn.test-profile=janus
    // 
    // The reason is that the default configuration of Grakn uses the Janus Factory while the default
    // test profile is tinker: so when running a unit test within an IDE without any extra parameters,
    // we end up wanting to use the JanusFactory but without starting Cassandra first.
    LOG.info("starting engine...");
    // start engine
    setRestAssuredUri(config);
    spark = Service.ignite();
    config.setConfigProperty(GraknConfigKey.REDIS_HOST, Collections.singletonList("localhost:" + redis.port()));
    RedisWrapper redis = RedisWrapper.create(config);
    server = startGraknEngineServer(redis);
    LOG.info("engine started on " + uri());
}
Also used : RedisWrapper(ai.grakn.engine.data.RedisWrapper) SimpleURI(ai.grakn.util.SimpleURI) JedisPool(redis.clients.jedis.JedisPool)

Example 53 with JedisPool

use of redis.clients.jedis.JedisPool in project dubbo by alibaba.

the class RedisRegistry method doUnregister.

@Override
public void doUnregister(URL url) {
    String key = toCategoryPath(url);
    String value = url.toFullString();
    RpcException exception = null;
    boolean success = false;
    for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
        JedisPool jedisPool = entry.getValue();
        try {
            Jedis jedis = jedisPool.getResource();
            try {
                jedis.hdel(key, value);
                jedis.publish(key, Constants.UNREGISTER);
                success = true;
                if (!replicate) {
                    //  If the server side has synchronized data, just write a single machine
                    break;
                }
            } finally {
                jedis.close();
            }
        } catch (Throwable t) {
            exception = new RpcException("Failed to unregister service to redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
        }
    }
    if (exception != null) {
        if (success) {
            logger.warn(exception.getMessage(), exception);
        } else {
            throw exception;
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) RpcException(com.alibaba.dubbo.rpc.RpcException) JedisPool(redis.clients.jedis.JedisPool) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 54 with JedisPool

use of redis.clients.jedis.JedisPool in project jfinal by jfinal.

the class RedisPlugin method start.

public boolean start() {
    JedisPool jedisPool;
    if (port != null && timeout != null && password != null && database != null && clientName != null)
        jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password, database, clientName);
    else if (port != null && timeout != null && password != null && database != null)
        jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password, database);
    else if (port != null && timeout != null && password != null)
        jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password);
    else if (port != null && timeout != null)
        jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout);
    else if (port != null)
        jedisPool = new JedisPool(jedisPoolConfig, host, port);
    else
        jedisPool = new JedisPool(jedisPoolConfig, host);
    if (serializer == null)
        serializer = FstSerializer.me;
    if (keyNamingPolicy == null)
        keyNamingPolicy = IKeyNamingPolicy.defaultKeyNamingPolicy;
    Cache cache = new Cache(cacheName, jedisPool, serializer, keyNamingPolicy);
    Redis.addCache(cache);
    return true;
}
Also used : JedisPool(redis.clients.jedis.JedisPool)

Example 55 with JedisPool

use of redis.clients.jedis.JedisPool in project gitblit by gitblit.

the class RedisTicketService method createPool.

private JedisPool createPool(String url) {
    JedisPool pool = null;
    if (!StringUtils.isEmpty(url)) {
        try {
            URI uri = URI.create(url);
            if (uri.getScheme() != null && uri.getScheme().equalsIgnoreCase("redis")) {
                int database = Protocol.DEFAULT_DATABASE;
                String password = null;
                if (uri.getUserInfo() != null) {
                    password = uri.getUserInfo().split(":", 2)[1];
                }
                if (uri.getPath().indexOf('/') > -1) {
                    database = Integer.parseInt(uri.getPath().split("/", 2)[1]);
                }
                pool = new JedisPool(new GenericObjectPoolConfig(), uri.getHost(), uri.getPort(), Protocol.DEFAULT_TIMEOUT, password, database);
            } else {
                pool = new JedisPool(url);
            }
        } catch (JedisException e) {
            log.error("failed to create a Redis pool!", e);
        }
    }
    return pool;
}
Also used : JedisException(redis.clients.jedis.exceptions.JedisException) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisPool(redis.clients.jedis.JedisPool) URI(java.net.URI)

Aggregations

JedisPool (redis.clients.jedis.JedisPool)108 Jedis (redis.clients.jedis.Jedis)75 Test (org.junit.Test)47 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)40 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)17 HostAndPort (redis.clients.jedis.HostAndPort)6 URI (java.net.URI)5 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)5 JedisCluster (redis.clients.jedis.JedisCluster)5 RpcException (com.alibaba.dubbo.rpc.RpcException)4 URISyntaxException (java.net.URISyntaxException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 JedisException (redis.clients.jedis.exceptions.JedisException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 InvalidURIException (redis.clients.jedis.exceptions.InvalidURIException)3 ArrayList (java.util.ArrayList)2