文章插图
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!");
}
}
}
文章插图
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
文章插图
推荐阅读
- 怎么不让别人看自己的微信朋友圈
- 打开Excel出现某个对象程序库
- 中国茶文化的生命价值观分析,四大名茶
- 图像的拼接、修改、再创造
- 中国茶文化中的茶道,铁观音发源地
- 怎样录制高清无水印的视频
- 汉魏晋南北朝-茶文化的酿造,茶叶连锁加盟
- 2018年4K电视如何选
- 工夫茶与潮人的文化心态,湖南茶
- 图解利用SSMS复制数据库