Search code examples
ruby-on-railsredisredis-cli

How to delete a key using HDEL if the key have space with it


I am using Ruby 2.5.1 and trying to delete keys from redis using HDEL. But it doesn't work key with spaces. I can delete with the quotes from redis-cli but I need to write a code to delete keys with space.

Sample value

["play group_1", "{\"id\":\"1\",\"name\":\"Play Group\"}"]

Delete not working in redis-cli (If doesn't passing single quotes with in it),

127.0.0.1:6379> HDEL development_groups play group_1
(integer) 0

Delete works in redis-cli (If passing single quotes with in it),

127.0.0.1:6379> HDEL development_groups 'play group_1'
(integer) 1

Ruby code,

redis.hdel(index, key)

How to delete keys with space using HDEL?


Solution

  • Try with to_s option

    i.e) key.to_s