Java Code Examples for redis.clients.jedis.Jedis#connect()
The following examples show how to use
redis.clients.jedis.Jedis#connect() .
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: TestServicesUtils.java From simpleci with MIT License | 6 votes |
public static boolean testRedis(String host, int port) { final int tryCount = 10; for (int i = 1; i <= tryCount; i++) { logger.info(String.format("redis: connecting to %s:%s, try %d of %d", host, port, i, tryCount)); try { Jedis connection = new Jedis(host, port); connection.connect(); connection.close(); logger.info("Connection to redis established successfully"); return true; } catch (JedisConnectionException e) { logger.info("Failed to connect: " + e.getMessage()); try { Thread.sleep(1000); } catch (InterruptedException e1) { logger.error("", e); } } } logger.info(String.format("Failed connect to redis on %s:%d", host, port)); return false; }
Example 2
Source File: PipelinedGetSetBenchmark.java From cachecloud with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws UnknownHostException, IOException { Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort()); jedis.connect(); jedis.auth("foobared"); jedis.flushAll(); long begin = Calendar.getInstance().getTimeInMillis(); Pipeline p = jedis.pipelined(); for (int n = 0; n <= TOTAL_OPERATIONS; n++) { String key = "foo" + n; p.set(key, "bar" + n); p.get(key); } p.sync(); long elapsed = Calendar.getInstance().getTimeInMillis() - begin; jedis.disconnect(); System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); }
Example 3
Source File: ClusterCommandsTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort()); node1.connect(); node1.flushAll(); node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort()); node2.connect(); node2.flushAll(); }
Example 4
Source File: RedisClient.java From nosql4idea with Apache License 2.0 | 5 votes |
@Override public void connect(ServerConfiguration serverConfiguration) { Jedis jedis = createJedis(serverConfiguration); jedis.connect(); String userDatabase = serverConfiguration.getUserDatabase(); int index = 0; if (StringUtils.isNotEmpty(userDatabase)) { index = Integer.parseInt(userDatabase); } jedis.select(index); }
Example 5
Source File: SaveTopologyinDB.java From netphony-topology with Apache License 2.0 | 5 votes |
public void configure( Hashtable<String,TEDB> intraTEDBs,MultiDomainTEDB multiTED, boolean writeTopology, String host, int port){ this.intraTEDBs=intraTEDBs; this.writeTopology=writeTopology; this.multiDomainTEDB=multiTED; //rdh.setHost(host); //rdh.setPort(port); if (writeTopology){ jedis = new Jedis(host,port); jedis.connect(); } }
Example 6
Source File: RedisStore.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
@Override public void connect() throws IOException { jedis = new Jedis(host, port,timeOut); jedis.connect(); jedis.select(dbIndex); }
Example 7
Source File: RedisServerClientConnectionManager.java From digdag with Apache License 2.0 | 5 votes |
@Override public ParamServerClientConnection getConnection() { Jedis redisClient = new Jedis(host, port, ssl); if (password.isPresent()) { redisClient.auth(password.get()); } redisClient.connect(); return new RedisServerClientConnection(redisClient); }
Example 8
Source File: PipeliningTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { jedis = new Jedis(hnp.getHost(), hnp.getPort(), 2000); jedis.connect(); jedis.auth("foobared"); jedis.flushAll(); }
Example 9
Source File: PoolBenchmark.java From cachecloud with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Jedis j = new Jedis(hnp.getHost(), hnp.getPort()); j.connect(); j.auth("foobared"); j.flushAll(); j.quit(); j.disconnect(); long t = System.currentTimeMillis(); // withoutPool(); withPool(); long elapsed = System.currentTimeMillis() - t; System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); }
Example 10
Source File: RedisDatabaseHandler.java From netphony-topology with Apache License 2.0 | 5 votes |
public boolean write(String key, String json){ //System.out.println("WRITING IN "+host+" port "+port); Jedis jedis = new Jedis(host,port); jedis.connect(); String ret = jedis.set(key, json); jedis.sadd("TEDB",key); jedis.disconnect(); return true; }
Example 11
Source File: MyJedisPool.java From bidder with Apache License 2.0 | 5 votes |
@Override protected Jedis createObject() { Jedis jedis = new Jedis(host,port); jedis.connect(); return jedis; }
Example 12
Source File: TransactionCommandsTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { super.setUp(); nj = new Jedis(hnp.getHost(), hnp.getPort(), 500); nj.connect(); nj.auth("foobared"); nj.flushAll(); }
Example 13
Source File: JedisCommandTestBase.java From cachecloud with Apache License 2.0 | 5 votes |
protected Jedis createJedis() { Jedis j = new Jedis(hnp.getHost(), hnp.getPort()); j.connect(); j.auth("foobared"); j.flushAll(); return j; }
Example 14
Source File: JedisCommandTestBase.java From cachecloud with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { jedis = new Jedis(hnp.getHost(), hnp.getPort(), 500); jedis.connect(); jedis.auth("foobared"); jedis.configSet("timeout", "300"); jedis.flushAll(); }
Example 15
Source File: RedisLockCoordinator.java From jeesuite-libs with Apache License 2.0 | 5 votes |
public Jedis getRedisClient(){ Jedis jedis = (Jedis) JedisProviderFactory.getJedisProvider(DLOCK_GROUP_NAME).get(); if(!jedis.isConnected()){ jedis.connect(); } return jedis; }
Example 16
Source File: RedisHashRecordReader.java From Redis-4.x-Cookbook with MIT License | 5 votes |
public void initialize(InputSplit split, TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException { host = split.getLocations()[0]; prefix = ((RedisHashInputSplit) split).getPrefix(); key = ((RedisHashInputSplit) split).getKey(); String hashKey = prefix+":"+key; jedis = new Jedis(host); log.info("Connect to " + host); jedis.connect(); jedis.getClient().setTimeoutInfinite(); totalKVs = jedis.hlen(hashKey); keyValueMapIter = jedis.hgetAll(hashKey).entrySet().iterator(); }
Example 17
Source File: RedisHashRecordWriter.java From Redis-4.x-Cookbook with MIT License | 5 votes |
public RedisHashRecordWriter( String host, String pLength, String prefix) { this.pLength = Integer.parseInt(pLength); this.prefix = prefix; jedis = new Jedis(host); jedis.connect(); }
Example 18
Source File: ClusterBinaryJedisCommandsTest.java From cachecloud with Apache License 2.0 | 4 votes |
@Before public void setUp() throws InterruptedException { node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort()); node1.connect(); node1.flushAll(); node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort()); node2.connect(); node2.flushAll(); node3 = new Jedis(nodeInfo3.getHost(), nodeInfo3.getPort()); node3.connect(); node3.flushAll(); // ---- configure cluster // add nodes to cluster node1.clusterMeet("127.0.0.1", nodeInfo2.getPort()); node1.clusterMeet("127.0.0.1", nodeInfo3.getPort()); // split available slots across the three nodes int slotsPerNode = JedisCluster.HASHSLOTS / 3; int[] node1Slots = new int[slotsPerNode]; int[] node2Slots = new int[slotsPerNode + 1]; int[] node3Slots = new int[slotsPerNode]; for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < JedisCluster.HASHSLOTS; i++) { if (i < slotsPerNode) { node1Slots[slot1++] = i; } else if (i > slotsPerNode * 2) { node3Slots[slot3++] = i; } else { node2Slots[slot2++] = i; } } node1.clusterAddSlots(node1Slots); node2.clusterAddSlots(node2Slots); node3.clusterAddSlots(node3Slots); waitForClusterReady(); jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); jedisCluster = new JedisCluster(jedisClusterNode); }
Example 19
Source File: ClusterScriptingCommandsTest.java From cachecloud with Apache License 2.0 | 4 votes |
@Before public void setUp() throws InterruptedException { node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort()); node1.connect(); node1.flushAll(); node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort()); node2.connect(); node2.flushAll(); node3 = new Jedis(nodeInfo3.getHost(), nodeInfo3.getPort()); node3.connect(); node3.flushAll(); // ---- configure cluster // add nodes to cluster node1.clusterMeet("127.0.0.1", nodeInfo2.getPort()); node1.clusterMeet("127.0.0.1", nodeInfo3.getPort()); // split available slots across the three nodes int slotsPerNode = JedisCluster.HASHSLOTS / 3; int[] node1Slots = new int[slotsPerNode]; int[] node2Slots = new int[slotsPerNode + 1]; int[] node3Slots = new int[slotsPerNode]; for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < JedisCluster.HASHSLOTS; i++) { if (i < slotsPerNode) { node1Slots[slot1++] = i; } else if (i > slotsPerNode * 2) { node3Slots[slot3++] = i; } else { node2Slots[slot2++] = i; } } node1.clusterAddSlots(node1Slots); node2.clusterAddSlots(node2Slots); node3.clusterAddSlots(node3Slots); waitForClusterReady(); jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); jedisCluster = new JedisCluster(jedisClusterNode); }
Example 20
Source File: RedisVerticleTest.java From reactive-refarch-cloudformation with Apache License 2.0 | 3 votes |
@BeforeClass public static void before(TestContext context) throws Exception { String redisHost = System.getenv(REDIS_HOST) == null ? "localhost" : System.getenv(REDIS_HOST); int redisPort = System.getenv(REDIS_PORT) == null ? 6379 : Integer.getInteger(System.getenv(REDIS_PORT)); LOGGER.info("Using Redis Host " + redisHost); LOGGER.info("Using Redis Port " + redisPort); jedis = new Jedis(redisHost, redisPort); jedis.connect(); TrackingMessage trackingMessage = prepareData(); writeDatatoRedis(trackingMessage, redisPort, redisHost); vertx = Vertx.vertx(); eb = vertx.eventBus(); // For this test, we need RedisVerticle and CacheVerticle vertx.deployVerticle(RedisVerticle.class.getCanonicalName(), context.asyncAssertSuccess(deploymentID -> { })); vertx.deployVerticle(CacheVerticle.class.getCanonicalName(), context.asyncAssertSuccess(deploymentID -> { })); }