redis 下载及使用
redis 官网下载地址:http://redis.io/
E:\工作软件\新建文件夹\redis64-2.8.19 redis-server.exe 执行该命令
当前已启动 端口号:6379
redis.conf 该配制文件中配置登陆密码
在次下面配置################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass "123456"
redis 可视化工具RedisStudio下载地址 :https://github.com/cinience/RedisStudio/releases 下载之后直接打开
填写完毕之后直接save就可以了
在此下面查找数据
redis java的增删改查:
/**
* 根据key删除value
* @param key
*/
public void remove(String key){
if(key == null || "".equals(key)){
throw new ServiceException("key值不能为空!");
}
JedisPool pool = null;
Jedis jedis = null;
try{
pool = getPool();
jedis = pool.getResource();
if(jedis.exists(key)){
jedis.del(key);
}
}catch (Exception e){
e.printStackTrace();
}finally {
if(jedis != null){
jedis.close();
}
}
} /**
* 根据key读取value值,可根据传入类型进行转型
* @param key
* @param clazz
* @param <T>
* @return
*/
public <T> T getData(String key, Class<T> clazz){
if(key == null || "".equals(key)){
throw new ServiceException("key值不能为空!");
}
Object result = null;
JedisPool pool = null;
Jedis jedis = null;
try{
pool = getPool();
jedis = pool.getResource();
result = jedis.get(key);
}catch (Exception e){
e.printStackTrace();
}finally {
if(jedis != null){
jedis.close();
}
}
JsonMapper m = new JsonMapper();
return (T) m.fromJson(String.valueOf(result), clazz);
} /**
* 新增/修改,需要传入key,value可传入对象,生存时间(单位:秒)
* @param key
* @param obj
* @param t
*/
public void save(String key, Object obj, int t){
if(key == null || "".equals(key)){
throw new ServiceException("key值不能为空!");
} if(obj == null){
throw new ServiceException("value值不能为空!");
} JsonMapper m = new JsonMapper();
String val = m.toJson(obj);
logger.debug("新增key=>" + key + "及value=>" + val);
JedisPool pool = null;
Jedis jedis = null;
try {
pool = getPool();
jedis = pool.getResource();
jedis.set(key, val);
jedis.expire(key, t);
}catch (Exception e){
e.printStackTrace();
throw new ServiceException("保存redis数据失败!");
}finally {
if(jedis != null){
jedis.close();
}
}
} /**
* 更新key的生存时间(单位:秒)
* @param key
* @param t
* @return
*/
public Long expireRow(String key, int t){
if(key == null || "".equals(key)){
throw new ServiceException("key值不能为空!");
} Long res = 0L;
JedisPool pool = null;
Jedis jedis = null;
try{
pool = getPool();
jedis = pool.getResource();
res = jedis.expire(key, t);
}catch (Exception e){
e.printStackTrace();
}finally {
if(jedis != null){
jedis.close();
}
}
return res;
} public static Map<String, Object> beanToMap(Object obj) {
if(obj == null){
return null;
}
Map<String, Object> map = new HashMap<String, Object>();
try {
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor property : propertyDescriptors) {
String key = property.getName(); // 过滤class属性
if (!key.equals("class")) {
// 得到property对应的getter方法
Method getter = property.getReadMethod();
Object value = getter.invoke(obj); map.put(key, value);
}
}
} catch (Exception e) {
System.out.println("transBean2Map Error " + e);
}
return map;
}
redis 下载及使用的更多相关文章
- Redis下载及安装部署
官网介绍:Redis is an open source advanced key-value store.It is often referred to as a data structure se ...
- (1)redis下载编译
一.redis下载编译 这里没什么好说的 用的版本是redis-2.8.17 1)redis-server是可执行程序 2)mian函数在redis.c里面 3)如果要修改调试 这届在src目录下 ...
- centos6.5环境Redis下载及编译安装
centos6.5环境Redis下载及编译安装 1:官方站点: http://redis.io/download 下载最新版或者最新stable版 2:解压源码并进入目录 tar -zxvf redi ...
- Redis 下载 安装
Redis 官网 https://redis.io/ github 主页 https://github.com/antirez/redis 下载页面 https://redis.io/download ...
- Windows上redis下载与安装
一.redis是什么 非关系型内存数据库,以key-value的形式将数据储存在内存中.Mysql是关系型数据库,数据是保存在硬盘中 二.redis下载安装 1.要安装Redis,首先要获取安装包. ...
- Redis 下载与配置window服务
1.Redis下载 Git下载地址:https://github.com/MicrosoftArchive/redis/releases 2.配置Window服务 步骤一:在 Redis目录 输入 c ...
- redis基础:redis下载安装与配置,redis数据类型使用,redis常用指令,jedis使用,RDB和AOF持久化
知识点梳理 课堂讲义 课程计划 1. REDIS 入 门 (了解) (操作) 2. 数据类型 (重点) (操作) (理解) 3. 常用指令 (操作) 4. Jedis (重点) (操作) ...
- Redis下载安装与配置(windows)
一.Redis下载 Redis官网建议使用Linux进行部署,未提供windows版本的Redis,但微软开发和维护着Windows64版本的Redis. Windows64版本的Redis下载地址: ...
- redis 下载启动,设置、查询超时时间
1.定义 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted ...
随机推荐
- 多个Class作用于同一个元素的结果分析
多个Class作用于同一个元素的结果分析 多个class作用于同一个元素出现样式冲突,因为权重相同,结果如何呢 [代码] <html> <head> <sty ...
- 如何在eclipse中通过Juit进行单元测试
1.什么是Junit Junit即单元测试,是JAVA语言的单元测试框架,是对程序的一个方法所进行的测试 一般都是由程序员自己通过Junit来进行测试,因此单元测试也叫程序员测试: 如果测试人员熟悉程 ...
- runtime运行时
/** * Describes the instance variables declared by a class. * * @param cls The class to inspect. * @ ...
- spring-boot 文件上传获取不到File原因,MultipartHttpServletRequest.getFiles为空
以下是spring-boot的处理方式,其他可参考处理具体问题:1.CommonsMultipartResolver解析不到request中的文件流2.Controller方法参数MultipartH ...
- 【Java EE 学习 75 上】【数据采集系统第七天】【二进制运算实现权限管理】【权限分析和设计】
一.权限计算相关分析 1.如何存储权限 首先说一下权限保存的问题,一个系统中最多有多少权限呢?一个大的系统中可能有成百上千个权限需要管理.怎么保存这么多的权限?首先,我们使用一个数字中的一位保存一种权 ...
- opencv中的SIFT,SURF,ORB,FAST 特征描叙算子比较
opencv中的SIFT,SURF,ORB,FAST 特征描叙算子比较 参考: http://wenku.baidu.com/link?url=1aDYAJBCrrK-uk2w3sSNai7h52x_ ...
- [leetcode] 题型整理之图论
图论的常见题目有两类,一类是求两点间最短距离,另一类是拓扑排序,两种写起来都很烦. 求最短路径: 127. Word Ladder Given two words (beginWord and end ...
- 转:工具类之SpannableStringUtils(相信你会爱上它)
这个工具类真是构思了良久才设计出来,采用了建造者模式,然后你们就可以用链式调用了,talk is cheap, let me show the demo. demo code 有没有心动一下哈,下面就 ...
- 大话css之display的Block未解之谜(一)
用了几年的css了,css中inline | block |inline-block|table|flex从来没有做过系统的整理和分析,网上的分析文章也很多,零散. 今天有空,就在这做一下整理分析 b ...
- linux 常用命令
//创建目录mkdir//创建中间没有路径的文件夹mkdir -p //删除文件rm//强制删除文件rm -f//删除目录rmdir//删除多个目录rmdir -p //输出当前环境根路径echo $ ...