背景:項目需求里年扩,想做一個可拓展的隊列來存儲名單。
實現(xiàn)功能:該隊列實現(xiàn)增刪改的功能
我用的方法:
采用了redis的Lpush實現(xiàn),不過還得考慮刪除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.