- 浏览: 270826 次
- 性别:
- 来自: 天津
文章分类
- 全部博客 (183)
- oracle (4)
- informix (1)
- web开发 (6)
- java (49)
- hibernate (1)
- hadoop (1)
- spring (23)
- 非技术 (8)
- ibatis2 (5)
- Linux (6)
- tomcat (14)
- nginx (7)
- dubbo (3)
- myibatis (7)
- webservice 开发 (2)
- mysql (2)
- svn (2)
- redis (7)
- 分布式技术 (17)
- zookeeper (2)
- kafka (2)
- velocity (1)
- maven (7)
- js (1)
- freemarker (1)
- Thymeleaf (3)
- 代码审计 (1)
- ibatis3 (1)
- rabbitmq (1)
最新评论
使用RedisTemplate 对redis操作时,存入的数据为明文时数据容易被盗,我了解决这个问题,我们可以对数据进行加密后再存入redis 中。具体操作如下:
1.启用缓存:
package com.tms.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tms.bean.system.client.Jackson2JsonRedisSerializerAes;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import java.lang.reflect.Method;
/**
* Redis 缓存配置
*/
@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport{
// @Bean
// public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
// RedisTemplate<String, String> redisTemplate = new RedisTemplate();
// redisTemplate.setConnectionFactory(redisConnectionFactory);
// return redisTemplate;
// }
@Bean
public KeyGenerator keyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object target, Method
method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for (Object obj : params) {
sb.append(obj.toString());
}
return sb.toString();
}
};
}
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
//明文显示
// Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new //Jackson2JsonRedisSerializer(Object.class);
//密文显示
Jackson2JsonRedisSerializerAes jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializerAes(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
cacheManager.setDefaultExpiration(60*60*24*60);//设置过期时间 (秒)
return cacheManager;
}
}
2.编写加解密类:
package com.tms.bean.system.util;
import org.apache.tomcat.util.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Created by gjp on 2017/10/11.
*/
public class AESUtil {
private static final String KEY_ALGORITHM = "AES";
private static final String DEFAULT_CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";//默认的加密算法
/**
* AES 加密操作
*
* @param content 待加密内容
* @param password 加密密码
* @return 返回Base64转码后的加密数据
*/
public static String encrypt(String content, String password) {
try {
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);// 创建密码器
byte[] byteContent = content.getBytes("utf-8");
cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(password));// 初始化为加密模式的密码器
byte[] result = cipher.doFinal(byteContent);// 加密
return Base64.encodeBase64String(result);//通过Base64转码返回
} catch (Exception ex) {
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* AES 解密操作
*
* @param content
* @param password
* @return
*/
public static String decrypt(String content, String password) {
try {
//实例化
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
//使用密钥初始化,设置为解密模式
cipher.init(Cipher.DECRYPT_MODE, getSecretKey(password));
//执行操作
byte[] result = cipher.doFinal(Base64.decodeBase64(content));
return new String(result, "utf-8");
} catch (Exception ex) {
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* AES 加密操作
*
* @param byteContent 待加密内容
* @param password 加密密码
* @return 加密字符串
*/
public static byte[] encryptbyte(byte[] byteContent, byte[] password) {
try {
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);// 创建密码器
String spwd = new String(password);
cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(spwd));// 初始化为加密模式的密码器
byte[] result = cipher.doFinal(byteContent);// 加密
return result;
} catch (Exception ex) {
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* AES 解密操作
*
* @param byteContent
* @param password
* @return 解密字符串
*/
public static byte[] decryptByte(byte[] byteContent, byte[] password) {
try {
//实例化
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
String pwd = new String(password);
//使用密钥初始化,设置为解密模式
cipher.init(Cipher.DECRYPT_MODE, getSecretKey(pwd));
//执行操作
byte[] result = cipher.doFinal(byteContent);
return result;
} catch (Exception ex) {
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* 生成加密秘钥
*
* @return
*/
private static SecretKeySpec getSecretKey(final String password) {
//返回生成指定算法密钥生成器的 KeyGenerator 对象
KeyGenerator kg = null;
try {
kg = KeyGenerator.getInstance(KEY_ALGORITHM);
//AES 要求密钥长度为 128
kg.init(128, new SecureRandom(password.getBytes()));
//生成一个密钥
SecretKey secretKey = kg.generateKey();
return new SecretKeySpec(secretKey.getEncoded(), KEY_ALGORITHM);// 转换为AES专用密钥
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public static void main(String[] args) {
String s = "789helloWORLD{name:“信息”}";
System.out.println("s:" + s);
// String s1 = AESUtil.encrypt(s, "1234");
// System.out.println("s1:" + s1);
//
// System.out.println("s2:"+AESUtil.decrypt(s1, "1234"));
try {
byte[] pwd = AESUtil.encryptbyte(s.getBytes("UTF-8"), "1234".getBytes("utf-8"));
System.out.println(new String(Base64.encodeBase64(pwd)));
byte[] oldPwd = AESUtil.decryptByte(pwd,"1234".getBytes("UTF-8"));
System.out.println(new String(oldPwd,"UTF-8"));
}catch (Exception e){
e.printStackTrace();
}
}
}
3.实现RedisSerializer接口:
package com.tms.bean.system.client;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.tms.bean.system.util.AESUtil;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import org.springframework.util.Assert;
import java.nio.charset.Charset;
/**
* Created by gjp on 2017/10/11.
*
*/
public class Jackson2JsonRedisSerializerAes<T> implements RedisSerializer<T> {
private static final String PWD = "123456789asdfghjkl";
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
private final JavaType javaType;
private ObjectMapper objectMapper = new ObjectMapper();
public Jackson2JsonRedisSerializerAes(Class<T> type) {
this.javaType = this.getJavaType(type);
}
public Jackson2JsonRedisSerializerAes(JavaType javaType) {
this.javaType = javaType;
}
public T deserialize(byte[] bytes) throws SerializationException {
if(null == bytes || bytes.length ==0) {
return null;
} else {
try {
byte[] result = AESUtil.decryptByte(bytes,PWD.getBytes(DEFAULT_CHARSET));
return this.objectMapper.readValue(result, 0, bytes.length, this.javaType);
} catch (Exception var3) {
throw new SerializationException("Could not read JSON: " + var3.getMessage(), var3);
}
}
}
public byte[] serialize(Object t) throws SerializationException {
if(t == null) {
return new byte[0];
} else {
try {
byte[] temp = this.objectMapper.writeValueAsBytes(t);
return AESUtil.encryptbyte(temp,PWD.getBytes(DEFAULT_CHARSET));
//return this.objectMapper.writeValueAsBytes(t);
} catch (Exception var3) {
throw new SerializationException("Could not write JSON: " + var3.getMessage(), var3);
}
}
}
public void setObjectMapper(ObjectMapper objectMapper) {
Assert.notNull(objectMapper, "'objectMapper' must not be null");
this.objectMapper = objectMapper;
}
protected JavaType getJavaType(Class<?> clazz) {
return TypeFactory.defaultInstance().constructType(clazz);
}
}
没有加密时实现为:
加密后显示:
1.启用缓存:
package com.tms.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tms.bean.system.client.Jackson2JsonRedisSerializerAes;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import java.lang.reflect.Method;
/**
* Redis 缓存配置
*/
@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport{
// @Bean
// public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
// RedisTemplate<String, String> redisTemplate = new RedisTemplate();
// redisTemplate.setConnectionFactory(redisConnectionFactory);
// return redisTemplate;
// }
@Bean
public KeyGenerator keyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object target, Method
method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for (Object obj : params) {
sb.append(obj.toString());
}
return sb.toString();
}
};
}
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
//明文显示
// Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new //Jackson2JsonRedisSerializer(Object.class);
//密文显示
Jackson2JsonRedisSerializerAes jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializerAes(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
cacheManager.setDefaultExpiration(60*60*24*60);//设置过期时间 (秒)
return cacheManager;
}
}
2.编写加解密类:
package com.tms.bean.system.util;
import org.apache.tomcat.util.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Created by gjp on 2017/10/11.
*/
public class AESUtil {
private static final String KEY_ALGORITHM = "AES";
private static final String DEFAULT_CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";//默认的加密算法
/**
* AES 加密操作
*
* @param content 待加密内容
* @param password 加密密码
* @return 返回Base64转码后的加密数据
*/
public static String encrypt(String content, String password) {
try {
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);// 创建密码器
byte[] byteContent = content.getBytes("utf-8");
cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(password));// 初始化为加密模式的密码器
byte[] result = cipher.doFinal(byteContent);// 加密
return Base64.encodeBase64String(result);//通过Base64转码返回
} catch (Exception ex) {
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* AES 解密操作
*
* @param content
* @param password
* @return
*/
public static String decrypt(String content, String password) {
try {
//实例化
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
//使用密钥初始化,设置为解密模式
cipher.init(Cipher.DECRYPT_MODE, getSecretKey(password));
//执行操作
byte[] result = cipher.doFinal(Base64.decodeBase64(content));
return new String(result, "utf-8");
} catch (Exception ex) {
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* AES 加密操作
*
* @param byteContent 待加密内容
* @param password 加密密码
* @return 加密字符串
*/
public static byte[] encryptbyte(byte[] byteContent, byte[] password) {
try {
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);// 创建密码器
String spwd = new String(password);
cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(spwd));// 初始化为加密模式的密码器
byte[] result = cipher.doFinal(byteContent);// 加密
return result;
} catch (Exception ex) {
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* AES 解密操作
*
* @param byteContent
* @param password
* @return 解密字符串
*/
public static byte[] decryptByte(byte[] byteContent, byte[] password) {
try {
//实例化
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
String pwd = new String(password);
//使用密钥初始化,设置为解密模式
cipher.init(Cipher.DECRYPT_MODE, getSecretKey(pwd));
//执行操作
byte[] result = cipher.doFinal(byteContent);
return result;
} catch (Exception ex) {
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* 生成加密秘钥
*
* @return
*/
private static SecretKeySpec getSecretKey(final String password) {
//返回生成指定算法密钥生成器的 KeyGenerator 对象
KeyGenerator kg = null;
try {
kg = KeyGenerator.getInstance(KEY_ALGORITHM);
//AES 要求密钥长度为 128
kg.init(128, new SecureRandom(password.getBytes()));
//生成一个密钥
SecretKey secretKey = kg.generateKey();
return new SecretKeySpec(secretKey.getEncoded(), KEY_ALGORITHM);// 转换为AES专用密钥
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(AESUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public static void main(String[] args) {
String s = "789helloWORLD{name:“信息”}";
System.out.println("s:" + s);
// String s1 = AESUtil.encrypt(s, "1234");
// System.out.println("s1:" + s1);
//
// System.out.println("s2:"+AESUtil.decrypt(s1, "1234"));
try {
byte[] pwd = AESUtil.encryptbyte(s.getBytes("UTF-8"), "1234".getBytes("utf-8"));
System.out.println(new String(Base64.encodeBase64(pwd)));
byte[] oldPwd = AESUtil.decryptByte(pwd,"1234".getBytes("UTF-8"));
System.out.println(new String(oldPwd,"UTF-8"));
}catch (Exception e){
e.printStackTrace();
}
}
}
3.实现RedisSerializer接口:
package com.tms.bean.system.client;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.tms.bean.system.util.AESUtil;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import org.springframework.util.Assert;
import java.nio.charset.Charset;
/**
* Created by gjp on 2017/10/11.
*
*/
public class Jackson2JsonRedisSerializerAes<T> implements RedisSerializer<T> {
private static final String PWD = "123456789asdfghjkl";
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
private final JavaType javaType;
private ObjectMapper objectMapper = new ObjectMapper();
public Jackson2JsonRedisSerializerAes(Class<T> type) {
this.javaType = this.getJavaType(type);
}
public Jackson2JsonRedisSerializerAes(JavaType javaType) {
this.javaType = javaType;
}
public T deserialize(byte[] bytes) throws SerializationException {
if(null == bytes || bytes.length ==0) {
return null;
} else {
try {
byte[] result = AESUtil.decryptByte(bytes,PWD.getBytes(DEFAULT_CHARSET));
return this.objectMapper.readValue(result, 0, bytes.length, this.javaType);
} catch (Exception var3) {
throw new SerializationException("Could not read JSON: " + var3.getMessage(), var3);
}
}
}
public byte[] serialize(Object t) throws SerializationException {
if(t == null) {
return new byte[0];
} else {
try {
byte[] temp = this.objectMapper.writeValueAsBytes(t);
return AESUtil.encryptbyte(temp,PWD.getBytes(DEFAULT_CHARSET));
//return this.objectMapper.writeValueAsBytes(t);
} catch (Exception var3) {
throw new SerializationException("Could not write JSON: " + var3.getMessage(), var3);
}
}
}
public void setObjectMapper(ObjectMapper objectMapper) {
Assert.notNull(objectMapper, "'objectMapper' must not be null");
this.objectMapper = objectMapper;
}
protected JavaType getJavaType(Class<?> clazz) {
return TypeFactory.defaultInstance().constructType(clazz);
}
}
没有加密时实现为:
加密后显示:
发表评论
-
spring boot 1.5.6 redis 解决session共享
2017-10-19 10:30 14271.下载: <dependency> ... -
spring boot 上传文件大小限制
2017-09-25 15:25 1765上传时出现了The field file exceeds it ... -
springboot和fastdfs实现文件ajax上传
2017-09-20 10:54 58131.下载: <dependency> ... -
spring-session 共享session
2017-07-21 11:20 7591.下载jar <!-- spring 共享sessio ... -
Spring4 中使用 jasypt 加密数据密码
2017-07-05 16:59 30961.加载类jar <dependency> ... -
spring3 多视图集成
2017-05-17 10:57 531使用spring3.2.9 集成多视图,可以使用jsp页面,f ... -
spring3.2+velocity 实例
2017-05-15 16:40 420Velocity,名称字面翻译为:速度、速率、迅速,用在Web ... -
spring 获取HttpSession ,HttpServletRequest ,HttpServletResponse
2017-05-02 16:30 1134ServletRequestAttributes servle ... -
spring4 + quarz2 集群
2017-03-20 15:55 5601下载: def springVers ... -
spring 测试工具
2017-03-17 17:08 453package com.cloud.test; ... -
拦截 @ResponseBody 标签输出的结果打印日志
2017-03-09 17:22 2236@ResponseBody @RequestMapp ... -
spring4 aop 使用
2017-03-09 10:23 6181.下载 jar //core spring ... -
@ResponseBody 返回对象中的Date类型如何格式化格式
2017-02-21 16:52 14861.首先定义一个格式化Date 类,这个类要实现Jso ... -
string @InitBinder 使用
2017-01-16 15:41 752在SpringMVC中,bean中定义了Date,doubl ... -
String 注解使用
2017-01-12 11:37 860二 @RequestHeader、@CookieVa ... -
Spring 的@RequestMapping注解
2017-01-12 11:35 532@RequestMapping RequestMappi ... -
spring4 使用@ResponseBody 返回中文时发现客户端乱码
2017-01-12 11:01 771在使用spring4 使用@ResponseBody 返回中 ... -
spring JdbcTemplate 不提交的问题
2015-05-29 10:54 4602最近 使用 spring3 的 JdbcTemplate ... -
使用spring3 配置自动任务
2015-05-28 17:47 5741.首先配置 spring3 的配置文件 <? ... -
spring 配置 自动任务
2015-02-03 12:00 584spring 中配置文件,定义 每天6:10:10 ...
相关推荐
RedisTemplate是Spring Data Redis模块中的一个核心组件,用于在Java应用中操作Redis数据库。它提供了一种面向对象的方式来执行各种Redis命令,简化了与Redis的数据交互。本篇将深入探讨如何将RedisTemplate封装成...
redis2json 这是一个快速而肮脏的脚本,它将redis转储到RAM中并打印出相应的JSON。用途您可以通过gzip通过管道传输输出并将其发送到文件,以进行快速的非redis数据备份或导出/迁移到另一个系统。 例如: ./redis_to_...
2. **JSON字符串存储**:最简单的方式是将Java对象转换为JSON字符串,然后存储为Redis中的String类型。Fastjson库在这里被用到,其`toJSONString`方法可以将Java对象转化为JSON格式的字符串。获取时,直接返回JSON...
"通过RedisTemplate连接多个...本文详细介绍了通过RedisTemplate连接多个Redis数据库的过程,包括配置文件的设置、添加RedisTemplate的Bean、连接多个Redis数据库等内容,对大家的学习或者工作具有一定的参考学习价值。
在本文中,我们将深入探讨如何使用Node.js与Redis数据库交互,并特别关注如何将Redis中的数据导出为JSON格式。Node.js是一种流行的JavaScript运行环境,它允许开发者在服务器端执行JavaScript代码,非常适合构建实时...
在将 JSON 对象存入 Redis 时,通常会将 JSON 字符串化后再存入,因为 Redis 不直接支持 JSON 数据类型。例如,可以使用 `json.dumps()` 函数将 Python 对象转换为 JSON 字符串,然后使用 `r.lpush()` 或其他 Redis ...
在本文中,我们将深入探讨Redis缓存的使用,以及如何在Java中处理泛型集合和JSON字符串之间的相互转换。这些技术对于构建高效、可扩展的Web应用程序至关重要,尤其是在处理大量数据时,缓存和数据序列化可以显著提高...
redis的配置类,里面配置了,一个自定义的 RedisTemplate ,用来解决我们存入redis序列化不统一乱码的问题
"Nginx、Lua、Redis 和 Json 的结合应用" Nginx 是一个高性能的 Web 服务器, Lua 是一种轻量级的脚本语言,而 Redis 是一个高性能的 NoSQL 数据库, Json 是一种轻量级的数据交换格式。通过结合使用这些技术,可以...
在Redis中,字符串对象是关键数据类型之一,而`sds`被用来实现这些对象,尤其是在存储和处理字符串值时。`sds`不仅用在数据库键值对的字符串值上,还作为内部程序中的`char*`替代品,提供更高级的功能和优化的性能。...
$ redis-dump $ redis-dump -u 127.0.0.1:6379 > db_full.json $ redis-dump -u 127.0.0.1:6379 -d 15 > db_db15.json $ < db_full.json redis-load $ < db_db15.json redis-load -d 15 # OR $ cat db_full | redis...
3. **JSON类型系统**:除了基本的JSON类型(对象、数组、字符串、数字、布尔和null),还支持浮点数、整数和字符串字面量的不同表示。 4. **操作原子性**:所有的RedisJSON命令都是原子操作,保证了并发环境下的...
Redis 4.字符串键(中).flv
redis在grafana的json文件
在Java开发环境中,Spring Boot框架提供了一个强大的工具——RedisTemplate,它使得与Redis交互变得更加简单和优雅。本篇文章将深入探讨如何在Spring Boot项目中优雅地使用RedisTemplate,实现对象的自动序列化和反...
它允许从Redis密钥(文档)存储,更新和获取JSON值。 主RedisJSON RedisJSON是一个Redis模块,它实现ECMA-404 JSON数据交换标准作为本机数据类型。 它允许从Redis密钥(文档)存储,更新和获取JSON值。 主要功能:...
Redis 5.字符串键(下).flv
Redis 3.字符串键(上).flv
首先,要了解的是JSON的基本结构,它由键值对组成,其中键(key)和字符串值(string value)都必须用双引号包裹。示例中的错误场景是指在JSON字符串的value中出现了非预期的双引号,这有可能是由于数据源的错误或者...