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. .net APP接口

    编写APP接口首先要搭建测试环境,在实际开发中APP对于大多数公司来说都是选择外包,并不是公司内部人员负责,遇到事情不可能时时进行沟通和交流,也不能写每一个接口都要双方及时确认.个人经历是双方确认AP ...

  2. plt画log图

    import matplotlib.pyplot as plt import math import numpy as np x = np.arange(-0.85,0.95,0.05) #获得函数结 ...

  3. php封装一个接口类

    <?phpClass Response{//返回数据 public static function show($code,$message='',$data='',$type = 'json', ...

  4. Go语言-并发模式-资源池实例(pool)

    Go语言并发模式 利用goroutine和channel进行go的并发模式,实现一个资源池实例(<Go语言实战>书中实例稍作修改) 资源池可以存储一定数量的资源,用户程序从资源池获取资源进 ...

  5. UML-领域模型的精化

    拙劣的分类和错误的概括是混乱生活的祸根.--H.G.Wells的总结 1.is-a原则 子类定义的成员变量.方法与超类必须一致.即:不能多,也不能少. 子类是“一种”超类.CreditPayment是 ...

  6. vue项目 首页开发 part3

    da当拖动图标时候,只有上部分可以,下部分无响应 swiper 为根页面引用,其中的css为独立,点击swiper标签可以看见其包裹区域只有部分 那么需要修改 就需要穿透样式 外部  >> ...

  7. SWIG 3 中文手册——9. SWIG 库

    目录 9 SWIG 库 9.1 %include 指令与库搜索路径 9.2 C 数组与指针 9.2.1 cpointer.i 9.2.2 carrays.i 9.2.3 cmalloc.i 9.2.4 ...

  8. goweb-模板引擎

    模板引擎 Go 为我们提供了 text/template 库和 html/template 库这两个模板引擎,模板引 擎通过将数据和模板组合在一起生成最终的 HTML,而处理器负责调用模板引擎并将引 ...

  9. Java线程——线程习题(一)子线程执行10次后,主线程再运行5次,这样交替执行三遍

    题目:子线程执行10次后,主线程再运行5次,这样交替执行三遍 代码如下: package com.itheima.gan; /** * 子线程执行10次后,主线程再运行5次,这样交替执行三遍 * @a ...

  10. 吴裕雄--天生自然 PHP开发学习:MySQL 插入多条数据

    <?php $servername = "localhost"; $username = "root"; $password = "admin& ...