Redis

Installation

script
1
2
3
4
> brew install redis
> brew info redis
> redis-cli ping
# get pong if run successfully

Commands

script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
> redis-cli
redis 127.0.0.1:6379> PING
PONG

redis 127.0.0.1:6379> CONFIG GET CONFIG_SESTTING_NAME
redis 127.0.0.1:6379> CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE

#String
redis 127.0.0.1:6379> SET A "test" (<= 512MB)
OK
redis 127.0.0.1:6379> GET A "test"
"test"
redis 127.0.0.1:6379> DEL A


#Hash
127.0.0.1:6379> HMSET hmset A "test1" B "test2" C "test3"
OK
127.0.0.1:6379> HGET hmset
(error) ERR wrong number of arguments for 'hget' command
127.0.0.1:6379> HGET hmset A
"test1"


#list
127.0.0.1:6379> lpush L testC
(integer) 2
127.0.0.1:6379> lrange L 0 1
1) "testC"
2) "testB"

#Set
127.0.0.1:6379> sadd A test1
(integer) 1
127.0.0.1:6379> sadd A test2
(integer) 1
127.0.0.1:6379> sadd A test1
(integer) 0
127.0.0.1:6379> smembers A
1) "test1"
2) "test2"

#ZSet : has a double score could be ranged
127.0.0.1:6379> zadd A 5 test3
(integer) 1
127.0.0.1:6379> zadd A 4 test3
(integer) 0
127.0.0.1:6379> zadd A 5 test2
(integer) 1
127.0.0.1:6379> zadd A 6 test3
(integer) 0
127.0.0.1:6379> ZRANGEBYSCORE A 0 10
1) "test2"
2) "test3"
127.0.0.1:6379>