为什么redis-benchmark命令不遵循redis协议?(How come the redis-benchmark command is not following the redis protocol?)
在运行
redis-benchmark
命令之后,我直接从tcp连接读取,据我所知,redis-benchmark
不遵循redis协议。redis协议如其网站所述:
RESP在Redis中用作请求 - 响应协议的方式如下:
- 客户端将命令作为Bulk Strings的RESP数组发送到Redis服务器。
- 服务器根据命令实现回复一种RESP类型。
这意味着正确的客户端实现必须始终发送批量字符串的RESP数组。
如果这是真的,那么任何不以*开头的东西都被认为是语法错误(因为它不是RESP数组)。
因此,如果要将一个ping命令发送到redis-server,则必须将其作为长度为1的resp数组发送,其中包含1个包含单词ping的批量字符串。 例如:
“* 1 \ r \ n $ 4 \ r \ nPING \ r \ n”
但是,每当我直接监听redis-benchmark命令并读取其tcp连接时,我得到的是:
“PING \ r \ n”
它不遵循redis协议。 这是一个错误还是redis协议中隐含的一些东西让ping变得特别? 据我所知,我找不到任何说ping特别的东西,也没有说长度1命令是特别的。 有人知道发生了什么事吗?
要查看自己重现这些结果,您可以复制我的代码以直接检查它:
package main import ( "fmt" "log" "net" ) func main() { RedisBenchmark() } func RedisBenchmark() { url := "127.0.0.1:6379" fmt.Println("listen: ", url) ln, err := net.Listen("tcp", url) //announces on local network if err != nil { log.Fatal(err) } for { conn, err := ln.Accept() //waits and returns the next connection to the listener if err != nil { log.Fatal(err) } tcpConn := conn.(*net.TCPConn) go HandleConnection(tcpConn) } } func HandleConnection(tcpConn *net.TCPConn) { b := make([]byte, 256) //TODO how much should I read at a time? n, err := tcpConn.Read(b) if err != nil { fmt.Println("n: ", n) log.Fatal(err) } fmt.Printf("+++++> raw input string(b): %q\n", string(b)) msg := string(b[:n]) fmt.Printf("+++++> raw input msg: %q\n", msg) }
并使用go运行它:
go run main.go
跟随在不同的终端(或tmux窗格):
redis-benchmark
对于所有测试或者如果您只想与1个客户端运行ping:
redis-benchmark -c 1 -t ping -n 1
你可以在http://redis.io/topics/benchmarks看到有关我如何运行它的详细信息
I was reading in directly from a tcp connection after running the
redis-benchmark
command and as far as I can tell,redis-benchmark
is NOT following the redis protocol.The redis protocol is as stated in its website:
The way RESP is used in Redis as a request-response protocol is the following:
- Clients send commands to a Redis server as a RESP Array of Bulk Strings.
- The server replies with one of the RESP types according to the command implementation.
Meaning that a correct client implementation must always send RESP arrays of bulk strings.
If that is true, then, anything that does not start with a * is considered a syntax error (since its not an RESP array).
Thus, if one were to send a ping command to a redis-server, then it must be sent as a resp array of length 1 with 1 bulk string containing the word ping. For example:
"*1\r\n$4\r\nPING\r\n"
However, whenever I listen directly to the redis-benchmark command and read its tcp connection I get instead:
"PING\r\n"
which does not follow the redis protocol. Is that a bug or is there something implied in the redis protocol that makes pings special? As far as I could tell I couldn't find anything that said that pings were special, nor that length 1 commands were special. Does someone know whats going on?
To see reproduce these results yourself you can copy my code to inspect it directly:
package main import ( "fmt" "log" "net" ) func main() { RedisBenchmark() } func RedisBenchmark() { url := "127.0.0.1:6379" fmt.Println("listen: ", url) ln, err := net.Listen("tcp", url) //announces on local network if err != nil { log.Fatal(err) } for { conn, err := ln.Accept() //waits and returns the next connection to the listener if err != nil { log.Fatal(err) } tcpConn := conn.(*net.TCPConn) go HandleConnection(tcpConn) } } func HandleConnection(tcpConn *net.TCPConn) { b := make([]byte, 256) //TODO how much should I read at a time? n, err := tcpConn.Read(b) if err != nil { fmt.Println("n: ", n) log.Fatal(err) } fmt.Printf("+++++> raw input string(b): %q\n", string(b)) msg := string(b[:n]) fmt.Printf("+++++> raw input msg: %q\n", msg) }
and run it using go with:
go run main.go
followed on a different terminal (or tmux pane):
redis-benchmark
for all the test or if you only want to run ping with 1 client:
redis-benchmark -c 1 -t ping -n 1
you can see the details of how I am running it with the flags at: http://redis.io/topics/benchmarks
原文:https://stackoverflow.com/questions/25225333
满意答案
如果您已正确设置约束并且应用程序的部署目标是> = iOS 8,则可以使用自动行高计算。 因此,您必须在
viewDidLoad
执行以下操作:tableView.estimatedRowHeight = 44 tableView.rowHeight = UITableViewAutomaticDimension
其中44应该是某种平均行高。 那么你根本不必实现
estimatedRowHeight
和heightForRow
方法......你也可以实现
heightForRow
并执行以下操作:// if cell is of kind textview cell return UITableViewAutomaticDimension // else return some static value
if you have setup your constraints correctly and your app's deployment target is >= iOS 8 you can use the automatic row height calculation. therefore you have to do the following in
viewDidLoad
:tableView.estimatedRowHeight = 44 tableView.rowHeight = UITableViewAutomaticDimension
where 44 should be some kind of average rowheight. then you do not have to implement the methods
estimatedRowHeight
andheightForRow
at all...you can also implement
heightForRow
and do something like the following:// if cell is of kind textview cell return UITableViewAutomaticDimension // else return some static value
相关问答
更多单元格高度等于图像宽度(Cell height equal to image width)
使UItableview单元格高度等于其子UItableview(Make UItableview cell height equal to it's child UItableview)
基于动态标签高度的iOS8动态单元格高度(iOS8 Dynamic Cell Height based on Dynamic Label height)
UItableview每个单元格标签都要隐藏,高度应该更改(UItableview each cell label want to hide and height should be change)
无法设置表格视图单元格的动态高度?(Not able to set the dynamic height of table view cell?)
如何使宽度单元格等于字符串长度?(How make width cell equal string length?)
设置单元格的高度等于标签内容(Set height of cell equal to the label content)
如何根据其内容更改单元格高度?(How do I change cell height according to its content?)
如何设置自定义单元格标签的约束?(How to set the constraints for custom cell label?)
以编程方式设置collectionview单元格中标签约束的高度(Setting up height of label constraint in collectionview cell programatically)
相关文章
更多Redis Cookbook
Redis概述
redis 集群环境搭建-redis集群管理
Redis 事务详解
redis从库只读设置-redis集群管理
redis安装-redis集群管理
redis sentinel.conf详解-redis集群管理
基于linux下redis安装与配置
Redis配置文件详解
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!