Redisの操作


127.0.0.1:6379> rpush mycolor pink
(integer) 1
127.0.0.1:6379> rpush mycolor green
(integer) 2
127.0.0.1:6379> rpush mycolor red
(integer) 3
127.0.0.1:6379> rpush mycolor yellow
(integer) 4
127.0.0.1:6379> rpush mycolor blue
(integer) 5
127.0.0.1:6379> rpush myclolor purple
(integer) 1
127.0.0.1:6379> lrange mycolor 0 5
1) "pink"
2) "green"
3) "red"
4) "yellow"
5) "blue"
127.0.0.1:6379> lrange mycolor 0 -1
1) "pink"
2) "green"
3) "red"
4) "yellow"
5) "blue"

リスト操作

127.0.0.1:6379> rpop mycolor
"blue"
127.0.0.1:6379> lrange mycolor 0 -1
1) "pink"
2) "green"
3) "red"
4) "yellow"
127.0.0.1:6379> lpop mycolor
"pink"
127.0.0.1:6379> lrange mycolor 0 -1
1) "green"
2) "red"
3) "yellow"
127.0.0.1:6379> lindex mycolor 2
"yellow"
127.0.0.1:6379> llen mycolor
(integer) 3
127.0.0.1:6379> ltrim mycolor 0 2
OK
127.0.0.1:6379> lrange mycolor 0 -1
1) "green"
2) "red"
3) "yellow"

セット型の計算

127.0.0.1:6379> sadd myset1 a
(integer) 1
127.0.0.1:6379> sadd myset1 b
(integer) 1
127.0.0.1:6379> sadd myset1 c
(integer) 1
127.0.0.1:6379> smembers myset1
1) "c"
2) "b"
3) "a"
127.0.0.1:6379> sadd myset1 d
(integer) 1
127.0.0.1:6379> smembers myset1
1) "d"
2) "c"
3) "b"
4) "a"
127.0.0.1:6379> srem myset1 d
(integer) 1
127.0.0.1:6379> smembers myset1
1) "c"
2) "b"
3) "a"
127.0.0.1:6379> sadd myset2 b
(integer) 1
127.0.0.1:6379> sadd myset2 c
(integer) 1
127.0.0.1:6379> sadd myset2 e
(integer) 1
127.0.0.1:6379> smembers myset1
1) "c"
2) "b"
3) "a"
127.0.0.1:6379> smembers myset2
1) "c"
2) "b"
3) "e"
127.0.0.1:6379> sunion myset1 myset2
1) "b"
2) "c"
3) "e"
4) "a"
127.0.0.1:6379> sinter mysete1 myset2
(empty list or set)
127.0.0.1:6379> sdiff myset1 myset2
1) "a"

ソート済みの集合

127.0.0.1:6379> zadd hs 22 yamada
(integer) 1
127.0.0.1:6379> zadd hs 50 tanaka
(integer) 1
127.0.0.1:6379> zadd hs 80 yasuda
(integer) 1
127.0.0.1:6379> zadd hs 21 okamoto
(integer) 1
127.0.0.1:6379> zrange hs 0 -1
1) "okamoto"
2) "yamada"
3) "tanaka"
4) "yasuda"
127.0.0.1:6379> zrevrange hs 0 -1
1) "yasuda"
2) "tanaka"
3) "yamada"
4) "okamoto"
127.0.0.1:6379> zrank hs yamada
(integer) 1
127.0.0.1:6379> zrevrank hs yamada
(integer) 2