redis 写入 redis = redis:new();
.........
redis->set('foyon', ' ') #redis 写入空串,这个时候是正常的
redis->get('foyon') #报错误
hset hmset 写入空串 ,获取时都有问题
用的openresty 1.2.8 中resty中的redis.lua
2014/05/27 11:53:35 [error] 27617#0: *36 lua handler aborted: runtime error: .../openresty/foyonlua/luaframework/lualibs/resty/redis.lua:132: bad argument #1
to 'receive' (bad pattern argument),
并且我将
../lualibs/resty/redis.lua
116 local function _read_reply(sock)
117 local line, err = sock:receive()
118 if not line then
119 return nil, err
120 end
121
122 local prefix = sub(line, 1, 1)
123
124 if prefix == "$" then
125 -- print("bulk reply")
126
127 local size = tonumber(sub(line, 2))
128 --redis返回控制 bug 修复,避免前端写 '' 报错误
129 --alert by Foyon 2014-5-27 19:22:52 || size <0 改为 size <=0
130 if size <= 0 then
131 return null
132 end
133
134 local data, err = sock:receive(size)
135 if not data then
136 return nil, err
137 end
138
139 local dummy, err = sock:receive(2) -- ignore CRLF
140 if not dummy then
141 return nil, err
142 end
143
144 return data
修改这个后, 我在使用的时候 还是报错,
265 ---------------------end----------------------------
266 +++++++++++++++++begin++++++++++++++++++++++++
267 208:recommend_list
268 pppppppppppid=>208
269 cccccccccccccccccccc=>recommend_list
270 vvvvvvvvvvvvv=>0
271 1.1e+26
272 1001
273 112
274 ---------------------end----------------------------
275 +++++++++++++++++begin++++++++++++++++++++++++
276 208:s_flag
277 pppppppppppid=>208
278 cccccccccccccccccccc=>s_flag
279 vvvvvvvvvvvvv=>null
280 1.1e+26
281 nilunkown prefix: ""
282 112
283 ---------------------end----------------------------
284 +++++++++++++++++begin++++++++++++++++++++++++
285 208:serial
286 pppppppppppid=>208
287 cccccccccccccccccccc=>serial
288 vvvvvvvvvvvvv=>1001
289 1.1e+26
290 0
291 112
292 ---------------------end----------------------------
并且导致我后面取 key的值 和实际内存中的值不一样!!!
实际应用中逻辑代码
87 for k,value in ipairs(edit_list) do
88 ngx.say('+++++++++++++++++begin++++++++++++++++++++++++')
89 ngx.say(value)
90
91 local offset = string.find(value, ':')
92
93 if offset then
94 local pid = tonumber(string.sub(value,0,offset-1))
95 local column = string.sub(value,offset+1,string.len(value))
96
97
98 ngx.say('pppppppppppid=>',pid)
99 ngx.say('cccccccccccccccccccc=>',column)
100
101 --是否存在pid
102 --match_list[pid] = match_list[pid] or {}
103
104 --获取字段值
105 local m_k = 'MatchConf:'..plat..':'..pid
106
107 local v = Redis:hget(m_k, column) --当hget 取某key,改key的值为 空串 (‘ ’) , 循环继续取 ,发现key 和value 已经错乱
108 ngx.say('vvvvvvvvvvvvv=>',v)
109 ngx.say(109999999999999999999999999)
110 ngx.say(Redis:hget(m_k,"game_id"))
111
112 ngx.say(112)
113 --if v then
114 -- match_list[pid][column] = v
115 --end
116 end
117 ngx.say('---------------------end----------------------------')
望作者能修复 这个问题。感谢!~~