redis数据库的java接入,redisson的使用( 三 )


文章插图

9ps,于2017/09/07弥补:
这是我本身写的一个简单操作redis数据库的Dao类,可以作为参考
package db;
import java.util.Set;  
  
import org.redisson.Redisson;
import org.redisson.config.Config;  
public class RedisDao {  
public static int STATUS = 0;
private static Redisson redisson;
static {
//启动redis办事器
openExe();
// 1.初始化设置装备摆设
        Config config = new Config();  
        config.useSingleServer().setAddress("http://127.0.0.1:6379");  //要毗连的redis库
        redisson = (Redisson) Redisson.create(config);  //建立毗连
        System.out.println("reids毗连当作功...");  
}

public static void add(String setName,String url) {
// 将url插手set表中
        Set mySet = redisson.getSet(setName);  
        mySet.add(url);  
}

public static boolean querySet(String setName,String url) {
// 查询set中是否包含url
        Set mySet = redisson.getSet(setName);  
        return mySet.contains(url);
}

public static void closeRedis() {
// 封闭毗连  
        redisson.shutdown();  
}

// 挪用可执行文件 
public static void openExe() {  
   final Runtime runtime = Runtime.getRuntime();  
   Process process = null; 
   try {  
    //redis-server.exe的路径
       process = runtime.exec("G:\\eclipse4.7space\\Redis-x64-3.0.504\\redis-server.exe");  
       STATUS = 1;
   } catch (final Exception e) {  
       System.out.println("Error exec!");  
   }  
}       
}  

redis数据库的java接入,redisson的使用

文章插图

10别的需要注重一下redis的默认持久化法则,单key操作完当作后15min后保留,10key操作完当作5min后保留,10000key操作完当作后,1min后保留,且以上保留只发生在操作完当作之后,持续操作间断电将导致数据丢掉
# Save the DB on disk:
#
#   save <seconds> <changes>
#
#   Will save the DB if both the given number of seconds and the given
#   number of write operations against the DB occurred.
#
#   In the example below the behaviour will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
#
#   Note: you can disable saving completely by commenting out all "save" lines.
#
#   It is also possible to remove all the previously configured save
#   points by adding a save directive with a single empty string argument
#   like in the following example:
#
#   save ""
save 900 1
save 300 10
【redis数据库的java接入,redisson的使用】save 60 10000

redis数据库的java接入,redisson的使用

文章插图

推荐阅读