ralph
ralph

Reputation: 335

key holding wrong kind of value in redis when pushing data on a list

I am trying redis on my heroku app. I have the following code in config/initializers/redis.rb

uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

I'm trying the following in the console but getting error:

irb(main):003:0> REDIS.rpush ('foo','bar')
(irb):3: warning: don't put space before argument parentheses
RuntimeError: -ERR Operation against a key holding the wrong kind of value

Upvotes: 2

Views: 13288

Answers (1)

Pieter
Pieter

Reputation: 181

This error is returned when you try to operate on for instance a list value, while the key is holding another type of value (e.g. string, set, etc.). To find out what type of value is stored at foo, you can use the following command:

REDIS.type("foo")

When you do an RPUSH or LPUSH against a key that doesn't hold a value, a list will automatically be created. So, you have to make sure foo doesn't exist or holds a list value for this operation to work.

Upvotes: 11

Related Questions