redis的安装直接跳过

1.注册redis服务

在DOM窗口下,进入redis的安装目录(可以先进入安装目录,然后shift+右键,选择在此处打开powershell窗口),

输入命令:

redis-server --service-install redis.windows-service.conf --loglevel verbose;

开启redis服务

打开DOM窗口,输入命令:

redis-server --service-start

关闭redis服务

打开DOM窗口,输入命令:

redis-server --service-stop

到此,redis在windows下的配置便告完成。

2.jedis api的使用

maven引入jedis的依赖:

        <dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.1.0</version>
</dependency> <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>

redis.properties文件定义了jedis连接池的一些参数和redis服务器的信息

#config for redis
#最大连接数
redis.pool.maxActive=512
#最大空闲连接数
redis.pool.maxIdle=100
#最大等待等待时间
redis.pool.maxWait=100000
redis.pool.testOnBorrow=true
redis.pool.testOnReturn=true
redis.ip=127.0.0.1
redis.port=6379
#设置过期时间为2小时,超过过期时间会自动删除key-value
redis.expire=7200
注意:在实际的项目文件中不允许出现中文注解

RedisProvider类定义如何获得与redis的连接和释放与redis的连接

public class RedisProvider {

    //protected static final Logger LOG = LoggerFactory.getLogger(RedisProvider.class);
protected static JedisPool jedispool;
protected static int EXPIRE = 130;
static{
ResourceBundle bundle = ResourceBundle.getBundle("redis");
if (bundle == null) {
throw new IllegalArgumentException(
"[redis.properties] is not found!");
} EXPIRE = Integer.valueOf(bundle.getString("redis.expire")); JedisPoolConfig jedisconfig = new JedisPoolConfig();
jedisconfig.setMaxActive(Integer.valueOf(bundle
.getString("redis.pool.maxActive")));
jedisconfig.setMaxIdle(Integer.valueOf(bundle
.getString("redis.pool.maxIdle")));
jedisconfig.setMaxWait(Long.valueOf(bundle
.getString("redis.pool.maxWait")));
jedisconfig.setTestOnBorrow(Boolean.valueOf(bundle
.getString("redis.pool.testOnBorrow")));
jedisconfig.setTestOnReturn(Boolean.valueOf(bundle
.getString("redis.pool.testOnReturn")));
jedispool = new JedisPool(jedisconfig, bundle.getString("redis.ip"),
Integer.valueOf(bundle.getString("redis.port")), 100000);
} /*获取资源*/
public static Jedis getJedis() {
Jedis jedis = null;
try {
jedis = jedispool.getResource();
} catch (JedisConnectionException jce) {
ExceptionUtil.getTrace(jce);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
ExceptionUtil.getTrace(e);
}
jedis = jedispool.getResource();
}
return jedis;
} /*释放资源*/
public static void returnResource(JedisPool pool, Jedis jedis) {
if (jedis != null) {
pool.returnResource(jedis);
}
}
}
/*资源jedis理解为连接。jedispool理解为连接池*/

RedisHelper定义了利用jedis连接堆redis服务器端进行的各种操作,这里出于应用的需要,只实现了基本的set和get操作,更多的jedis操作可见它的api:

https://tool.oschina.net/uploads/apidocs/

public class RedisHelper extends RedisProvider {

    /**
* Set the string value as value of the key. Default settings at save
* time(2000s)
*
* @param key
* @param value
* @return
*/
public static String set(String key, String value) {
Jedis jedis = null;
String rtn = null;
try {
jedis = getJedis();
rtn = jedis.setex(key, EXPIRE, value);
} catch (Exception e) {
//LOG.error(ExceptionUtil.getTrace(e));
jedispool.returnBrokenResource(jedis);
} finally {
returnResource(jedispool, jedis);
}
return rtn;
} public static String get(String key) {
Jedis jedis = null;
String rtn = null;
try {
jedis = getJedis();
rtn = jedis.get(key);
} catch (Exception e) {
//LOG.error(ExceptionUtil.getTrace(e));
jedispool.returnBrokenResource(jedis);
} finally {
returnResource(jedispool, jedis);
}
return rtn;
} }

windows下redis的配置和jedis api的最基本的使用的更多相关文章

  1. Windows下Redis安装配置和使用注意事项

    Windows下Redis安装配置和使用注意事项 一:下载 下载地址: https://github.com/microsoftarchive/redis/releases 文件介绍: 本文以3.2. ...

  2. windows下Redis主从复制配置(报错:Invalid argument during startup: unknown conf file parameter : slaveof)

    主从复制配置中的遇到的异常: Invalid argument during startup: unknown conf file parameter :  slaveof 把Redis文件夹复制两份 ...

  3. windows下安装和配置redis

    1.windows下安装和配置redis 1.1 下载: 官网(linux下载地址):https://redis.io/ Windows系统下载地址:https://github.com/MSOpen ...

  4. windows下redis安装和配置

    windows下redis安装和配置 redis介绍 Redis是一个开源,高级的键值存储和一个适用的解决方案,用于构建高性能,可扩展的Web应用程序. Redis有三个主要特点,使它优越于其它键值数 ...

  5. < python音频库:Windows下pydub安装配置、过程出现的问题及常用API >

    < python音频库:Windows下pydub安装配置.过程出现的问题及常用API > 背景 刚从B站上看过倒放挑战之后也想体验下,心血来潮一个晚上完成了基本的实现.其中倒放与播放部分 ...

  6. windows下Redis安装及利用java操作Redis

    一.windows下Redis安装 1.Redis下载 下载地址:https://github.com/MicrosoftArchive/redis 打开下载地址后,选择版本 然后选择压缩包 下载 R ...

  7. 最新Windows下Redis集群

    实现简单的Windows下Redis集群配置,以下是配置过程中出现的几个问题: [1]逐个启动7001 7002 7003 7004 7005 7006节点时,出现createing server T ...

  8. Windows下Redis的使用

    Redis介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,和Memcached类似,它支持存储的value类型相对更多,包括st ...

  9. windows下Redis 主从读写分离部署

    原文:windows下Redis 主从读写分离部署 1.可直接下载window下的运行文件(下面这个链接) 也可以浏览github 查看相应的版本说明文档 https://github.com/Ser ...

随机推荐

  1. Python心得--新手开发注意

    1  注释 介绍 在大多数编程语言当中,注释都是一项非常有用的功能.我们开始编写的程序之中都只包含Python代码,但是随着程序越来越大.越来越复杂,就应在其中添加说明,对你解决问题的方法进行大致的阐 ...

  2. 题解 P2622 【关灯问题II】

    题目 感觉大佬们的代码在读入上的处理比本蒟蒻优秀多了,于是,一个AFO蒟蒻弱弱地提出一下自己的看法 [分析] 首先,对于 \(n\) 那么小,肯定是状压啦 对于读入,本蒟蒻开了两个数组来储存每个按钮的 ...

  3. python Mysql数据库连接池组件封装(转载)

    以前一直在用Java来开发,数据库连接池等都是有组件封装好的,直接使用即可,最近在尝试Python的学习,碰到了和数据库打交道的问题,和数据库打交道我们都知道,数据库连接池必不可少,不然要么就是程序异 ...

  4. [Security] Web Security Essentials

    In this course, we'll learn how to exploit and then mitigate several common Web Security Vulnerabili ...

  5. IP首部检验和的计算和举例

    IP首部校验和 首部校验和(16位)字段只检验数据报的首部,不检验数据部分.这里不采用CRC检验码而采用简单的计算方法. 发送端 首先将检验和置零,求首部数据的补码和(包含检验和),因为为零,所以无影 ...

  6. android中shape的使用(android:angle小解)

    本文参考http://kofi1122.blog.51cto.com/2815761/521605和http://blog.csdn.net/qizi329/article/details/63098 ...

  7. 注意力机制和Seq2seq模型

    注意力机制 在"编码器-解码器(seq2seq)"⼀节⾥,解码器在各个时间步依赖相同的背景变量(context vector)来获取输⼊序列信息.当编码器为循环神经⽹络时,背景变量 ...

  8. sklearn 模型评估

    原文链接 http://d0evi1.com/sklearn/model_evaluation/ 预测值:pred 真实值:y_test #### 直接用平均值 ``` mean(pred == y_ ...

  9. node.js实现http服务器进行访问

    步骤:一.安装node;二.新建一个文件夹目录(根目录),里面再新建一个server.js文件:三.打开命令行界面,进入文件夹目录然后输入命令node server.js;四.然后就可以在浏览器上通过 ...

  10. D. Minimax Problem(二分+二进制)

    D. Minimax Problem time limit per test 5 seconds memory limit per test 512 megabytes input standard ...