使用java遠端連線redis
阿新 • • 發佈:2019-01-07
public class RedisConn {
public static class User{
private String username ;
private String passwords ;
}
public static void main(String[] args) {
Jedis redis = new Jedis("192.168.40.128");//連線到redis伺服器
System.out.println(redis.ping());//判斷是否連線成功
System.out.println( !redis.exists("user" ));//建立一個/hash
if ( ! redis.exists("user")) {
redis.hset("user" , "username" ,"shenjg");//新增引數
redis.hset("user" , "passwords" , "123456");
System.out.println(redis.hget("user" , "username"));
}
User user = new User();
user.username = redis.hget("user" , "username");//獲取資料
user.passwords = redis.hget("user" , "passwords");
System.out.println("使用者名稱" + user.username + "密碼: " + user.passwords );
}
public static class User{
private String username ;
private String passwords ;
}
public static void main(String[] args) {
Jedis redis = new Jedis("192.168.40.128");//連線到redis伺服器
System.out.println(redis.ping());//判斷是否連線成功
System.out.println( !redis.exists("user"
if ( ! redis.exists("user")) {
redis.hset("user" , "username" ,"shenjg");//新增引數
redis.hset("user" , "passwords" , "123456");
System.out.println(redis.hget("user" , "username"));
}
User user = new User();
user.username = redis.hget("user" , "username");//獲取資料
user.passwords
System.out.println("使用者名稱" + user.username + "密碼: " + user.passwords );
}