diff --git a/ThunderSoft_redisapi/README.md b/ThunderSoft_redisapi/README.md new file mode 100644 index 000000000..7e3aa5fa0 --- /dev/null +++ b/ThunderSoft_redisapi/README.md @@ -0,0 +1,22 @@ +# unitApi +libraryDemo_redis针对于redis数据存储进行一些列的操作 + + +## 逻辑详情 + +### +setvalue +getValue + + +## 使用步骤说明 + +1. 应用引用依赖库 +2. 配置应用配置参数 (无需配置) +3. 逻辑调用示例截图 + +参考文档 + +## 应用演示链接 + +[使用了本依赖库的制品应用链接] diff --git a/ThunderSoft_redisapi/lib/nasl-metadata-collector-0.7.0.jar b/ThunderSoft_redisapi/lib/nasl-metadata-collector-0.7.0.jar new file mode 100644 index 000000000..f085868b0 Binary files /dev/null and b/ThunderSoft_redisapi/lib/nasl-metadata-collector-0.7.0.jar differ diff --git a/ThunderSoft_redisapi/pom.xml b/ThunderSoft_redisapi/pom.xml new file mode 100644 index 000000000..d853a9cfe --- /dev/null +++ b/ThunderSoft_redisapi/pom.xml @@ -0,0 +1,90 @@ + + + 4.0.0 + com.netease + redisapi + 1.0.0 + redis工具类 + + org.springframework.boot + spring-boot-starter-parent + 2.2.9.RELEASE + + + + 8 + 8 + UTF-8 + 3.3 + + + + + nasl-metadata-collector + com.netease.lowcode + 0.7.0 + true + system + ${project.basedir}/lib/nasl-metadata-collector-0.7.0.jar + + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-test + test + + + junit + junit + test + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.3.0 + + + jar-with-dependencies + + false + + + + make-assembly + package + + single + + + + + + com.netease.lowcode + nasl-metadata-maven-plugin + 1.3.0 + + true + + + + + archive + + + + + + + diff --git "a/ThunderSoft_redisapi/redis\345\267\245\345\205\267\344\276\235\350\265\226\345\214\205.docx" "b/ThunderSoft_redisapi/redis\345\267\245\345\205\267\344\276\235\350\265\226\345\214\205.docx" new file mode 100644 index 000000000..61eb899f8 Binary files /dev/null and "b/ThunderSoft_redisapi/redis\345\267\245\345\205\267\344\276\235\350\265\226\345\214\205.docx" differ diff --git a/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/LibraryAutoScan.java b/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/LibraryAutoScan.java new file mode 100644 index 000000000..49bf81c1c --- /dev/null +++ b/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/LibraryAutoScan.java @@ -0,0 +1,8 @@ +package com.netease.lib.redistemplatetool; + +/** + * 依赖库自动扫描类 + * @author system + */ +public class LibraryAutoScan { +} diff --git a/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/config/RedisConfig.java b/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/config/RedisConfig.java new file mode 100644 index 000000000..f90ef3200 --- /dev/null +++ b/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/config/RedisConfig.java @@ -0,0 +1,101 @@ +package com.netease.lib.redistemplatetool.config; + +import com.netease.lowcode.core.annotation.NaslConfiguration; +import org.springframework.context.annotation.Configuration; + + +@Configuration +public class RedisConfig { + /** + * redis 地址。redis模式多选一,按需配置。无用的配置可空 + */ + @NaslConfiguration + public String redisHost; + /** + * redis 端口 + */ + @NaslConfiguration + public String redisPort; + + /** + * redis密码 + */ + @NaslConfiguration + public String redisPassword; + /** + * redis sentinel 主节点 + */ + @NaslConfiguration + public String redisSentinelMaster; + /** + * redis sentinel 节点 + */ + @NaslConfiguration + public String redisSentinelNodes; + /** + * redis哨兵密码 + */ + @NaslConfiguration + private String redisSentinelPassword; + /** + * redis cluster 节点 + */ + @NaslConfiguration + public String redisClusterNodes; + /** + * redis slave 地址 + */ + @NaslConfiguration + public String redisSlaveHost; + /** + * redis slave 端口 + */ + @NaslConfiguration + public String redisSlavePort; + /** + * Redis 数据库索引 + */ + @NaslConfiguration + private String redisDatabase; + + /** + * 连接超时时间,默认为 0,单位为毫秒。 + */ + @NaslConfiguration + private String springRedisTimeout; + /** + * 是否启用 SSL 连接,默认为 false。 + */ + @NaslConfiguration + private String springRedisSsl; + /** + * 连接池最大连接数。 + */ + @NaslConfiguration + private String springRedisLettucePoolMaxActive; + /** + * 连接池中的最大空闲连接。 + */ + @NaslConfiguration + private String springRedisLettucePoolMaxIdle; + /** + * 连接池中的最小空闲连接。 + */ + @NaslConfiguration + private String springRedisLettucePoolMinIdle; + /** + * 执行命令的超时时间,默认为 3 秒。 + */ + @NaslConfiguration + private String springRedisLettuceCommandTimeout; + /** + * 关闭连接时的超时时间,默认为 100 毫秒。 + */ + @NaslConfiguration + private String springRedisLettuceShutdownTimeout; + /** + * 设置客户端名称。 + */ + @NaslConfiguration + private String springRedisLettuceClientName; +} diff --git a/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/spring/LibDemoRedisSpringEnvironmentConfiguration.java b/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/spring/LibDemoRedisSpringEnvironmentConfiguration.java new file mode 100644 index 000000000..f6d755788 --- /dev/null +++ b/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/spring/LibDemoRedisSpringEnvironmentConfiguration.java @@ -0,0 +1,16 @@ +package com.netease.lib.redistemplatetool.spring; + +import com.netease.lib.redistemplatetool.LibraryAutoScan; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * 加入spring环境配置(在spring.factories中指定) + */ +@Configuration +@ComponentScan(basePackageClasses = LibraryAutoScan.class) +public class LibDemoRedisSpringEnvironmentConfiguration { + public LibDemoRedisSpringEnvironmentConfiguration() { + System.out.println("LibDemoRedisSpringEnvironmentConfiguration"); + } +} diff --git a/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/util/LibDemoRedisEnvironmentMapperPostProcessor.java b/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/util/LibDemoRedisEnvironmentMapperPostProcessor.java new file mode 100644 index 000000000..079ff8c14 --- /dev/null +++ b/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/util/LibDemoRedisEnvironmentMapperPostProcessor.java @@ -0,0 +1,66 @@ +package com.netease.lib.redistemplatetool.util; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.annotation.Order; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.util.StringUtils; + +import java.util.HashMap; +import java.util.Map; + +@Order +public class LibDemoRedisEnvironmentMapperPostProcessor implements EnvironmentPostProcessor { + private static final Map REDIS_CONFIG_MAPPER = new HashMap<>(); + + //File文件类型 数据权限 + static { + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.redisHost", "spring.redis.host"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.redisPort", "spring.redis.port"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.redisDatabase", "spring.redis.database"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.redisPassword", "spring.redis.password"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.redisSentinelMaster", "spring.redis.sentinel.master"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.redisSentinelNodes", "spring.redis.sentinel.nodes"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.redisClusterNodes", "spring.redis.cluster.nodes"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.redisSlaveHost", "spring.redis.slave.host"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.redisSlavePort", "spring.redis.slave.port"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.redisSentinelPassword", "spring.redis.sentinel.password"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.springRedisTimeout", "spring.redis.timeout"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.springRedisSsl", "spring.redis.ssl"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.springRedisLettucePoolMaxActive", "spring.redis.lettuce.pool.max-active"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.springRedisLettucePoolMaxIdle", "spring.redis.lettuce.pool.max-idle"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.springRedisLettucePoolMinIdle", "spring.redis.lettuce.pool.min-idle"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.springRedisLettuceCommandTimeout", "spring.redis.lettuce.command-timeout"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.springRedisLettuceShutdownTimeout", "spring.redis.lettuce.shutdown-timeout"); + REDIS_CONFIG_MAPPER.put("extensions.redisapi.custom.springRedisLettuceClientName", "spring.redis.lettuce.client-name"); + } + + /** + * Post-process the given {@code environment}. + * + * @param environment the environment to post-process + * @param application the application to which the environment belongs + */ + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + Map mapperProperties = new HashMap<>(); + REDIS_CONFIG_MAPPER.forEach((key, value) -> { + if (environment.containsProperty(value)) { + return; + } + if (environment.containsProperty(key)) { + String property = environment.getProperty(key); + if (!StringUtils.isEmpty(property)) { + mapperProperties.put(value, property); + } + } + }); + + if (mapperProperties.isEmpty()) { + return; + } + environment.getPropertySources().addLast(new MapPropertySource("REDIS_CONFIG_MAPPER", mapperProperties)); + } + +} \ No newline at end of file diff --git a/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/util/RedisTool.java b/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/util/RedisTool.java new file mode 100644 index 000000000..16e955424 --- /dev/null +++ b/ThunderSoft_redisapi/src/main/java/com/netease/lib/redistemplatetool/util/RedisTool.java @@ -0,0 +1,356 @@ +package com.netease.lib.redistemplatetool.util; + +import com.netease.lowcode.core.annotation.NaslLogic; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.ListOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + + +@Component +public class RedisTool { + + @Autowired + public RedisTemplate redisTemplate; + + /** + * 设置 Redis 中指定 key 的值为指定字符串 + * + * @param key Redis 中的键 + * @param value Redis 中的值 + */ + @NaslLogic + public String setValueTimeOut(String key, String value, Long timeout) { + ValueOperations ops = redisTemplate.opsForValue(); + ops.set(key, value, timeout, TimeUnit.SECONDS); + return ops.get(key); + } + + /** + * 设置 Redis 中指定 key 的值为指定字符串 + * + * @param key Redis 中的键 + * @param value Redis 中的值 + */ + @NaslLogic + public String setValue(String key, String value) { + ValueOperations ops = redisTemplate.opsForValue(); + ops.set(key, value); + return ops.get(key); + } + + @NaslLogic + public List getListValue(String key) { + ListOperations ops = redisTemplate.opsForList(); + return ops.range(key, 0, -1); + } + + @NaslLogic + public List setListValue(String key, List value) { + ListOperations ops = redisTemplate.opsForList(); + ops.rightPushAll(key, value); + return ops.range(key, 0, -1); + } + + /** + * 获取 Redis 中指定 key 的值 + * + * @param key Redis 中的键 + * @return Redis 中的值 + */ + @NaslLogic + public String getValue(String key) throws NullPointerException { + ValueOperations ops = redisTemplate.opsForValue(); + return ops.get(key); + } + + /** + * 如果 Redis 中不存在指定 key,则设置为指定字符串 + * + * @param key Redis 中的键 + * @param value Redis 中的值 + * @return 如果设置成功,返回 true,否则返回 false + */ + @NaslLogic + public Boolean setIfAbsent(String key, String value) { + ValueOperations ops = redisTemplate.opsForValue(); + return ops.setIfAbsent(key, value); + } + + /** + * 如果 Redis 中不存在指定 key,则设置为指定字符串,并设置过期时间 + * + * @param key Redis 中的键 + * @param value Redis 中的值 + * @param timeout 过期时间 + * @return 如果设置成功,返回 true,否则返回 false + */ + @NaslLogic + public Boolean setIfAbsentWithExpire(String key, String value, Long timeout) { + ValueOperations ops = redisTemplate.opsForValue(); + return ops.setIfAbsent(key, value, timeout, TimeUnit.SECONDS); + } + + /** + * 如果 Redis 中存在指定 key,则设置为指定字符串,并设置过期时间 + * + * @param key Redis 中的键 + * @param value Redis 中的值 + * @param timeout 过期时间 + * @return 如果设置成功,返回 true,否则返回 false + */ + @NaslLogic + public Boolean setIfPresentWithExpire(String key, String value, Long timeout) { + ValueOperations ops = redisTemplate.opsForValue(); + return ops.setIfPresent(key, value, timeout, TimeUnit.SECONDS); + } + + /** + * 将 Redis 中指定 key 的值增加指定的整数 delta + * + * @param key Redis 中的键 + * @param delta 增加的整数值 + * @return 增加后的结果值 + */ + @NaslLogic + public Long incrementLong(String key, Long delta) { + ValueOperations ops = redisTemplate.opsForValue(); + return ops.increment(key, delta); + } + + /** + * 将 Redis 中指定 key 的值增加指定的浮点数 delta + * + * @param key Redis 中的键 + * @param delta 增加的浮点数值 + * @return 增加后的结果值 + */ + @NaslLogic + public Double incrementDoulbe(String key, Double delta) { + ValueOperations ops = redisTemplate.opsForValue(); + return ops.increment(key, delta); + } + + /** + * 删除 Redis 中指定的 key + * + * @param key Redis 中的键 + */ + @NaslLogic + public Boolean deleteKey(String key) { + return redisTemplate.delete(key); + } + + public String convertToJsonString(String input) { + return input.replace("\\", ""); + } + + /** + * 将多个键值对设置到 Redis 哈希表中,并返回更新后的哈希表。 + * + * @param hashKey 哈希表的键 + * @param keyValueMap 包含要设置到 Redis 哈希表中的键值对的 Map + * @return 表示更新后 Redis 哈希表的 Map + */ + @NaslLogic + public Map setHashValues(String hashKey, Map keyValueMap) { + HashOperations ops = redisTemplate.opsForHash(); + for (Map.Entry entry : keyValueMap.entrySet()) { + ops.put(hashKey, entry.getKey(), entry.getValue()); + } + return ops.entries(hashKey); + } + + /** + * 获取 Redis 哈希表中指定 key 的所有域和值 + * + * @param hashKey 哈希表的 key + * @return 包含所有域和值的 Map 对象,键为域,值为对应的值 + */ + @NaslLogic + public Map getHashValuesWithNoKey(String hashKey) { + HashOperations ops = redisTemplate.opsForHash(); + return ops.entries(hashKey); + } + + /** + * 从 Redis 哈希表中获取多个键对应的值,并返回一个包含这些键值对的 Map。 + * + * @param hashKey 哈希表的键 + * @param fieldKeys 包含要获取值的键的列表 + * @return 一个包含指定键值对的 Map + */ + @NaslLogic + public Map getHashValues(String hashKey, List fieldKeys) { + HashOperations ops = redisTemplate.opsForHash(); + List values = ops.multiGet(hashKey, fieldKeys); + + Map resultMap = new HashMap<>(); + for (int i = 0; i < fieldKeys.size(); i++) { + String key = fieldKeys.get(i); + String value = values.get(i); + if (value != null) { + resultMap.put(key, value); + } + } + return resultMap; + } + + /** + * 根据传入的 key 和 field 列表查询 Redis 中对应的值,并将查询结果存储在一个 Map> 中 + * + * @param keyAndFieldsMap Map,其中 key 是 Redis 中的 key,value 是要查询的 field + * @return Map>,其中外层的 key 是 Redis 中的 key,内层的 key-value 对是 field 和它对应的值 + */ + @NaslLogic + public Map> getHashValuesByKeysAndField(Map keyAndFieldsMap) { + HashOperations ops = redisTemplate.opsForHash(); + Map> resultMap = new HashMap<>(); + + for (Map.Entry entry : keyAndFieldsMap.entrySet()) { + String hashKey = entry.getKey(); + String fieldKey = entry.getValue(); + String value = ops.get(hashKey, fieldKey); + if (value != null) { + Map fieldMap = new HashMap<>(); + fieldMap.put(fieldKey, value); + resultMap.put(hashKey, fieldMap); + } + } + + return resultMap; + } + + /** + * 根据传入的 key 和 field 列表查询 Redis 中对应的值,并将查询结果存储在一个 Map> 中 + * + * @param keyAndFieldsMap Map>,其中 key 是 Redis 中的 key,value 是要查询的 hashMap 中对应的 field 的列表 + * @return Map>,其中外层的 key 是 Redis 中的 key,内层的 key-value 对是 field 和它对应的值 + */ + @NaslLogic + public Map> getHashValuesByKeysAndFiledList(Map> keyAndFieldsMap) { + HashOperations ops = redisTemplate.opsForHash(); + Map> resultMap = new HashMap<>(); + + for (Map.Entry> entry : keyAndFieldsMap.entrySet()) { + String hashKey = entry.getKey(); + List fieldKeys = entry.getValue(); + + List values = ops.multiGet(hashKey, fieldKeys); + + Map fieldMap = new HashMap<>(); + for (int i = 0; i < fieldKeys.size(); i++) { + String key = fieldKeys.get(i); + String value = values.get(i); + if (value != null) { + fieldMap.put(key, value); + } + } + + resultMap.put(hashKey, fieldMap); + } + + return resultMap; + } + + /** + * 删除 Redis 哈希表中指定的一个或多个域 + * + * @param hashKey 哈希表的 key + * @param keys 要删除的一个或多个域 + * @return 被删除的域的数量 + */ + @NaslLogic + public Long deleteHashfieldKeys(String hashKey, List keys) { + HashOperations ops = redisTemplate.opsForHash(); + String[] fieldKeysArray = keys.toArray(new String[0]); + return ops.delete(hashKey, fieldKeysArray); + } + + /** + * 检查 Redis 哈希表中是否存在指定的域 + * + * @param hashKey 哈希表的 key + * @param fieldKey 要检查的域 + * @return 如果存在,返回 true;否则,返回 false + */ + @NaslLogic + public Boolean hashfieldKeyExists(String hashKey, String fieldKey) { + HashOperations ops = redisTemplate.opsForHash(); + return ops.hasKey(hashKey, fieldKey); + } + + /** + * 将指定的域设置为指定的值,仅当域不存在时才进行设置 + * + * @param hashKey 哈希表的 key + * @param fieldKey 要设置的域 + * @param value 要设置的值 + * @return 如果设置成功,返回 true;如果域已存在,不进行设置,返回 false + */ + @NaslLogic + public Boolean hashSetIfNotExists(String hashKey, String fieldKey, String value) { + HashOperations ops = redisTemplate.opsForHash(); + return ops.putIfAbsent(hashKey, fieldKey, value); + } + + /** + * 获取 Redis 哈希表中域的数量 + * + * @param hashKey 哈希表的 key + * @return 哈希表中域的数量 + */ + @NaslLogic + public Long hashSize(String hashKey) { + HashOperations ops = redisTemplate.opsForHash(); + return ops.size(hashKey); + } + + /** + * 获取 Redis 哈希表中的所有域 + * + * @param hashKey 哈希表的 key + * @return 哈希表中的所有域 + */ + @NaslLogic + public List hashKeys(String hashKey) { + HashOperations ops = redisTemplate.opsForHash(); + return new ArrayList<>(ops.keys(hashKey)); + } + + /** + * 将 Redis 哈希表中指定域的值增加指定的增量 + * + * @param hashKey 哈希表的 key + * @param fieldKey 要增加值的域 + * @param increment 增量 + * @return 增加指定增量后域的值 + */ + @NaslLogic + public Long hashIncrementBy(String hashKey, String fieldKey, Long increment) { + HashOperations ops = redisTemplate.opsForHash(); + return ops.increment(hashKey, fieldKey, increment); + } + + /** + * 将 Redis 哈希表中指定域的值增加指定的浮点数增量 + * + * @param hashKey 哈希表的 key + * @param fieldKey 要增加值的域 + * @param increment 增量 + * @return 增加指定增量后域的值 + */ + @NaslLogic + public Double hashIncrementByFloat(String hashKey, String fieldKey, Double increment) { + HashOperations ops = redisTemplate.opsForHash(); + return ops.increment(hashKey, fieldKey, increment); + } +} diff --git a/ThunderSoft_redisapi/src/main/resources/META-INF/spring.factories b/ThunderSoft_redisapi/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..5ccf33109 --- /dev/null +++ b/ThunderSoft_redisapi/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.env.EnvironmentPostProcessor=com.netease.lib.redistemplatetool.util.LibDemoRedisEnvironmentMapperPostProcessor +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.netease.lib.redistemplatetool.spring.LibDemoRedisSpringEnvironmentConfiguration diff --git a/ThunderSoft_redisapi/src/test/java/com/netease/CheckTest.java b/ThunderSoft_redisapi/src/test/java/com/netease/CheckTest.java new file mode 100644 index 000000000..29ec18561 --- /dev/null +++ b/ThunderSoft_redisapi/src/test/java/com/netease/CheckTest.java @@ -0,0 +1,41 @@ +package com.netease; + + +import com.netease.lib.redistemplatetool.spring.LibDemoRedisSpringEnvironmentConfiguration; +import com.netease.lib.redistemplatetool.util.RedisTool; +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.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.test.context.junit4.SpringRunner; + +//@SpringBootTest(classes = LibDemoRedisSpringEnvironmentConfiguration.class) +//@RunWith(SpringRunner.class) +public class CheckTest { + @Autowired + public RedisTemplate redisTemplate; + @Autowired + private RedisConnectionFactory redisConnectionFactory; + @Autowired + private RedisTool redisTool; +// @Test + public void queryDataTest() { + ValueOperations operations = redisTemplate.opsForValue(); + String redisKey = operations.get("redis-key"); + System.out.println("redisKey:" + redisKey); + operations.set("redis-key", "hello world"); + redisKey = operations.get("redis-key"); + System.out.println("redisKey:" + redisKey); + // 对redis的key的value进行加1 + redisTemplate.opsForValue().increment("increment-key"); + System.out.println("当前使用的redis客户端是: " + redisConnectionFactory.getConnection()); + String value = redisTool.getValue("redis-key"); + System.out.println(value); + redisTool.setValue("redis-key", "hello world2222"); + value = redisTool.getValue("redis-key"); + System.out.println(value); + } +} diff --git a/ThunderSoft_redisapi/src/test/resources/application.yml b/ThunderSoft_redisapi/src/test/resources/application.yml new file mode 100644 index 000000000..64cc284c6 --- /dev/null +++ b/ThunderSoft_redisapi/src/test/resources/application.yml @@ -0,0 +1,8 @@ +extensions: + libraryDemo_redis: + custom: + redisHost: + redisPort: + redisPassword: + redisDatabase: +