Created
December 31, 2021 15:59
-
-
Save AnasBrital98/8b960818cff0a773a6bb9c54390b9ece to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Set; | |
import redis.clients.jedis.Jedis; | |
public class Main { | |
static final String HOST = "192.168.43.94"; | |
static final int PORT = 6379; | |
public static void main(String args[]) | |
{ | |
try { | |
Jedis redis_client = new Jedis(HOST , PORT); | |
// Manipulation des Strings | |
redis_client.set("MSIDSD", "MASTER EN SYSTÈME INTELLIGENTS ET DÉVELOPPEMENT DES SYSTÈMES DÉCISIONNELS"); | |
System.out.println(redis_client.get("MSIDSD")); | |
//Manipulation des Lists | |
redis_client.lpush("msidsd_students_list", "Hind","Mohamed","khaoula","amine","karim","mohamed"); | |
List<String> msidsd_students = redis_client.lrange("msidsd_students_list", 0, -1); | |
msidsd_students.forEach(student -> {System.out.println(student);}); | |
// Manipulation des Sets | |
redis_client.sadd("students_list", "Student 1"); | |
redis_client.sadd("students_list", "Student 2"); | |
redis_client.sadd("students_list", "Student 3"); | |
Set<String> students = redis_client.smembers("students_list"); | |
students.forEach(s ->{System.out.println(s);}); | |
Boolean exists = redis_client.sismember("students_list", "Student 2"); | |
System.out.println(exists); | |
// Manipulation des Hashes | |
redis_client.hset("product:1", "id", "1"); | |
redis_client.hset("product:1", "name", "AAAA"); | |
redis_client.hset("product:1", "description", "Desc for AAAA"); | |
redis_client.hset("product:1", "price", "120"); | |
float product_price = Float.parseFloat(redis_client.hget("product:1", "price")); | |
System.out.println("Le Prix du produit avec le ID = 1 est : "+product_price); | |
Map<String, String> produt = redis_client.hgetAll("product:1"); | |
System.out.println("Product:1 : "); | |
produt.entrySet().forEach(entry -> {System.out.println(entry.getKey() + " : "+entry.getValue());}); | |
// Manipulation des Sorted Set | |
Map<String ,Integer> students_list = new HashMap(); | |
students_list.put("student 1", 16); | |
students_list.put("student 2", 13); | |
students_list.put("student 3", 17); | |
students_list.put("student 4", 20); | |
students_list.put("student 5", 12); | |
students_list.entrySet().forEach(entry -> { | |
redis_client.zadd("students_list", entry.getValue(),entry.getKey()); | |
}); | |
String student_1 = redis_client.zrevrange("students_list", 0, 1).iterator().next(); | |
System.out.println(student_1); | |
}catch(Exception e) { | |
System.out.println(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment