Redis removes certain items from a set

I have a set of members. For example, a set called "college" with the names of 20 colleges.

Now, how to remove only a subset, for example. selected set of 10 colleges from the set?

I am starting a redis v2.4.5 server

The documentation found here http://redis.io/commands/srem says that we can delete several keys for redis> = 2.4, but still could not figure out how to achieve this.

I am working with RubyonRails and I have done this in the rails console

> $redis
    #<Redis client v2.2.2 connected to redis://localhost:6379/0 (Redis v2.4.5)>
> ruby-1.9.3-p0 :011 > $redis.sadd("college","champion1")
 => true 
ruby-1.9.3-p0 :012 > $redis.sadd("college","champion2")
 => true 
ruby-1.9.3-p0 :013 > $redis.sadd("college","champion3")
 => true 
ruby-1.9.3-p0 :014 > $redis.sadd("college","champion4")
 => true 
ruby-1.9.3-p0 :015 > $redis.sadd("college","champion5")
 => true
ruby-1.9.3-p0 :016 > $redis.smembers("college")
 => ["champion1", "champion2", "champion3", "champion4", "champion5"
ruby-1.9.3-p0 :017 > $redis.srem("college","champion1" "champion2")
 => false
ruby-1.9.3-p0 :018 > $redis.smembers("college")
 => ["champion1", "champion2", "champion3", "champion4", "champion5"]

Members "champion1" and "champion2" are not removed from the set.

I installed gem redis (2.2.2 ruby).

+3
source share
3 answers

, , sdiff sdiffstore. , , .

, .

+3
% telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

...

sadd myset 1 2 3      
:3
srem myset 1 3
:2
+3

Sorry guys, this is a problem specific to Rails.

I installed redis gem version 2.2.2 and it did not have support for deleting multiple keys. But, however, to enter redis-cli for the redis> = 2.4 server, we can achieve it.

gagan@gagan-desktop:~/projects/test_proj [master]$ redis-cli
redis 127.0.0.1:6379> smembers "college"
1) "champion1"
2) "champion2"
3) "champion3"
4) "champion4"
5) "champion5"
redis 127.0.0.1:6379> srem "college" "champion1" "champion2"
(integer) 2
redis 127.0.0.1:6379> smembers "college"
1) "champion3"
2) "champion4"
3) "champion5"
redis 127.0.0.1:6379> exit
+3
source

All Articles