Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ bug ]redis提交工单,set命令里面的value不能有空格,否则报错。 #746

Closed
roytrack opened this issue May 17, 2020 · 6 comments
Labels
area/redis bug Something isn't working

Comments

@roytrack
Copy link

重现步骤

1.提交工单执行redis,例如 set abc "archery is good"。
2.执行工单。
3.报错 异常信息:syntax error。

错误原因分析:

由于archery使用的是redis模块,他在connection.py的pack_command方法实现时只是简单的按照空格进行split,所以会导致redis其实所有命令的value都不支持包含空格。

修复思路:
建议使用shlex.split(),这个可以兼容有单双引号的情况。由于是嵌入到了redis包里,不知道更新版本的redis里面是否修复了这个问题。

期待结果和实际结果

期待结果:
能够正常设置值。

实际结果:
报错不能正常设置。

截图

错误日志

[2020-05-14 10:40:45,164][MainThread:140460059264832][task_id:default][redis.py:137][WARNING]- Redis命令执行报错,语句:set abc archery is good, 错误信息:
Traceback (most recent call last):
  File "/opt/archery/sql/engines/redis.py", line 125, in execute_workflow
    conn.execute_command(cmd)
  File "/opt/venv4archery/lib/python3.6/site-packages/redis/client.py", line 839, in execu
te_command
    return self.parse_response(conn, command_name, **options)
  File "/opt/venv4archery/lib/python3.6/site-packages/redis/client.py", line 853, in parse
_response
    response = connection.read_response()
  File "/opt/venv4archery/lib/python3.6/site-packages/redis/connection.py", line 718, in r
ead_response

版本信息

应用版本/分支: 1.7.4

部署方式:Docker

@LeoQuote
Copy link
Collaborator

emmmm 感觉是不是使用问题? set abc \"archery is good\"转义一下会不会好? 参考:

https://stackoverflow.com/questions/21065225/redis-command-line-set-value-containing-double-quotes

@LeoQuote
Copy link
Collaborator

https://demo.archerydms.com/detail/1243/ 试了下最新版确实有这个问题的, 最新版的包肯定是最新的, 升级redis-py 应该解决不了.

https://demo.archerydms.com/detail/1244/ https://demo.archerydms.com/detail/1245/ 另外转义似乎也不好使

我先本地试一下 redis-py 看看能不能复现

@LeoQuote
Copy link
Collaborator

奇怪, 试了下 redis-py 完全ok, 帮忙提供一下 pip freeze 的结果以及 redis server 版本吧, 今天没空搭测试环境, 有空我看一下.

pip freeze

pkg-resources==0.0.0
redis==3.5.2

redis server version

Redis 4.0.9 (00000000/0) 64 bit
>>> import redis
>>> r = redis.Redis(host='localhost', port=6379, db=0)
>>> r.execute_command("set abc "archery123"")
  File "<stdin>", line 1
    r.execute_command("set abc "archery123"")
                                         ^
SyntaxError: invalid syntax
>>> r.execute_command("set abc \"archery123\"")
b'OK'
>>> r.execute_command("set abc 'archery123'")
b'OK'
>>> cmd = "set abc 'archery123'"
>>> r.execute_command(cmd)
b'OK'
>>> cmd = "set abc \"archery123\""
>>> cmd
'set abc "archery123"'
>>> r.execute_command(cmd)
b'OK'

@LeoQuote LeoQuote added area/redis bug Something isn't working labels May 17, 2020
@LeoQuote
Copy link
Collaborator

https://demo.archerydms.com/detail/1246/ 奇怪, 单引号也失败了.....

@hhyo
Copy link
Owner

hhyo commented May 17, 2020

django-redis依赖的redis.py是3.5版本,可以升级试试

@LeoQuote
Copy link
Collaborator

不能再升了、已经是最高了

@hhyo hhyo closed this as completed in ee01f8b May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/redis bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants