下面讲解下windows上面redis的安装与使用,以及在springboot环境下,怎么使用API来快速上手redis。Redis官方是没有提供Windows版本的,因为目前Linux版本已经相当稳定,而且用户量很大,无需开发windows版本,反而会带来兼容性等问题。

文章目录

  • windows上面redis的安装与使用
  • redis在springboot程序中的使用

windows上面redis的安装与使用

redis在github上面的下载地址


启动服务器之后的场景

在客户端对redis进行操作


redis在springboot程序中的使用

导入依赖

<!-- redis-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- SpringBootTest-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId>
<!-- <scope>test</scope>-->
</dependency>

Java配置

package cn.wideth.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;/*** 编写配置类,构造RedisTemplate* 这个springboot已经帮我们配了,* 但是默认object,我想改成string*/
@Configuration
public class RedisConfig {@Beanpublic RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {RedisTemplate<String, Object> template = new RedisTemplate<>();template.setConnectionFactory(factory);// 设置key的序列化方式template.setKeySerializer(RedisSerializer.string());// 设置value的序列化方式template.setValueSerializer(RedisSerializer.json());// 设置hash的key的序列化方式template.setHashKeySerializer(RedisSerializer.string());// 设置hash的value的序列化方式template.setHashValueSerializer(RedisSerializer.json());template.afterPropertiesSet();return template;}}

在程序中调用相关的API来进行程序操作

package cn.wideth.util.other;import cn.wideth.PdaAndIpadApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;@RunWith(SpringRunner.class)
@SpringBootTest()
@ContextConfiguration(classes = PdaAndIpadApplication.class)
public class TestRedis {@Autowiredprivate RedisTemplate<String, Object> redisTemplate;@Testpublic void operateStr(){System.out.println(redisTemplate);// 存入key为hello ,value为worldredisTemplate.opsForValue().set("hello","world");// 获取key为helloString username = (String) redisTemplate.opsForValue().get("hello");System.out.println(username);}}

程序结果

Redis的安装与使用相关推荐

  1. Linux下redis的安装(适用centos)

    转自:https://www.cnblogs.com/_popc/p/3684835.html 第一部分:安装redis  希望将redis安装到此目录 1 /usr/local/redis 希望将安 ...

  2. Redis 入门安装(Linux)

    Redis 入门安装(Linux) 备注:该案例讲解基于CentOS6.5.Reids3.2.8 Redis 官网 中文地址:http://www.redis.cn/ 英文地址:https://red ...

  3. Redis初学:1(NoSQL的简介和Redis的安装)

    什么是NoSQL NoSQL数据库意即:Not Only SQL 不仅仅是SQL,它区别于传统的关系型数据库,储存方式按照的是key-value的形式存储数据,这个我们可以联想到我们以前学过的Hash ...

  4. Linux下redis的安装

    原文出处:http://www.cnblogs.com/_popc/p/3684835.html 第一步:redis的安装 希望将redis安装到此目录 1 /usr/local/redis 希望将安 ...

  5. Redis、Redis+sentinel安装(Ubuntu 14.04下Redis安装及简单测试)

    Ubuntu下Redis安装两种安装方式: 1.apt-get方式 步骤: 以root权限登录,切换到/usr目录下. 接下来输入命令,apt-get install redis-server,如图: ...

  6. redis的安装以及常见运用场景

    2019独角兽企业重金招聘Python工程师标准>>> 1.redis的安装 Window 下安装 下载地址:https://github.com/MSOpenTech/redis/ ...

  7. 浅谈Redis及其安装配置

    一.Redis的介绍 二.Redis的安装配置 三.Redis的配置文件说明 四.Redis的简单操作 简介: Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型. ...

  8. linux redis数据库安装配置,Linux系统中redis的安装配置步骤

    Linux系统中redis的安装配置步骤 发布时间:2020-06-23 10:13:36 来源:亿速云 阅读:87 作者:Leah 这篇文章将为大家详细讲解有关Linux系统中redis的安装配置步 ...

  9. CentOS下Redis的安装

    CentOS下Redis的安装 前言 安装Redis需要知道自己需要哪个版本,有针对性的安装,比如如果需要redis GEO这个地理集合的特性,那么redis版本就不能低于3.2版本,由于这个特性是3 ...

  10. 七、redis的安装(linux)

    1.系统环境 [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.8.2003 (Core) 2.Linux安装yum ...

最新文章

  1. php常用比较函数区别表
  2. 青稞大义 -RISV-V
  3. 8. String to Integer
  4. [ATF]-smc指令详解
  5. linux消息队列操作
  6. VTK:Utilities之ShepardMethod
  7. SSD300网络结构(pytorch)+多尺度训练与测试
  8. SpringBoot 自带工具类~断言
  9. util.java_TelnetUtil.java
  10. 聚能聊每周精选 第十一期
  11. 在控制台中操作MYSQL数据库步骤以及一些小问题
  12. identity 1 1 mysql_identity在mysql中怎么用啊以下代码的错误在哪里
  13. expert php and mysql_Expert PHP and Mysql
  14. SMBUS和i2cBus,PMBus 区别
  15. ANSYS 有限元分析 网格划分
  16. lte网络测试用什么软件,LTE_测试软件使用教程.doc
  17. 我们都应该停止三种测试实践
  18. AndroidSDK目录和源码目录详解
  19. PHP面试要点---mysql
  20. Jenkins-API

热门文章

  1. How to Fix Git Push Time Consuming Issue in a Big Team?
  2. 更新FreeBSD Ports的方法
  3. LPI 认证考试介绍
  4. javascript浮点数学习总结之0.1+0.2
  5. 计算机网络常见英文缩写
  6. NSByteCountFormatter
  7. 分享无限:偷拍IBM power 720内部外部图片
  8. office2007右键doc,xls
  9. 如何提高数据库的访问效率?
  10. 21种代码的“坏味道”