Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在冰咖啡脚本函数中增加redis hmset_Redis_Iced Coffeescript - Fatal编程技术网

在冰咖啡脚本函数中增加redis hmset

在冰咖啡脚本函数中增加redis hmset,redis,iced-coffeescript,Redis,Iced Coffeescript,我想将redis hmset嵌入 exports.hmset = (name, autocb, params...)=> await client.hmset name, params, defer(err) throw err if err 我有一个params是类似['fooKey','fooValue','barKey','barValue']的数组。但我在redis数据库中的namekey上有数据: {'0' : 'fooKey', '1' : 'fooValue

我想将redis hmset嵌入

exports.hmset = (name, autocb, params...)=>
    await client.hmset name, params, defer(err)
    throw err if err
我有一个
params
是类似
['fooKey','fooValue','barKey','barValue']
的数组。但我在redis数据库中的
name
key上有数据:

{'0' : 'fooKey', '1' : 'fooValue', '2' : 'barKey', '3': 'barValue'}
但我希望它是:

{'fooKey' : 'fooValue', 'barKey' : 'barValue'}

我知道我必须将它们传递到
client.hmset
中,不像数组
['fooKey','fooValue','barKey','barValue']
,而是像args:
'fooKey','fooValue','barKey','barValue'
。但是当args长度不同时,如何通过包装
exports.hmset
函数传递它们呢?

据我所知,您使用的是调用
hmset
的约定。使用收集数组中的参数,然后将数组作为参数传递给node_redis,node_redis也支持此约定,即传递一个包含键及其值的普通对象。这就是为什么要使用位置键来获取redis散列,因为如果将javascript数组视为对象,这就是您所拥有的

您只需在调用redis时再次打开
params

exports.hmset = (name, autocb, params...)=>
    await client.hmset name, params..., defer(err)
    throw err if err

现在,coffeescript将该数组作为varargs传递给“real”
hmset
。作为额外的好处,您还可以使用“params As a object”(参数作为对象)约定,这一约定可以说更加优雅。

您是否理解
抛出错误将不会在IcedCoffeeScript中按预期工作?
它将在事件循环中引发错误,这样您就无法在代码中用“try”捕捉到它