import redis.clients.jedis.UnifiedJedis;
public class CmdsHashExample {
public void run() {
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
// Tests for 'hdel' step.
// Tests for 'hexists' step.
// Tests for 'hexpire' step.
// Tests for 'hexpireat' step.
// Tests for 'hexpiretime' step.
Map<String, String> hGetExampleParams = new HashMap<>();
hGetExampleParams.put("field1", "foo");
long hGetResult1 = jedis.hset("myhash", hGetExampleParams);
System.out.println(hGetResult1); // >>> 1
String hGetResult2 = jedis.hget("myhash", "field1");
System.out.println(hGetResult2); // >>> foo
String hGetResult3 = jedis.hget("myhash", "field2");
System.out.println(hGetResult3); // >>> null
// Tests for 'hget' step.
// Tests for 'hgetall' step.
// Tests for 'hincrby' step.
// Tests for 'hincrbyfloat' step.
// Tests for 'hkeys' step.
// Tests for 'hlen' step.
// Tests for 'hmget' step.
// Tests for 'hmset' step.
// Tests for 'hpersist' step.
// Tests for 'hpexpire' step.
// Tests for 'hpexpireat' step.
// Tests for 'hpexpiretime' step.
// Tests for 'hpttl' step.
// Tests for 'hrandfield' step.
// Tests for 'hscan' step.
Map<String, String> hSetExampleParams = new HashMap<>();
hSetExampleParams.put("field1", "Hello");
long hSetResult1 = jedis.hset("myhash", hSetExampleParams);
System.out.println(hSetResult1); // >>> 1
String hSetResult2 = jedis.hget("myhash", "field1");
System.out.println(hSetResult2); // >>> Hello
hSetExampleParams.clear();
hSetExampleParams.put("field2", "Hi");
hSetExampleParams.put("field3", "World");
long hSetResult3 = jedis.hset("myhash",hSetExampleParams);
System.out.println(hSetResult3); // >>> 2
String hSetResult4 = jedis.hget("myhash", "field2");
System.out.println(hSetResult4); // >>> Hi
String hSetResult5 = jedis.hget("myhash", "field3");
System.out.println(hSetResult5); // >>> World
Map<String, String> hSetResult6 = jedis.hgetAll("myhash");
for (String key: hSetResult6.keySet()) {
System.out.println("Key: " + key + ", Value: " + hSetResult6.get(key));
}
// >>> Key: field3, Value: World
// >>> Key: field2, Value: Hi
// >>> Key: field1, Value: Hello
// Tests for 'hset' step.
// Tests for 'hsetnx' step.
// Tests for 'hstrlen' step.
// Tests for 'httl' step.
// Tests for 'hvals' step.
}
}