Redis对于Linux是官方支持的,安装和使用没有什么好说的,普通使用按照官方指导,5分钟以内就能搞定。详情请参考:

http://redis.io/download

Redis官方是不支持windows的,只是 Microsoft Open Tech group 在 GitHub上开发了一个Win64的版本,项目地址是:

https://github.com/MSOpenTech/redis

打开以后,可以直接使用浏览器下载,或者Git克隆。

(注意: dist文件改变了下载地址: https://github.com/MSOpenTech/redis/releases )

在 Release 页面中,可以找到 msi 安装文件以及 .zip 文件(而且有3.0的beta版,请下拉查找)。

下载解压,没什么好说的,在解压后的bin目录下有以下这些文件:

  1. redis-benchmark.exe         #基准测试
  2. redis-check-aof.exe         # aof
  3. redis-check-dump.exe        # dump
  4. redis-cli.exe               # 客户端
  5. redis-server.exe            # 服务器
  6. redis.windows.conf          # 配置文件

redis配置密码

1.通过配置文件进行配置

windos方式安装的redis配置文件通常在redis.windows.conf中,打开配置文件找到

  1. #requirepass foobared


去掉行前的注释,并修改密码为所需的密码,保存文件

  1. requirepass wssjj123

进入redis目录下启动redis

redis-server.exe redis.windows.conf

这个时候尝试登录redis,发现可以登上,但是执行具体命令是提示操作不允许

尝试用密码登录并执行具体的命令看到可以成功执行

2.通过命令行进行配置

  1. redis 127.0.0.1:6379[1]> config set requirepass my_redis
  2. OK
  3. redis 127.0.0.1:6379[1]> config get requirepass
  4. 1) "requirepass"
  5. 2) "my_redis"

无需重启redis
使用第一步中配置文件中配置的老密码登录redis,会发现原来的密码已不可用,操作被拒绝

  1. redis-cli -h 127.0.0.1 -p 6379 -a myRedis
  2. redis 127.0.0.1:6379> config get requirepass
  3. (error) ERR operation not permitted

使用修改后的密码登录redis,可以执行相应操作

  1. redis-cli -h 127.0.0.1 -p 6379 -a my_redis
  2. redis 127.0.0.1:6379> config get requirepass
  3. 1) "requirepass"
  4. 2) "my_redis

尝试重启一下redis,用新配置的密码登录redis执行操作,发现新的密码失效,redis重新使用了配置文件中的密码

    1. sudo service redis restart
    2. Stopping redis-server:                                     [  OK  ]
    3. Starting redis-server:                                     [  OK  ]
    4. redis-cli -h 127.0.0.1 -p 6379 -a my_redis
    5. redis 127.0.0.1:6379> config get requirepass
    6. (error) ERR operation not permitted
    7. redis-cli -h 127.0.0.1 -p 6379 -a myRedis
    8. redis 127.0.0.1:6379> config get requirepass
    9. 1) "requirepass"
    10. 2) "myRedis"

 

redis整合Spring

1、引入jar包

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.6.1.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.2</version>
</dependency>

2、配置bean

在application.xml加入如下配置

<context:property-placeholder location="classpath:redis.properties" />

    <!-- jedis 配置 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<!-- redis服务器中心 -->
<bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="poolConfig" ref="poolConfig" />
<property name="port" value="${redis.port}" />
<property name="hostName" value="${redis.host}" />
<property name="password" value="${redis.pass}" />
<property name="timeout" value="${redis.maxWait}"></property>
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="keySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="valueSerializer">
<bean
class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
</property>
</bean> <!-- cache配置 -->
<bean id="redisUtil" class="me.shijunjie.util.RedisUtil">
<property name="redisTemplate" ref="redisTemplate" />
</bean>

其中配置文件redis一些配置数据redis.properties如下:

# Redis settings
redis.host=123.206.228.200
redis.port=6379
redis.pass=******
redis.maxIdle=300
redis.maxActive=600
redis.maxWait=1000
redis.testOnBorrow=true

3、一些工具类

(1)RedisUtil

上面的bean中,RedisUtil是用来缓存和去除数据的实例

package me.shijunjie.util;

import java.io.Serializable;
import java.util.Set;
import java.util.concurrent.TimeUnit; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations; /**
* redis cache 工具类
*
*/
public final class RedisUtil {
private Logger logger = LoggerFactory.getLogger(RedisUtil.class);
private RedisTemplate<Serializable, Object> redisTemplate; /**
* 批量删除对应的value
*
* @param keys
*/
public void remove(final String... keys) {
for (String key : keys) {
remove(key);
}
} /**
* 批量删除key
*
* @param pattern
*/
public void removePattern(final String pattern) {
Set<Serializable> keys = redisTemplate.keys(pattern);
if (keys.size() > 0)
redisTemplate.delete(keys);
} /**
* 删除对应的value
*
* @param key
*/
public void remove(final String key) {
if (exists(key)) {
redisTemplate.delete(key);
}
} /**
* 判断缓存中是否有对应的value
*
* @param key
* @return
*/
public boolean exists(final String key) {
return redisTemplate.hasKey(key);
} /**
* 读取缓存
*
* @param key
* @return
*/
public Object get(final String key) {
Object result = null;
ValueOperations<Serializable, Object> operations = redisTemplate
.opsForValue();
result = operations.get(key);
return result;
} /**
* 写入缓存
*
* @param key
* @param value
* @return
*/
public boolean set(final String key, Object value) {
boolean result = false;
try {
ValueOperations<Serializable, Object> operations = redisTemplate
.opsForValue();
operations.set(key, value);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
} /**
* 写入缓存
*
* @param key
* @param value
* @return
*/
public boolean set(final String key, Object value, Long expireTime) {
boolean result = false;
try {
ValueOperations<Serializable, Object> operations = redisTemplate
.opsForValue();
operations.set(key, value);
redisTemplate.expire(key, expireTime, TimeUnit.SECONDS);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
} public void setRedisTemplate(
RedisTemplate<Serializable, Object> redisTemplate) {
this.redisTemplate = redisTemplate;
}
}

4、执行结果:

写了一个简单的单元测试如下:

package me.shijunjie.testRedis;

import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import me.shijunjie.util.RedisUtil; public class RedisTest { private Logger logger = LoggerFactory.getLogger(RedisTest.class); private ApplicationContext context = null;
private RedisUtil redisUtil; @Before
public void before() {
System.out.println("初始化spring容器");
context = new ClassPathXmlApplicationContext("applicationContext.xml");
redisUtil = (RedisUtil) context.getBean("redisUtil");
} @Test
public void testSet() {
boolean isset = redisUtil.set("test", "hh");
System.out.println(isset);
Object value = redisUtil.get("test");
System.out.println(value);
} }

本文参照

http://blog.csdn.net/evankaka/article/details/50396325

https://github.com/cncounter/cncounter/blob/master/cncounter/src/test/resources/Redis%E6%9C%AC%E5%9C%B0%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA.md

http://blog.csdn.net/zyz511919766/article/details/42268219

Redis windows环境安装 以及 redis整合spring的更多相关文章

  1. PHP XAMPP windows环境安装扩展redis 致命错误: Class 'Redis' not found解决方法

    PHP XAMPP windows环境安装扩展redis 致命错误: Class 'Redis' not found解决方法 1.电脑需要先安装redis服务端环境,并在安装目录下打开客户端redis ...

  2. Redis Windows环境安装

    1.下载Windows 版本 Redis: https://github.com/ServiceStack/redis-windows 2. 解压文件: F:\开源代码学习\01_Redis 打开 目 ...

  3. Redis——windows环境安装redis和redis sentinel部署

    一:Redis的下载和安装 1:下载Redis Redis的官方网站Download页面,Redis提示说:Redis的正式版不支持Windows,要Windows学习Redis,请点击Learn m ...

  4. Redis:在windows环境安装Redis

    Redis:在windows环境安装Redis 第一步: 下载windows版本的Redis:https://github.com/MSOpenTech/Redis. 第二步: 在命令行执行:D:\r ...

  5. Redis Windows环境搭建

    简介 Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理.它支持字符串.哈希表.列表.集合.有序集合,位图,hyperloglogs等数据类型.内置复制 ...

  6. 【转】redis windows环境搭建

    一.下载redis windows压缩包 地址参考: https://github.com/ServiceStack/redis-windows/tree/master/downloads https ...

  7. window安装reidis完成之后,想要把数据存入redis,必须开扩展,不然报错,redis windows phpstudy 安装扩展

    redis windows phpstudy 安装扩展   1.http://windows.php.net/downloads/pecl/releases/redis/3.1.5rc1/ 2.htt ...

  8. Windows环境下启动Redis报错:Could not create server TCP listening socket 127.0.0.1:6379: bind: 操作成功完成。(已解决)

    问题描述: 今天在windows环境下启动Redis时启动失败报错: 解决方案: ①运行命令:redis-cli.exe ②退出Redis ③运行命令:redis-server.exe redis.w ...

  9. Windows环境安装tesseract-ocr 4.00并配置环境变量

    最近要做文字识别,不让直接用别人的接口,所以只能尝试去用开源的类库.tesseract-ocr是惠普公司开源的一个文字识别项目,通过它可以快速搭建图文识别系统,帮助我们开发出能识别图片的ocr系统.因 ...

随机推荐

  1. CF 1037 D. Valid BFS?

    D. Valid BFS? http://codeforces.com/contest/1037/problem/D 题意: 给一个序列,一棵树,判断能否bfs这棵树,得到这个序列. 分析: 将每个点 ...

  2. springboot+security+JWT实现单点登录

    本次整合实现的目标:1.SSO单点登录2.基于角色和spring security注解的权限控制. 整合过程如下: 1.使用maven构建项目,加入先关依赖,pom.xml如下: <?xml v ...

  3. DSP28335声音降噪(未完成)

    1. 确定使用的模块是Webrtc-NS,采集声音的芯片TLV32AIC23,实际测试发现Webrtc-NS无法使用,所以改成FIR滤波器. 从时域特性上来看,数字滤波器还可以分为有限冲激响应数字滤波 ...

  4. jquery.validate使用 - 5

    一些常用的验证脚本 不会写js了,只能从网上找一些常用的验证脚本. // 手机号码验证jQuery.validator.addMethod("mobile", function(v ...

  5. Python接口测试实战3(上)- Python操作数据库

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  6. python终端计算器,还有没其他方法?

    import sysdef lt(a, b, c ): if b == "+": return int(a)+int(c) elif b == "-": ret ...

  7. Loadrunner教程--常用操做流程

    1loadrunner压力测试一般使用流程 1.1loadrunner压力测试原理 本质就是在loadrunner上模拟多个用户同时按固定行为访问web站点.其中固定行为在loadrunner中是通过 ...

  8. 2017年4月8日Office 365 使用CSV文件导入邮件组

    国内版 第一步: Import-Module msonline Connect-MsolService 输入用户名密码 第二步: Get-MsolUser" 第三步: Set-Executi ...

  9. 二分图最大匹配模版 m√(n) 复杂度

    周大爷在比赛中搜到的黑科技二分图模版,复杂度为m√(n): 注意:点的序号要从0开始! 需要把nx,ny都赋值为n(点数) ; *; struct Edge { int v; int next; } ...

  10. [笔记] centos6.6编译安装httpd2.4.10

    系统安装包是CentOS-6.6-x86_64-minimal.iso 查看一下uname信息 [root@localhost ~]# uname -a Linux localhost.localdo ...