redis

1. Introduction

REmote DIctionary Server (Redis) is a key-value storage system written by Salvatore Sanfilippo .

Redis is an open source log-type , Key-Value database written in ANSI C language , compliant with BSD protocol , supporting network, memory-based and persistent , and provides APIs in multiple languages .

It is often referred to as a data structure server because the value can be of type String, Hash, List, Sets, and Sorted Sets .

Redis official website: https://redis.io/

Redis online test: http://try.redis.io/

 

Second, install

Redis installation please check

https://www.runoob.com/redis/redis-install.html

 

Third, the configuration in springboot

#REDIS配置
# Redis服务器地址
spring.redis.host=127.0.0.1
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=30
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=10000
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=10
# 连接超时时间(毫秒) 10秒
spring.redis.timeout=10000

4. Import of JAR package in java development

 <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>

V. Use in controller

 private static JedisPool pool;
 private static Jedis jedis;

@ResponseBody
    @RequestMapping(value = "/getMobileLocateReal")
    public void getMobileLocateReal(HttpServletRequest request, HttpServletResponse response) throws Exception {
        pool = new JedisPool(new JedisPoolConfig(), "127.0.0.1");
        jedis = pool.getResource();
//取值
String str = "jsapi_ticket=" + jedis.get(Constants.jsapi_ticket) + "&noncestr=" + noncestr + "&timestamp=" + timestamp + "&url=" + url;

//放值
jedis.set(Constants.accessToken, accessToken.getAccessToken());
        jedis.set(Constants.expiresin, accessToken.getExpiresin() + "");
}

This is just a simple application.For more redis functions or function extensions, you can check the official API.

Published 51 original articles · Like 4 · Visitor 7902

Guess you like

Origin blog.csdn.net/u012174809/article/details/103013321