Last active
January 22, 2019 19:31
-
-
Save deepakverma/9aa4dc04ded700603a8ef24eececf5d3 to your computer and use it in GitHub Desktop.
Jedis Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> | |
<property name="maxTotal" value="10" /> | |
</bean> | |
<bean id="jedisShardInfo" class="redis.clients.jedis.JedisShardInfo"> | |
<constructor-arg index="0" value="*.redis.cache.windows.net" /> | |
<constructor-arg index="1" value="6379" type="int" /> | |
<property name="password" value="***"/> | |
</bean> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try(Jedis jedis = jedisPool.getResource()) | |
{ | |
//pipeline | |
Pipeline p = jedis.pipelined(); | |
Response<String> pipeIdResponse = p.get("ID"); | |
Response<String> pipeNameResponse = p.get("Name"); | |
p.sync(); | |
String id = pipeIdResponse.get(); | |
String name = pipeNameResponse.get(); | |
System.out.println(id); | |
System.out.println(name); | |
} | |
catch(JedisConnectionException ex) | |
{ | |
//log.warn("Could not connect to Redis."); | |
} | |
catch (JedisException ex) | |
{ | |
//log.error("Failed to process", e); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JedisPoolConfig poolConfig = new JedisPoolConfig(); | |
poolConfig.setMaxTotal(10); | |
JedisPool jedisPool = new | |
JedisPool(poolConfig,"127.0.0.1", 6379); // jedisPool should be re-used and stored statically |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment