扩展功能
RedisFX支持用户自定义扩展数据编/解码、数据查看方式。
数据编/解码
- 在数据展示区域点击菜单栏的
编/解码方式
按钮,选择自定义扩展
,会弹出设置界面并定位到编/解码器
选项,点击+新增
按钮及可添加自定义扩展。 - 数据编/解码器是给用户提供一种自定义的数据转换方式,比如压缩、加/解密等场景。
- stdio使用标准输入输出进行数据交互,文件交互模式下使用文件进行数据交互,也就是输入输出数据会临时存储在
输入输出目录
中。

注意
如果是stdio交互模式,输入输出目录可以不填,文件交互模式下,输入输出目录必须填写。 stdio适合快速开发,文件交互模式更适合数据量大或者需要对数据转换进行持久化存储的场景。
stdio交互示例
- 功能为使用
.bat
脚本实现对数据的转换,数据为hello字符串,解码器会将字符串拼接上word,而编码器会将末尾的word去掉。 示例代码
- 测试效果
分别在解码和编码配置的命令输入框填写脚本路径,如:E:/xxx/join_stdio_decode.bat 和 E:/xxx/join_stdio_encode.bat
- 解码器
bat
@echo off
setlocal enabledelayedexpansion
:: 从标准输入读取数据
set /p inputData=
:: 将数据转换为字符串(实际上在批处理中默认就是字符串)
set resultString=%inputData%
:: 拼接上 "word"
set finalResult=%resultString%word
:: 通过标准输出返回结果
echo %finalResult%
- 编码器
bat
@echo off
setlocal enabledelayedexpansion
:: 从标准输入读取数据
set /p inputData=
:: 将数据转换为字符串(实际上在批处理中默认就是字符串)
set resultString=%inputData%
:: 去掉末尾的 "word"
set finalResult=%resultString:~0,-4%
:: 通过标准输出返回结果
echo %finalResult%
- 功能为使用
.python
脚本实现对数据的加解密。 示例代码
- 解码器
python
import sys
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
# 配置密钥和IV(根据实际加密参数修改)
key = b"1234567890123456" # 16字节AES密钥
iv = b"1234567890123456" # 16字节IV
# 直接从stdin读取二进制数据
data = sys.stdin.buffer.read()
# AES解密
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
decryptor = cipher.decryptor()
decrypted = decryptor.update(data) + decryptor.finalize()
# 直接通过stdout输出二进制结果
sys.stdout.buffer.write(decrypted)
sys.stdout.flush()
- 编码器
python
import sys
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
# 配置密钥和IV(与解密脚本保持一致)
key = b"1234567890123456" # 16字节AES密钥
iv = b"1234567890123456" # 16字节IV
# 从stdin读取明文数据
plaintext = sys.stdin.buffer.read()
# PKCS7填充
padding_length = 16 - (len(plaintext) % 16)
plaintext += bytes([padding_length] * padding_length)
# AES加密
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
encryptor = cipher.encryptor()
encrypted = encryptor.update(plaintext) + encryptor.finalize()
# 通过stdout输出加密结果
sys.stdout.buffer.write(encrypted)
sys.stdout.flush()
文件交互示例
注意
文件交互模式下,输入和输出文件名固定为redis-fx.input和redis-fx.output。
- 功能为使用
.python
脚本实现对数据的加解密。 示例代码
- 解码器
python
import os
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
# 配置密钥和IV(根据实际加密参数修改)
key = b"1234567890123456" # 16字节AES密钥
iv = b"1234567890123456" # 16字节IV
# 输入输出路径需要和自定义编解码器中的配置保持一致,且输入固定为redis-fx.input 输出固定为redis-fx.output
io_dir = r'E:\test\decode'
with open(os.path.join(io_dir, 'redis-fx.input'), "rb") as f:
# 从文件读取二进制数据
data = f.read()
# AES解密
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
decryptor = cipher.decryptor()
decrypted = decryptor.update(data) + decryptor.finalize()
# 将二进制数据写入文件
with open(os.path.join(io_dir, 'redis-fx.output'), "wb") as f:
f.write(decrypted)
- 编码器
python
import os
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
# 配置密钥和IV(与解密脚本保持一致)
key = b"1234567890123456" # 16字节AES密钥
iv = b"1234567890123456" # 16字节IV
# 输入输出路径需要和自定义编解码器中的配置保持一致,且输入固定为redis-fx.input 输出固定为redis-fx.output
io_dir = r'E:\test\encode'
with open(os.path.join(io_dir, 'redis-fx.input'), "rb") as f:
# 从文件读取二进制数据
data = f.read()
# PKCS7填充
padding_length = 16 - (len(data) % 16)
data += bytes([padding_length] * padding_length)
# AES加密
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
encryptor = cipher.encryptor()
encrypted = encryptor.update(data) + encryptor.finalize()
# 将二进制数据写入文件
with open(os.path.join(io_dir, 'redis-fx.output'), "wb") as f:
f.write(encrypted)
数据查看方式
基于jar包的插件开发模式,正在计划开发中。