Let's first look at how java links redis
Maven:
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.0.1</version> </dependency>
Java:
public static void main(String[] args) { Jedis jedis = new Jedis("192.168.5.137",6379);//Link redis with IP and Port parameters Set<String> keys = jedis.keys("*"); //View redis existing key for(String key : keys){ System.out.println(key); } }
Java links redis using Jedis and manipulates data in Redis through Jedis. Let's look at the functions provided in Jedis.
Jedis structure:
Jedis construction provides a wealth of redis linking methods and parameter settings, the most commonly used of which is the first few, setting redis IP and Port, and then setting the link timeout time and whether to use SSL (Secure Socket Layer)
public Jedis() { } public Jedis(String host) { super(host); } public Jedis(HostAndPort hp) { super(hp); } //HostAndPort encapsulates host and port information public Jedis(String host, int port) { super(host, port); } public Jedis(String host, int port, boolean ssl) { super(host, port, ssl); } public Jedis(String host, int port, int timeout) { super(host, port, timeout); } public Jedis(String host, int port, int timeout, boolean ssl) { super(host, port, timeout, ssl); } public Jedis(String host, int port, boolean ssl, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters, HostnameVerifier hostnameVerifier) { super(host, port, ssl, sslSocketFactory, sslParameters, hostnameVerifier); } public Jedis(String host, int port, int timeout, boolean ssl, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters, HostnameVerifier hostnameVerifier) { super(host, port, timeout, ssl, sslSocketFactory, sslParameters, hostnameVerifier); } public Jedis(String host, int port, int connectionTimeout, int soTimeout) { super(host, port, connectionTimeout, soTimeout); } public Jedis(String host, int port, int connectionTimeout, int soTimeout, boolean ssl) { super(host, port, connectionTimeout, soTimeout, ssl); } public Jedis(String host, int port, int connectionTimeout, int soTimeout, boolean ssl, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters, HostnameVerifier hostnameVerifier) { super(host, port, connectionTimeout, soTimeout, ssl, sslSocketFactory, sslParameters, hostnameVerifier); } public Jedis(JedisShardInfo shardInfo) { super(shardInfo); } public Jedis(URI uri) { super(uri); } public Jedis(URI uri, int timeout) { super(uri, timeout); } public Jedis(URI uri, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters, HostnameVerifier hostnameVerifier) { super(uri, sslSocketFactory, sslParameters, hostnameVerifier); } public Jedis(URI uri, int timeout, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters, HostnameVerifier hostnameVerifier) { super(uri, timeout, sslSocketFactory, sslParameters, hostnameVerifier); } public Jedis(URI uri, int connectionTimeout, int soTimeout) { super(uri, connectionTimeout, soTimeout); } public Jedis(URI uri, int connectionTimeout, int soTimeout, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters, HostnameVerifier hostnameVerifier) { super(uri, connectionTimeout, soTimeout, sslSocketFactory, sslParameters, hostnameVerifier); }
Jedis contains all the redis operation functions, and the command function is very similar to our direct redis operation commands in the redis client. Here we list some redis functions for your reference. More Jedis API can see the source code of Jedis. Here you can compare Common commands for redis To learn.
Jedis Command:
Boolean exists(String var1); Long persist(String var1); Set<String> keys(String var1); String select(int index) Long move(String key, int dbIndex)
Jedis operates on String type data:
String set(String var1, String var2); String get(String var1); String getSet(String var1, String var2); List<String> mget(String... var1); String mset(String... var1);
Jedis operates on List type data:
List<String> blpop(int var1, String... var2); List<String> brpop(int var1, String... var2); List<String> blpop(String... var1); List<String> brpop(String... var1); String lpop(String var1); String rpop(String var1);
Jedis operates on Set type data:
Long sadd(String var1, String... var2); Set<String> smembers(String var1); Long srem(String var1, String... var2); String spop(String var1); Set<String> spop(String var1, long var2); Long scard(String var1);
Jedis operates on Zset type data:
Long zadd(String var1, double var2, String var4); Long zadd(String var1, Map<String, Double> var2); Long zcard(String var1); Long zcount(String var1, double var2, double var4); Long zcount(String var1, String var2, String var3); Set<String> zrangeByScore(String var1, double var2, double var4); Set<String> zrangeByScore(String var1, String var2, String var3);
Jedis operates on Hash type data:
Boolean hexists(String var1, String var2); Long hdel(String var1, String... var2); Long hlen(String var1); Set<String> hkeys(String var1); List<String> hvals(String var1);