java操作redis
①导入依赖
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.0.1</version>
</dependency>
②
Jedis j=new Jedis("192.168.43.245",6379);
System.out.println(j.ping());
j.set("name","李螺丝");
j.get("name");
j.lpush("list","g","q","y","w");
List<String> list = j.lrange("list", 0, -1);
System.out.println(list.toString());
Map<String,String> map=new HashMap<>();
map.put("g","1");
map.put("y","2");
j.hset("map",map);
System.out.println(j.hget("map", "g"));
Map<String, String> map1 = j.hgetAll("map");
Iterator<String> iterator = map1.keySet().iterator();
while (iterator.hasNext()){
String next = iterator.next();
String s = map1.get(next);
System.out.println(next + s);
}
启动redis服务
cd /user/myredis 进入文件夹
./redis-server redis.conf 启动服务
./redis-cli