国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務器之家 - 編程語言 - Java教程 - spring boot結合Redis實現工具類的方法示例

spring boot結合Redis實現工具類的方法示例

2021-06-17 11:02蘭茗翔 Java教程

這篇文章主要介紹了spring boot結合Redis實現工具類的方法示例,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

自己整理了 spring boot 結合 redis 的工具類

引入依賴

?
1
2
3
4
<dependency>
  <groupid>org.springframework.boot</groupid>
  <artifactid>spring-boot-starter-data-redis</artifactid>
</dependency>

加入配置

?
1
2
3
4
5
6
# redis數據庫索引(默認為0
spring.redis.database=0
# redis服務器地址
spring.redis.host=localhost
# redis服務器連接端口
spring.redis.port=6379

實現代碼

這里用到了 靜態類工具類中 如何使用 @autowired

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.lmxdawn.api.common.utils;
 
import java.util.collection;
import java.util.set;
import java.util.concurrent.timeunit;
 
import javax.annotation.postconstruct;
 
import org.springframework.beans.factory.annotation.autowired;
import org.springframework.data.redis.core.redistemplate;
import org.springframework.stereotype.component;
 
/**
 * 緩存操作類
 */
@component
public class cacheutils {
  @autowired
  private redistemplate<string, string> redistemplate;
 
  // 維護一個本類的靜態變量
  private static cacheutils cacheutils;
 
  @postconstruct
  public void init() {
    cacheutils = this;
    cacheutils.redistemplate = this.redistemplate;
  }
 
  /**
   * 將參數中的字符串值設置為鍵的值,不設置過期時間
   * @param key
   * @param value 必須要實現 serializable 接口
   */
  public static void set(string key, string value) {
    cacheutils.redistemplate.opsforvalue().set(key, value);
  }
 
  /**
   * 將參數中的字符串值設置為鍵的值,設置過期時間
   * @param key
   * @param value 必須要實現 serializable 接口
   * @param timeout
   */
  public static void set(string key, string value, long timeout) {
    cacheutils.redistemplate.opsforvalue().set(key, value, timeout, timeunit.seconds);
  }
 
  /**
   * 獲取與指定鍵相關的值
   * @param key
   * @return
   */
  public static object get(string key) {
    return cacheutils.redistemplate.opsforvalue().get(key);
  }
 
  /**
   * 設置某個鍵的過期時間
   * @param key 鍵值
   * @param ttl 過期秒數
   */
  public static boolean expire(string key, long ttl) {
    return cacheutils.redistemplate.expire(key, ttl, timeunit.seconds);
  }
 
  /**
   * 判斷某個鍵是否存在
   * @param key 鍵值
   */
  public static boolean haskey(string key) {
    return cacheutils.redistemplate.haskey(key);
  }
 
  /**
   * 向集合添加元素
   * @param key
   * @param value
   * @return 返回值為設置成功的value數
   */
  public static long sadd(string key, string... value) {
    return cacheutils.redistemplate.opsforset().add(key, value);
  }
 
  /**
   * 獲取集合中的某個元素
   * @param key
   * @return 返回值為redis中鍵值為key的value的set集合
   */
  public static set<string> sgetmembers(string key) {
    return cacheutils.redistemplate.opsforset().members(key);
  }
 
  /**
   * 將給定分數的指定成員添加到鍵中存儲的排序集合中
   * @param key
   * @param value
   * @param score
   * @return
   */
  public static boolean zadd(string key, string value, double score) {
    return cacheutils.redistemplate.opsforzset().add(key, value, score);
  }
 
  /**
   * 返回指定排序集中給定成員的分數
   * @param key
   * @param value
   * @return
   */
  public static double zscore(string key, string value) {
    return cacheutils.redistemplate.opsforzset().score(key, value);
  }
 
  /**
   * 刪除指定的鍵
   * @param key
   * @return
   */
  public static boolean delete(string key) {
    return cacheutils.redistemplate.delete(key);
  }
 
  /**
   * 刪除多個鍵
   * @param keys
   * @return
   */
  public static long delete(collection<string> keys) {
    return cacheutils.redistemplate.delete(keys);
  }
}

相關地址

github 地址:https://github.com/lmxdawn/vue-admin-java

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://segmentfault.com/a/1190000017131552

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 国内外成人激情免费视频 | 日本二区视频 | 一级片视频在线观看 | 99草视频 | 激情毛片| 欧美日韩在线综合 | 久久亚洲欧美日韩精品专区 | 午夜精品视频 | 国产欧美精品区一区二区三区 | 亚洲国产成人av好男人在线观看 | 精品久久久久一区二区国产 | a视频在线| 日韩一区二区在线观看 | 毛片在线视频 | 中文字幕在线观看一区二区 | 亚洲欧美一区二区三区四区 | 久热精品免费 | av在线大全| 日韩高清中文字幕 | 精品日韩| 日本不卡免费新一二三区 | 热精品| bxbx成人精品一区二区三区 | 免费一级 国产 | 国产麻豆一区二区三区 | 精品久久久久久亚洲综合网 | 一级电影在线观看 | 久久久婷| 欧美精品v国产精品v日韩精品 | 亚欧毛片 | 久久精彩免费视频 | 国产精品美女久久久久aⅴ国产馆 | 亚洲美女一区 | 中文字幕最新在线 | 蜜臀精品 | 中文在线日韩 | 免费网站看v片在线a | 一区二区三区视频在线观看 | 久久合| 欧美激情五月 | 日韩av在线电影 |