-1

这是包含 ruby​​gems 和 redis 后我的 rails 控制台的输出。

2.0.0-p353 :024 > r = Redis.new
=> #<Redis client v3.0.7 for redis://127.0.0.1:6379/0> 
2.0.0-p353 :025 > r.set('foo','bar')
=> "OK" 
2.0.0-p353 :026 > r.get('foo')
=> "bar"
2.0.0-p353 :033 > r.lpush('foo','bar')
Redis::CommandError: ERR Operation against a key holding the wrong kind of value
from /home/poorva/.rvm/gems/ruby-2.0.0-p353/gems/redis-3.0.7/lib/redis/client.rb:97:in `call'
from /home/poorva/.rvm/gems/ruby-2.0.0-p353/gems/redis-3.0.7/lib/redis.rb:949:in `block in lpush'
from /home/poorva/.rvm/gems/ruby-2.0.0-p353/gems/redis-3.0.7/lib/redis.rb:37:in `block in synchronize'
from /home/poorva/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /home/poorva/.rvm/gems/ruby-2.0.0-p353/gems/redis-3.0.7/lib/redis.rb:37:in `synchronize'
from /home/poorva/.rvm/gems/ruby-2.0.0-p353/gems/redis-3.0.7/lib/redis.rb:948:in `lpush'
from (irb):33
from /home/poorva/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /home/poorva/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /home/poorva/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
2.0.0-p353 :034 > r.lpush(foo,'bar')
NameError: undefined local variable or method `foo' for main:Object
from (irb):34
from /home/poorva/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /home/poorva/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /home/poorva/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
4

1 回答 1

-1

更新:第一个参数必须是 lpush 命令的第一个参数,即列表的键。第二,要推送的值。


初始消息(修改问题之前)

消息是明确的ArgumentError: wrong number of arguments (0 for 2)只需按照Redis 文档中的描述为 LPUSH 提供预期的参数:要推送的键和值。

lpush('mylist', 'bar')
于 2014-03-24T08:16:12.657 回答