1建立一个maven工程放入下面jedis依赖
<!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> |
2
package com.jredistest;
import java.util.HashMap;
import java.util.Map;
import redis.clients.jedis.Jedis;
public class Test {
private static Jedis jedis = null;
public static void main(String[] args) {
jedis = new Jedis("192.168.26.4", 6379);//redis里面的名字和redis的端口号
jedis.auth("123456");//redis的密码
// sethashmap();
// setstring();
//setlist();
setset();
}
public static void setstring() {
jedis.set("hegongye", "8000");
System.out.println("添加成功");
}
public static void sethashmap() {
Map<String, String> map = new HashMap<String, String>();
map.put("jhj", "13000");
map.put("Lj", "13000");
jedis.hmset("jiuye", map);
System.out.println("添加成功");
}
public static void setlist() {
jedis.lpush("jhj", "10000");
jedis.lpush("jhj", "20000");
System.out.println("添加成功");
}
public static void setset() {
jedis.sadd("xiaodong", "baobao");
jedis.sadd("xiaodong", "bao");
jedis.sadd("xiaodong", "baoo");
}
public static void setpaixu() {