自学内容网 自学内容网

Java 使用 Redis cmd显示出现乱码问题

Java 使用 Redis 出现乱码问题

pom.xml

<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/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!--继承父工程-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.6</version>
    </parent>
    <groupId>com.zhong</groupId>
    <artifactId>big-event</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>big-event</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!--web 依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
       
        <!--单元测试依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        
        <!--redis 依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
    </dependencies>
</project>

application.yml

spring:
  # Redis 配置信息
  data:
    redis:
      host: localhost
      port: 6379

测试代码

package com.zhong;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

/**
 * @ClassName : RedisConn
 * @Description : Redis 测试
 * @Author : zhx
 * @Date: 2024-03-02 10:06
 */

@SpringBootTest
public class RedisConn {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void testStringSet() {
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        ops.set("username", "张三");
    }

    @Test
    public void testStringGet() {
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        String name = ops.get("username");
        System.out.println(name);
    }
}

在这里插入图片描述

用 cmd 查看出现乱码

reids-cli
get "username"

![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/fad9beeb811c4e75a88b757a485b7bbc.png

解决方法

chcp 65001
reids-cli --raw
get "username"

在这里插入图片描述


原文地址:https://blog.csdn.net/weixin_56050344/article/details/136411570

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!