Installation and use redis redis [2] Operation of the java

1, provided that the constraints
are familiar with command line operation https://www.jianshu.com/p/26f6e85e600f redis
modify redis.conf
# Bind the ip, author machine is 192.168.100.192, the reader is set according to the actual situation
bind 192.168.100.192
# non-protected mode
protected-mode no
save and reboot

2. Operation
2.1 idea to create a maven project
https://www.jianshu.com/p/042073b7710b

2.2 pom.xml modified
by adding the following dependency:

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.2</version>
</dependency>
2.3 创建测试类
import redis.clients.jedis.Jedis;

import java.util.List;
import java.util.Set;

public class Test {
public static void main(String[] args) {
Jedis jedis = new Jedis("192.168.100.192", 6379);

//string设置及获取值
jedis.set("name", "ali");
String name = jedis.get("name");
System.out.println(name);

//list设置及获取值
jedis.lpush("list1", "a", "b");
List<String> list1 = jedis.lrange("list1", 0, -1);// Set the hash value acquisition and
System.out.println (List1);




















Guess you like

Origin www.cnblogs.com/ly570/p/10961761.html