redis command line view Chinese non scrambled code method (hexadecimal string processing)
- 2020-05-30 21:16:20
- OfStack
redis command line view Chinese not messy code
When using the command line, Redis will display a hexadecimal string "\xe4\xb8\xad\xe5\x9b\xbd" if the contents contain Chinese.
127.0.0.1:6379> set k1 ' China '
OK
127.0.0.1:6379> get k1
"\xe4\xb8\xad\xe5\x9b\xbd"
If you want to see the Chinese characters, there are two solutions:
1. Use echo
$ echo -e `redis-cli get k1`
China
2. Add the hang raw to redis-cli
$ redis-cli --raw
127.0.0.1:6379> get k1
China
Here is a detailed example of Redis's use of base 106 string manipulation, as follows:
Redis in the process of using a Chinese content are stored in 106 in the form of the system, when using redis - cli client connections so if it is a part of the contents have Chinese would be in the form of 106 into the system, so the data in a query redis content is a little too convenient, actually under the Unix system can look up to the 106 "- in hexadecimal content with echo e" parameter is used to convert the query to 106 base content, are as follows:
127.0.0.1:6379> get test1
"test\xe6\x8c\x81\xe4\xb9\x85\xe5\x8c\x96"
127.0.0.1:6379> quit
[root@localhost ~]# echo -e "test\xe6\x8c\x81\xe4\xb9\x85\xe5\x8c\x96"
test persistence
In addition, when using the redis-cli client, the "--raw" parameter of the redis-cli client itself can be used to output the original content when connecting to redis:
[root@localhost ~]# redis-cli --raw
127.0.0.1:6379> get test1
test persistence
conclusion