Redis overview

Installation

For mac

1
sudo brew install redis-server

open redis server

1
redis-server

test is work or not

1
redis-cli ping

basic command

1
2
3
ECHO 'hello word

QUIT
  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
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
SET foo 100

GET foo // 100

SET bar 'hello world'

GET bar // hello world

INCR foo // 101

DECR foo // 100

EXISTS foo // 1

EXISTS foo1 // 0

DEL bar

EXISTS bar // 0

GET bar //(nir)

FLUSHALL // all empty

SET server:name someserver

GET server:name // "someserver"

SET server:port 8000

GET server:port

SET greeting "Hello world"

GET greeting

EXPIRE greeting 50  // set expirations to 50 second

TTL greeting

SETEX greeting 30 "hello world" // set value and expiration

PERSIST greeting // key will not expire

TTL greeting // -1

MSET key1 "hello" key2 "world"

APPEND key1 " world"

RENAME key1 greeting

LPUSH people "Brad" // 1

LPUSH people "Jen" // 2

LPUSH people "Tom" // 3

LRANGE people 0 -1 // return all // Tom Jen Brad

LRANGE people 1 2 // Jen Brad

RPUSH people "Harry"

LRANGE people 0 -1 // Tom Jen Brad Harry

LLEN people // 4

RPOP people // Harry

LPOP people

LINSERT people BEFORE "Brad" "TOM"

LRANGE people 0 -1 // Jen Tom Brad

SADD cars "Ford"

SADD cars "Honda"

SADD cars "BMW"

SISMEMBER cars "Ford" // 1

SISMEMBER cars "Chevy" // 0

SMEMBER cars // Honda BMW Ford

SCARD cars // 3

SMOVE cars mycars "Ford"

SMEMBER cars // Honda BMW

SMEMBER mycars // Ford

SRAM cars "BMW"

SMEMBER cars // Honda

ZADD users 1980 "Brad"

ZADD users 1975 "Jen"

ZADD users 1990 "Mike"

ZADD users 1990 "Kate"

ZRANK users "Mike" // 3

ZRANK users "Jen" // 0

ZRANK users "Brad" // 1

ZRANGE users 0 -1 // Jen Brad Kate Mike

ZINCRBY users 1 "Jen" // 1976

HSET user:brad name "Brad"

HSET user:brad email "brad@gmail.com"

HGET user:brad name

HGET user:brad email

HGETALL user:brad

HMSET user:john name "Jen" email "jen@yahoo.com" age "25"

HGETALL user:john

HKEYS user:john

HVAL user:john

HINCERBY user:john age 1 // 26

HDEL user:john age // 1

HLEN user:john // 2

SAVE