Redis整合Springboot實現數據共享

代碼的整體結構

  • ?RedisSessionConfig.java
package com.cc.springbootredissession.config;import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;@Configuration
@EnableRedisHttpSession
public class RedisSessionConfig {
}
  • SessionsController

?

package com.cc.springbootredissession;import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;@RestController
@RequestMapping("/sessions")
public class SessionsController {//映射到http://localhost:8093/sessions/set//設置@GetMapping("/set")public Map<String, Object> setSession(HttpServletRequest request) {Map<String, Object> map = new HashMap<>();request.getSession().setAttribute("request Url", request.getRequestURL());map.put("request Url", request.getRequestURL());return map;}//映射到http://localhost:8093/sessions/list//取值@GetMapping(value = "/list")public Object sessions (HttpServletRequest request){Map<String, Object> map = new HashMap<>();map.put("sessionId", request.getSession().getId());map.put("message", request.getSession().getAttribute("request Url"));return map;}
}
  • application.properties
spring.redis.database=0
# server host1 單機使用,對應服務器ip
spring.redis.host=192.168.133.130
# server password 密碼,如果沒有設置可不配
#spring.redis.password=
#connection port  單機使用,對應端口號
spring.redis.port=10190
# pool settings ...池配置
spring.redis.pool.max-idle=8
spring.redis.pool.min-idle=0
spring.redis.pool.max-active=8
spring.redis.pool.max-wait=-1
  • 使用命令curl -i?http://localhost:8093/sessions/set進行鏈接的設置

  • 模擬多節點,需要將文件打包,使用命令mvn package
  • 使用命令java -jar springboot-redis-session-0.0.1-SNAPSHOT.jar --server.port=8000,模擬8000端口
  • 使用命令java -jar springboot-redis-session-0.0.1-SNAPSHOT.jar --server.port=8001,模擬8001端口
  • 在瀏覽器輸入http://localhost:8000/sessions/list,查看session的id
  • 在瀏覽器輸入http://localhost:8001/sessions/list,查看session的id
  • 他們的session是一樣的,從而實現了session的共享

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/447272.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/447272.shtml
英文地址,請注明出處:http://en.pswp.cn/news/447272.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

人生什么最重要

什么最重要 20歲的人說,學習成績最重要.一次考試分數,可以把人分為三六九等.&#xff02;博士&#xff02;,&#xff02;本科&#xff02;,&#xff02;大專&#xff02;&#xff02;高職&#xff02;&#xff02;中專&#xff02;,成績好的上好學校,成績差的上差學校;成績好的…

Redis整合Springboot實現單機配置

整體結構 配置文件 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apache.org/…

撐起整個互聯網的7大開源技術

撐起整個互聯網的7大開源技術 很多人可能尚未意識到&#xff0c;我們使用的電腦中運行有開源軟件&#xff0c;手機中運行有開源軟件&#xff0c;家里的電視也運行有開源軟件&#xff0c;甚至小小的數碼產品中也運行有開源軟件&#xff0c;尤其是互聯網服務器端軟件&#xff0c…

Redis整合springboot實現哨兵模式

整體結構 RedisConfig package com.cc.springredis.config;import com.cc.springredis.RedisUtil; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.R…

Redis整合springboot實現集群模式

整體結構 Redis.config package com.cc.springredis.config;import com.cc.springredis.RedisUtil; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection…

一個窮人是從什么時候開始有錢的?

2010年&#xff0c;文野31歲那年&#xff0c;買房后第二年&#xff0c;完成了「人生中最重要的一次轉變」。 這一年&#xff0c;他在心里對自己的定位&#xff0c;從窮人變成了有錢人。 「一些人哪怕有錢了&#xff0c;心里也永遠甩不脫窮的影子。」這是我曾經在《 階段性勝…

Redis整合springboot實現消息隊列

publisher消息的發出 代碼整體的結構 publisherConfig package com.cc.springbootredispublisher.config;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.conne…

人最重要的能力是什么?

我見過很多人有能力、能成功&#xff0c;但并不幸福。人最重要的能力是什么? 人生最重要的能力是什么?我的答案是&#xff0c;隨時保持內心平靜的能力。 我開始想到的是“堅持”&#xff0c;后來我認為不對&#xff0c;“堅持”僅僅是成功所必備的能力&#xff0c;并不是人生…

Redis數據緩存

代碼的整體結構 配置文件 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apac…

hevc/265 開源項目及相關

1.X265 個是有兩個版本&#xff0c;一個是國內人搞的&#xff0c;是國外公司搞的 1.國外公司版本 只是一個編碼器&#xff0c;目前沒有支持解碼 開發語言 c web url: www.x265.org source url: https://bitbucket.org/multicoreware/x265 x265 is an open-source projec…

IPFS星際文件系統的簡介

IPFS簡介 IPFS&#xff08;InterPlanetary File System&#xff09;叫星際文件傳輸系統&#xff0c;本質是一個基于點對點的分布式超媒體分發協議&#xff0c;它整合了分布式系統&#xff0c;為所有人提供全球統一的可尋址空間&#xff0c;因為他具有良好的安全性、較高的傳輸…

ARM和NEON指令 very nice

在移動平臺上進行一些復雜算法的開發&#xff0c;一般需要用到指令集來進行加速。目前在移動上使用最多的是ARM芯片。 ARM是微處理器行業的一家知名企業&#xff0c;其芯片結構有&#xff1a;armv5、armv6、armv7和armv8系列。芯片類型有&#xff1a;arm7、arm9、arm11、corte…

IPFS下載安裝和配置

參考鏈接 因為這個網站訪問速度很慢&#xff0c;我提供了IPFS的MAC版本。有需要的查看我的資源下載。 大致流程 安裝 $ ls go-ipfs_v0.4.10_darwin-amd64.tar.gz $ tar xvfz go-ipfs_v0.4.10_darwin-amd64.tar.gz x go-ipfs/build-log x go-ipfs/install.sh x go-ipfs/ipfs…

IPFS的相關操作命令

新增文件 在桌面新建名字為1121的文件夾&#xff0c;在文件夾里面新建file.txt文件&#xff0c;在文件里面輸入數據&#xff0c;保存退出 $ pwd /Users/CHY/Desktop $ mkdir 1121 $ cd 1121/ $ vi file.txt $ cat file.txt 哈哈&#xff0c;為什么只有我不快樂 給文件輸入內容…

Neon Intrinsics各函數介紹

#ifndef __ARM_NEON__ #error You must enable NEON instructions (e.g. -mfloat-abisoftfp -mfpuneon) to use arm_neon.h #endif/*(1)、正常指令&#xff1a;生成大小相同且類型通常與操作數向量相同的結果向量&#xff1b; (2)、長指令&#xff1a;對雙字向量操作數執行運算…

npm安裝包總是失敗了的,請參考

鏡像使用方法 &#xff08;三種辦法任意一種都能解決問題&#xff0c;建議使用第三種&#xff0c;將配置寫死&#xff0c;下次用的時候配置還在&#xff09;: 1.通過config命令 npm config set registry https://registry.npm.taobao.org npm info underscore //&#xff08…

arm 開發工具比較(ADS vs RealviewMDK vs RVDS)

ADS REALVIEW MDK RVDS 公司 ARM Keil&#xff08;后被ARM收購&#xff09; ARM 版本 最新1.2 ,被RVDS取代 最新4.0 是否免費 破解情況 有 有 工程管理 CodeWarrior IDE nVision IDE Eclipse/ CodeWarrior IDE 編譯器 ARM C compiler for AD…

解決macOS Catalina(10.15)解決阻止程序運行“macOS無法驗證此App不包含惡意軟件”

在終端里面輸入如下命令 sudo spctl --master-disable 下面圖片對比執行命令前后&#xff0c;安全性與隱私 界面上顯示的差異&#xff1a;使用命令之后&#xff0c;界面變了

MSYS2 + MinGW-w64 + Git + gVim 環境配置

原文 http://dantvt.is-programmer.com/posts/63161.html 以前用 MSYS 的多&#xff0c;最近重裝系統順帶把環境重新配一下&#xff0c;發現 MSYS2 挺順手的。 一、安裝 MSYS2 先裝 MSYS2 的好處是之后可以將 $HOME 設為 /home/name/&#xff0c;再裝其他 *nix 系工具時配置…

MAC版 的最新Docker 2.2版本配置國內代理的解決辦法

點擊Docker圖標&#xff0c;選擇Preference選項&#xff0c;進行國內代理的問題 輸入內容如下 {"experimental": false,"debug": true,"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn", "https://hub-mirror.c.163.…