背景:项目需求里,想做一个可拓展的队列来存储名单。
实现功能:该队列实现增删改的功能
我用的方法:
采用了redis的Lpush实现,不过还得考虑删除value的方法,这里又用上了redis的LREM方法
redis的Lpush方法
127.0.0.1:6379> lpush whiteIp 127.0.0.1
(integer) 1
127.0.0.1:6379> lpush whiteIp 127.0.0.2
(integer) 2
127.0.0.1:6379> LRANGE whiteIp 0 -1
1) "127.0.0.2"
2) "127.0.0.1"
redis的LREM 方法
redis> RPUSH mylist "hello"
(integer) 1
redis> RPUSH mylist "hello"
(integer) 2
redis> RPUSH mylist "foo"
(integer) 3
redis> RPUSH mylist "hello"
(integer) 4
redis> LREM mylist -2 "hello"
(integer) 2
redis> LRANGE mylist 0 -1
1) "hello"
2) "foo
The count argument influences the operation in the following ways:
count > 0: Remove elements equal to value moving from head to tail.
count < 0: Remove elements equal to value moving from tail to head.
count = 0: Remove all elements equal to value.