{"id":33811,"date":"2023-10-29T10:13:56","date_gmt":"2023-02-12T16:42:33","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/"},"modified":"2024-05-04T06:32:12","modified_gmt":"2024-05-03T22:32:12","slug":"%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/","title":{"rendered":"\u4f7f\u7528SpringBoot\u548cRedis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09"},"content":{"rendered":"<p>\u5e94\u7528\u73af\u5883\uff1a\u5b58\u50a8\u4ee4\u724c\u3001&#8230;<\/p>\n<h2>\u6b65\u9aa41\uff1a\u6dfb\u52a0Redis\u7684\u4f9d\u8d56\u5173\u7cfb<\/h2>\n<pre class=\"post-pre\"><code>    &lt;dependency&gt;\r\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;spring-boot-starter-data-redis&lt;\/artifactId&gt;\r\n    &lt;\/dependency&gt;\r\n<\/code><\/pre>\n<h2>\u6b65\u9aa42\uff1a\u521b\u5efa\u4e00\u4e2aRedis\u5305\uff0c\u5e76\u6dfb\u52a03\u4e2aRedis\u7c7b\u3002<\/h2>\n<details>\u4e00\u7b49\u6587\u4ef6\uff1aFastJsonRedisSerializer<br \/>\nimport com.alibaba.fastjson.JSON;<br \/>\nimport com.alibaba.fastjson.parser.ParserConfig;<br \/>\nimport com.alibaba.fastjson.serializer.SerializerFeature;<br \/>\nimport com.fasterxml.jackson.databind.JavaType;<br \/>\nimport com.fasterxml.jackson.databind.type.TypeFactory;<br \/>\nimport org.springframework.data.redis.serializer.RedisSerializer;<br \/>\nimport org.springframework.data.redis.serializer.SerializationException;import java.nio.charset.Charset;<\/p>\n<p>\/**<br \/>\n* \u4f7f\u7528FastJson\u7684Redis\u5e8f\u5217\u5316\u5668<br \/>\n*<br \/>\n* \u4f5c\u8005\uff1a\u4e00\u7b49\u6587\u4ef6<br \/>\n*\/<br \/>\npublic class FastJsonRedisSerializer implements RedisSerializer<br \/>\n{<\/p>\n<p>public static final Charset DEFAULT_CHARSET = Charset.forName(&#8220;UTF-8&#8221;);<\/p>\n<p>private Class clazz;<\/p>\n<p>static<br \/>\n{<br \/>\nParserConfig.getGlobalInstance().setAutoTypeSupport(true);<br \/>\n}<\/p>\n<p>public FastJsonRedisSerializer(Class clazz)<br \/>\n{<br \/>\nsuper();<br \/>\nthis.clazz = clazz;<br \/>\n}<\/p>\n<p>@Override<br \/>\npublic byte[] serialize(T t) throws SerializationException<br \/>\n{<br \/>\nif (t == null)<br \/>\n{<br \/>\nreturn new byte[0];<br \/>\n}<br \/>\nreturn JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);<br \/>\n}<\/p>\n<p>@Override<br \/>\npublic T deserialize(byte[] bytes) throws SerializationException<br \/>\n{<br \/>\nif (bytes == null || bytes.length &lt;= 0)<br \/>\n{<br \/>\nreturn null;<br \/>\n}<br \/>\nString str = new String(bytes, DEFAULT_CHARSET);<\/p>\n<p>return JSON.parseObject(str, clazz);<br \/>\n}<\/p>\n<p>protected JavaType getJavaType(Class&lt;?&gt; clazz)<br \/>\n{<br \/>\nreturn TypeFactory.defaultInstance().constructType(clazz);<br \/>\n}<br \/>\n}<\/p>\n<\/details>\n<details>Second class: RedisCache<br \/>\nimport org.springframework.beans.factory.annotation.Autowired;<br \/>\nimport org.springframework.data.redis.core.BoundSetOperations;<br \/>\nimport org.springframework.data.redis.core.HashOperations;<br \/>\nimport org.springframework.data.redis.core.RedisTemplate;<br \/>\nimport org.springframework.data.redis.core.ValueOperations;<br \/>\nimport org.springframework.stereotype.Component;import java.util.*;<br \/>\nimport java.util.concurrent.TimeUnit;<\/p>\n<p>@SuppressWarnings(value = { &#8220;unchecked&#8221;, &#8220;rawtypes&#8221; })<br \/>\n@Component<br \/>\npublic class RedisCache<br \/>\n{<br \/>\n@Autowired<br \/>\npublic RedisTemplate redisTemplate;<\/p>\n<p>\/**<br \/>\n* Cache basic objects, Integer, String, entity classes, etc.<br \/>\n*<br \/>\n* @param key Cached key values<br \/>\n* @param value The value of the cache<br \/>\n*\/<br \/>\npublic void setCacheObject(final String key, final T value)<br \/>\n{<br \/>\nredisTemplate.opsForValue().set(key, value);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* Cache basic objects, Integer, String, entity classes, etc.<br \/>\n*<br \/>\n* @param key \u7f13\u5b58\u7684\u952e\u503c<br \/>\n* @param value \u7f13\u5b58\u7684\u503c<br \/>\n* @param timeout \u65f6\u95f4<br \/>\n* @param timeUnit \u65f6\u95f4\u9897\u7c92\u5ea6<br \/>\n*\/<br \/>\npublic void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit)<br \/>\n{<br \/>\nredisTemplate.opsForValue().set(key, value, timeout, timeUnit);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u6709\u52b9\u6642\u9593\u306e\u8a2d\u5b9a<br \/>\n*<br \/>\n* @param key Redis\u952e<br \/>\n* @param timeout \u8d85\u65f6\u65f6\u95f4<br \/>\n* @return true=\u8bbe\u7f6e\u6210\u529f\uff1bfalse=\u8bbe\u7f6e\u5931\u8d25<br \/>\n*\/<br \/>\npublic boolean expire(final String key, final long timeout)<br \/>\n{<br \/>\nreturn expire(key, timeout, TimeUnit.SECONDS);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u6709\u52b9\u6642\u9593\u306e\u8a2d\u5b9a<br \/>\n*<br \/>\n* @param key Redis\u952e<br \/>\n* @param timeout \u8d85\u65f6\u65f6\u95f4<br \/>\n* @param unit \u65f6\u95f4\u5355\u4f4d<br \/>\n* @return true=\u8bbe\u7f6e\u6210\u529f\uff1bfalse=\u8bbe\u7f6e\u5931\u8d25<br \/>\n*\/<br \/>\npublic boolean expire(final String key, final long timeout, final TimeUnit unit)<br \/>\n{<br \/>\nreturn redisTemplate.expire(key, timeout, unit);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u57fa\u672c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3059\u308b\u3002<br \/>\n*<br \/>\n* @param key \u7f13\u5b58\u952e\u503c<br \/>\n* @return \u7f13\u5b58\u952e\u503c\u5bf9\u5e94\u7684\u6570\u636e<br \/>\n*\/<br \/>\npublic T getCacheObject(final String key)<br \/>\n{<br \/>\nValueOperations&lt;String, T&gt; operation = redisTemplate.opsForValue();<br \/>\nreturn operation.get(key);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u500b\u5225\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u524a\u9664\u3059\u308b<br \/>\n*<br \/>\n* @param key<br \/>\n*\/<br \/>\npublic boolean deleteObject(final String key)<br \/>\n{<br \/>\nreturn redisTemplate.delete(key);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u524a\u9664<br \/>\n*<br \/>\n* @param collection \u591a\u4e2a\u5bf9\u8c61<br \/>\n* @return<br \/>\n*\/<br \/>\npublic long deleteObject(final Collection collection)<br \/>\n{<br \/>\nreturn redisTemplate.delete(collection);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u30ad\u30e3\u30c3\u30b7\u30e5\u30ea\u30b9\u30c8\u30c7\u30fc\u30bf<br \/>\n*<br \/>\n* @param key \u7f13\u5b58\u7684\u952e\u503c<br \/>\n* @param dataList \u5f85\u7f13\u5b58\u7684List\u6570\u636e<br \/>\n* @return \u7f13\u5b58\u7684\u5bf9\u8c61<br \/>\n*\/<br \/>\npublic long setCacheList(final String key, final List dataList)<br \/>\n{<br \/>\nLong count = redisTemplate.opsForList().rightPushAll(key, dataList);<br \/>\nreturn count == null ? 0 : count;<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u305f\u30ea\u30b9\u30c8\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3059\u308b<br \/>\n*<br \/>\n* @param key \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u30ad\u30fc\u30d0\u30ea\u30e5\u30fc<br \/>\n* @return \u30ad\u30fc\u30d0\u30ea\u30e5\u30fc\u306b\u5bfe\u5fdc\u3059\u308b\u30ad\u30e3\u30c3\u30b7\u30e5\u30c7\u30fc\u30bf<br \/>\n*\/<br \/>\npublic List getCacheList(final String key)<br \/>\n{<br \/>\nreturn redisTemplate.opsForList().range(key, 0, -1);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u30ad\u30e3\u30c3\u30b7\u30e5\u30bb\u30c3\u30c8<br \/>\n*<br \/>\n* @param key \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u30ad\u30fc\u30d0\u30ea\u30e5\u30fc<br \/>\n* @param dataSet \u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u305f\u30c7\u30fc\u30bf<br \/>\n* @return \u30c7\u30fc\u30bf\u3092\u30ad\u30e3\u30c3\u30b7\u30e5\u3059\u308b\u305f\u3081\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<br \/>\n*\/<br \/>\npublic BoundSetOperations&lt;String, T&gt; setCacheSet(final String key, final Set dataSet)<br \/>\n{<br \/>\nBoundSetOperations&lt;String, T&gt; setOperation = redisTemplate.boundSetOps(key);<br \/>\nIterator it = dataSet.iterator();<br \/>\nwhile (it.hasNext())<br \/>\n{<br \/>\nsetOperation.add(it.next());<br \/>\n}<br \/>\nreturn setOperation;<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u305f\u30bb\u30c3\u30c8\u3092\u53d6\u5f97\u3059\u308b<br \/>\n*<br \/>\n* @param key<br \/>\n* @return<br \/>\n*\/<br \/>\npublic Set getCacheSet(final String key)<br \/>\n{<br \/>\nreturn redisTemplate.opsForSet().members(key);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u30ad\u30e3\u30c3\u30b7\u30e5Map<br \/>\n*<br \/>\n* @param key<br \/>\n* @param dataMap<br \/>\n*\/<br \/>\npublic void setCacheMap(final String key, final Map&lt;String, T&gt; dataMap)<br \/>\n{<br \/>\nif (dataMap != null) {<br \/>\nredisTemplate.opsForHash().putAll(key, dataMap);<br \/>\n}<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u305fMap\u306e\u53d6\u5f97<br \/>\n*<br \/>\n* @param key<br \/>\n* @return<br \/>\n*\/<br \/>\npublic Map&lt;String, T&gt; getCacheMap(final String key)<br \/>\n{<br \/>\nreturn redisTemplate.opsForHash().entries(key);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* Hash\u3078\u306e\u30c7\u30fc\u30bf\u306e\u9810\u3051\u5165\u308c<br \/>\n*<br \/>\n* @param key Redis key<br \/>\n* @param hKey Hash key<br \/>\n* @param value key<br \/>\n*\/<br \/>\npublic void setCacheMapValue(final String key, final String hKey, final T value)<br \/>\n{<br \/>\nredisTemplate.opsForHash().put(key, hKey, value);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u30cf\u30c3\u30b7\u30e5\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b<br \/>\n*<br \/>\n* @param key Redis Key<br \/>\n* @param hKey Hash Key<br \/>\n* @return Hash\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<br \/>\n*\/<br \/>\npublic T getCacheMapValue(final String key, final String hKey)<br \/>\n{<br \/>\nHashOperations&lt;String, String, T&gt; opsForHash = redisTemplate.opsForHash();<br \/>\nreturn opsForHash.get(key, hKey);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* Hash\u304b\u3089\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3059\u308b<br \/>\n*<br \/>\n* @param key<br \/>\n* @param hkey<br \/>\n*\/<br \/>\npublic void delCacheMapValue(final String key, final String hkey)<br \/>\n{<br \/>\nHashOperations hashOperations = redisTemplate.opsForHash();<br \/>\nhashOperations.delete(key, hkey);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* \u8907\u6570\u306e\u30cf\u30c3\u30b7\u30e5\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b<br \/>\n*<br \/>\n* @param key Redis\u30ad\u30fc<br \/>\n* @param hKeys \u30cf\u30c3\u30b7\u30e5\u30ad\u30fc\u30b3\u30ec\u30af\u30b7\u30e7\u30f3<br \/>\n* @return \u30cf\u30c3\u30b7\u30e5\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30ec\u30af\u30b7\u30e7\u30f3<br \/>\n*\/<br \/>\npublic List getMultiCacheMapValue(final String key, final Collection<object width=\"300\" height=\"150\">hKeys){return redisTemplate.opsForHash().multiGet(key, hKeys);}    \/*** \u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u305f\u57fa\u672c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u4e00\u89a7\u306e\u53d6\u5f97** @param pattern \u6587\u5b57\u5217\u306e\u63a5\u982d\u8f9e* @return \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30b9\u30c8*\/public Collection<string> keys(final String pattern){return redisTemplate.keys(pattern);}}<\/string><\/p>\n<details>The third Class file\uff1aRedisConfig\u8a2d\u5b9a\u30af\u30e9\u30b9import 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.StringRedisSerializer;@Configurationpublic class RedisConfig {@Bean@SuppressWarnings(value = { &#8220;unchecked&#8221;, &#8220;rawtypes&#8221; })public RedisTemplate&lt;Object, Object&gt; redisTemplate(RedisConnectionFactory connectionFactory){RedisTemplate&lt;Object, Object&gt; template = new RedisTemplate&lt;&gt;();template.setConnectionFactory(connectionFactory);FastJsonRedisSerializer serializer = new FastJsonRedisSerializer(Object.class);\/\/ StringRedisSerializer \u3092\u4f7f\u7528\u3057\u3066 redis \u306e\u30ad\u30fc\u5024\u3092\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u304a\u3088\u3073\u30c7\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3059\u308btemplate.setKeySerializer(new StringRedisSerializer());template.setValueSerializer(serializer);\/\/ Hash\u306e\u30ad\u30fc\u3082StringRedisSerializer\u3067\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3057\u307e\u3059\u3002template.setHashKeySerializer(new StringRedisSerializer());template.setHashValueSerializer(serializer);template.afterPropertiesSet();return template;}}<\/details>\n<h1>\u6b65\u9aa43\uff1a\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0Redis\u8bbe\u7f6e\u3002<\/h1>\n<pre class=\"post-pre\"><code>#yml\/yaml :\r\n\r\n# Redis\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9(\u30c7\u30d5\u30a9\u30eb\u30c8\u306f0)\r\nspring:\r\n  redis:\r\n    # Redis\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9(\u30c7\u30d5\u30a9\u30eb\u30c8\u306f0)\r\n    database: 0\r\n    # Redis\u30b5\u30fc\u30d0\u30fc\u306e\u30a2\u30c9\u30ec\u30b9\r\n    host: 127.0.0.1\r\n    # Redis\u30b5\u30fc\u30d0\u63a5\u7d9a\u30dd\u30fc\u30c8\r\n    port: 6379\r\n    jedis:\r\n      pool:\r\n        # \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u30d7\u30fc\u30eb\u3078\u306e\u6700\u5927\u63a5\u7d9a\u6570\uff08\u7121\u5236\u9650\u3092\u793a\u3059\u306b\u306f\u8ca0\u306e\u5024\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\uff09\r\n        max-active: 8\r\n        # \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u30d7\u30fc\u30eb\u306e\u30d6\u30ed\u30c3\u30af\u5f85\u3061\u6642\u9593\u306e\u6700\u5927\u5024\uff08\u7121\u5236\u9650\u3092\u793a\u3059\u306b\u306f\u8ca0\u306e\u5024\u3092\u4f7f\u7528\u3059\u308b\uff09\r\n        max-wait: 1\r\n        # \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u30d7\u30fc\u30eb\u306e\u6700\u5927\u7a7a\u304d\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u6570\r\n        max-idle: 8\r\n        # \u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u30d7\u30fc\u30eb\u306e\u6700\u5c0f\u7a7a\u304d\u63a5\u7d9a\u6570\r\n        min-idle: 0\r\n    # \u63a5\u7d9a\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\uff08\u30df\u30ea\u79d2\uff09\r\n    timeout: 5000\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>#Properties:\r\n\r\nspring.redis.database=0\r\nspring.redis.host=127.0.0.1\r\nspring.redis.port=6379\r\nspring.redis.jedis.pool.max-active=8\r\nspring.redis.jedis.pool.max-wait=1\r\nspring.redis.jedis.pool.max-idle=8\r\nspring.redis.jedis.pool.min-idle=0\r\nspring.redis.timeout=5000\r\n<\/code><\/pre>\n<h1>\u6b65\u9aa44\uff1a\u4e0b\u8f7d\u5e76\u6253\u5f00Redis\u3002<\/h1>\n<div>                            <img decoding=\"async\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d198137434c4406c096d1\/11-0.png\" class=\"post-images\" alt=\"image\" title=\"\" \/><\/div>\n<h1>\u6b65\u9aa4\u4e94\uff1a\u6d4b\u8bd5\u4f7f\u7528<\/h1>\n<p>\u9996\u5148\uff0c\u5728Spring Boot\u7684\u6d4b\u8bd5\u7c7b\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7@Autowired\u6ce8\u89e3\u5f15\u5165RedisCache\u3002\u901a\u8fc7\u8c03\u7528\u8be5\u5bf9\u8c61\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u64cd\u4f5cRedis\u6570\u636e\u5e93\u3002<\/p>\n<blockquote><p>\u8bf7\u7528\u4e2d\u6587\u5c06\u4ee5\u4e0b\u5185\u5bb9\u8fdb\u884c\u91ca\u4e49\uff0c\u53ea\u63d0\u4f9b\u4e00\u4e2a\u9009\u9879\uff1a1. &#8220;The weather is very hot today.&#8221;<\/p><\/blockquote>\n<pre class=\"post-pre\"><code>@Autowired\r\nprivate RedisCache redisCache;\r\n\r\n@Test\r\nvoid TextRedisXX() {\r\n    redisCache.setCacheObject(\"hhh\", \"123\");\r\n    String str = redisCache.getCacheObject(\"hhh\");\r\n    System.out.println(str);\r\n}\r\n<\/code><\/pre>\n<p>Outcome: \u7ed3\u679c<\/p>\n<div>                            <img decoding=\"async\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d198137434c4406c096d1\/17-0.png\" class=\"post-images\" alt=\"image\" title=\"\" \/><\/div>\n<p>\u8fd9\u662f\u4e00\u79cd\u7528\u4e8e\u83b7\u53d6\u8d85\u8fc7redisCache.getCacheObject(&#8220;hhh&#8221;)\u88abIDEA\u8c03\u7528\u4e4b\u5916\u7684\u65b9\u6cd5\u3002\u540c\u65f6\uff0c\u89e3\u538b\u7f29\u6587\u4ef6\u540e\u6253\u5f00redis-cli.exe\uff0c\u5e76\u8f93\u5165get hhh\u6307\u4ee4\u6765\u83b7\u53d6\u503c\u3002<\/p>\n<div>                            <img decoding=\"async\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d198137434c4406c096d1\/19-0.png\" class=\"post-images\" alt=\"image\" title=\"\" \/><\/div>\n<p>\u5982\u679c\u60a8\u6709\u4efb\u4f55\u7591\u95ee\u6216\u9700\u8981\u4e0e\u6211\u5206\u4eab\u539f\u521b\u5185\u5bb9\uff0c\u8bf7\u968f\u610f\u7559\u4e0b\u8bc4\u8bba\u3002<\/object><\/p>\n<\/details>\n","protected":false},"excerpt":{"rendered":"<p>\u5e94\u7528\u73af\u5883\uff1a\u5b58\u50a8\u4ee4\u724c\u3001&#8230; \u6b65\u9aa41\uff1a\u6dfb\u52a0Redis\u7684\u4f9d\u8d56\u5173\u7cfb &lt;dependency&gt; &#038; [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-33811","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528SpringBoot\u548cRedis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528springboot\u548credis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528SpringBoot\u548cRedis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09\" \/>\n<meta property=\"og:description\" content=\"\u5e94\u7528\u73af\u5883\uff1a\u5b58\u50a8\u4ee4\u724c\u3001&#8230; \u6b65\u9aa41\uff1a\u6dfb\u52a0Redis\u7684\u4f9d\u8d56\u5173\u7cfb &lt;dependency&gt; &amp; [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528springboot\u548credis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-12T16:42:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-03T22:32:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d198137434c4406c096d1\/11-0.png\" \/>\n<meta name=\"author\" content=\"\u6e05, \u626c\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u626c\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/\",\"name\":\"\u4f7f\u7528SpringBoot\u548cRedis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-02-12T16:42:33+00:00\",\"dateModified\":\"2024-05-03T22:32:12+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528SpringBoot\u548cRedis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\",\"name\":\"\u6e05, \u626c\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u626c\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528SpringBoot\u548cRedis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528springboot\u548credis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528SpringBoot\u548cRedis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09","og_description":"\u5e94\u7528\u73af\u5883\uff1a\u5b58\u50a8\u4ee4\u724c\u3001&#8230; \u6b65\u9aa41\uff1a\u6dfb\u52a0Redis\u7684\u4f9d\u8d56\u5173\u7cfb &lt;dependency&gt; & [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528springboot\u548credis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-02-12T16:42:33+00:00","article_modified_time":"2024-05-03T22:32:12+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d198137434c4406c096d1\/11-0.png"}],"author":"\u6e05, \u626c","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u626c","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/","name":"\u4f7f\u7528SpringBoot\u548cRedis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-02-12T16:42:33+00:00","dateModified":"2024-05-03T22:32:12+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528SpringBoot\u548cRedis\u7684\u6559\u7a0b\uff08\u51715\u6bb5\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461","name":"\u6e05, \u626c","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","caption":"\u6e05, \u626c"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8springboot%e5%92%8credis%e7%9a%84%e6%95%99%e7%a8%8b%ef%bc%88%e5%85%b15%e6%ae%b5%ef%bc%89\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/33811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=33811"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/33811\/revisions"}],"predecessor-version":[{"id":96689,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/33811\/revisions\/96689"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=33811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=33811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=33811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}