GETTING STARTED WITH
REDIS
INTRODUCTION TO REDIS
CreatedbyDanielKu
REDIS
is an open source, BSD licensed,
advanced key-valuestore.
Redis
FEATURES
DataTypes
Publish/Subscribe
Replication *
Persistence *
(Various)
INSTALLATION ON MAC
$brewinstallredis
Thanks, .brew
OTHER PLATFORMS ?
.Download
START SERVER
$redis-server/usr/local/etc/redis.conf
START SERVER AT LOGIN ON MAC
$ln-sfv/usr/local/opt/redis/*.plist~/Library/LaunchAgents
$launchctlload~/Library/LaunchAgent...
START SHELL CLIENT
$redis-cli
127.0.0.1:6379>
CONNECTION COMMANDS
PING
ECHOmessage
QUIT
127.0.0.1:6379>ping
PONG
127.0.0.1:6379>echohello
"hello"
127.0.0.1:6379>quit
DATABASE COMMANDS
SELECTindex
127.0.0.1:6379>select1
OK
127.0.0.1:6379[1]>select15
OK
127.0.0.1:6379[15]>select16//error
(...
DATABASES
Bydefault, there are 16 databases.
Bydefault, selects database 0.
STRING COMMANDS
SETkeyvalue
GETkey
127.0.0.1:6379>setname"Daniel"
OK
127.0.0.1:6379>getname
"Daniel"
APPENDkeyvalue
STRLENkey
127.0.0.1:6379>getname
"Daniel"
127.0.0.1:6379>appendname"Ku"
(integer)9
127.0.0.1:6379>getname
"...
GETRANGEkeystartend
SETRANGEkeyoffsetvalue
127.0.0.1:6379>getname
"DanielKu"
127.0.0.1:6379>getrangename47
"elK"
127.0.0.1...
GETSETkeyvalue
127.0.0.1:6379>getname
"DanielKim"
127.0.0.1:6379>getsetname"JennyLee"
"DanielKim"
127.0.0.1:6379>getname
"...
MSETkeyvalue[keyvalue...]
MGETkey[key...]
127.0.0.1:6379>msetname1"DanielKu"name2"JennyLee"
OK
127.0.0.1:6379>mgetname1nam...
INCRkey
DECRkey
127.0.0.1:6379>setage30
OK
127.0.0.1:6379>getage
"30"
127.0.0.1:6379>incrage
(integer)31
127.0.0.1:6379>ge...
INCRBYkeyincrement
DECRBYkeydecrement
127.0.0.1:6379>getage
"30"
127.0.0.1:6379>incrbyage10
(integer)40
127.0.0.1:6379>inc...
INCRBYFLOATkeyincrement
127.0.0.1:6379>getage
"40"
127.0.0.1:6379>incrbyage1.5
(error)ERRvalueisnotanintegeroroutofrange
1...
SETEXkeysecondsvalue
PSETEXkeymillisvalue
127.0.0.1:6379>getname
"JennyLee"
127.0.0.1:6379>setexname5"DanielKu"
OK
127.0.0...
SETNXkeyvalue
127.0.0.1:6379>getname
(nil)
127.0.0.1:6379>setnxname"DanielKu"
(integer)1
127.0.0.1:6379>getname
"DanielKu"...
MSETNXkeyvalue[keyvalue...]
127.0.0.1:6379>msetnxx1y2
(integer)1
127.0.0.1:6379>mgetxy
1)"1"
2)"2"
127.0.0.1:6379>msetnxx3...
LIST COMMANDS
LPUSHkeyvalue[value...]
LRANGEkeystartstop
127.0.0.1:6379>lpushlistabc
(integer)3
127.0.0.1:6379>lrangelist0-1
1)"c"
2)"b"...
RPUSHkeyvalue[value...]
127.0.0.1:6379>lrangelist0-1
1)"d"
2)"c"
3)"b"
4)"a"
127.0.0.1:6379>rpushlistz
(integer)5
127.0.0....
LPOPkey
RPOPkey
LLENkey
127.0.0.1:6379>lpoplist
"d"
127.0.0.1:6379>lrangelist0-1
1)"c"
2)"b"
3)"a"
4)"z"
127.0.0.1:6379>rp...
LREMkeycountvalue
127.0.0.1:6379>lrangelist0-1
1)"c"
2)"b"
3)"a"
127.0.0.1:6379>lremlist1a
(integer)1
127.0.0.1:6379>lrang...
127.0.0.1:6379>lpushlistcbab
(integer)6
127.0.0.1:6379>lrangelist0-1
1)"b"
2)"a"
3)"b"
4)"c"
5)"c"
6)"b"
127.0.0.1:6379>lr...
127.0.0.1:6379>lpushlistc
(integer)5
127.0.0.1:6379>lrangelist0-1
1)"c"
2)"a"
3)"c"
4)"c"
5)"b"
127.0.0.1:6379>lremlist-2c...
LINSERTkeyBEFORE|AFTERpivotvalue
127.0.0.1:6379>lrangelist0-1
1)"c"
2)"a"
3)"b"
127.0.0.1:6379>linsertlistbeforeax
(intege...
127.0.0.1:6379>linsertlistafteray
(integer)5
127.0.0.1:6379>lrangelist0-1
1)"c"
2)"x"
3)"a"
4)"y"
5)"b"
LINDEXkeyindex
127.0.0.1:6379>lrangelist0-1
1)"c"
2)"x"
3)"a"
4)"y"
5)"b"
127.0.0.1:6379>lindexlist0
"c"
127.0.0.1:6379>li...
LSETkeyindexvalue
127.0.0.1:6379>lrangelist0-1
1)"c"
2)"x"
3)"a"
4)"y"
5)"b"
127.0.0.1:6379>lsetlist1X
OK
127.0.0.1:6379>l...
LTRIMkeystartstop
127.0.0.1:6379>lrangelist0-1
1)"c"
2)"X"
3)"a"
4)"y"
5)"b"
127.0.0.1:6379>ltrimlist23
OK
127.0.0.1:6379>...
RPOPLPUSHsourcedestination
127.0.0.1:6379>lrangelist0-1
1)"a"
2)"y"
127.0.0.1:6379>rpoplpushlistlist2
"y"
127.0.0.1:6379>l...
LPUSHXkeyvalue
RPUSHXkeyvalue
127.0.0.1:6379>lrangelist0-1
(emptylistorset)
127.0.0.1:6379>lrangelist20-1
1)"a"
2)"y"
127....
BLPOPkey[key...]timeout
BRPOPkey[key...]timeout
Client#1
127.0.0.1:6379>lrangenames0-1
(emptylistorset)
127.0.0.1:6379>lpu...
Client#1
127.0.0.1:6379>blpopnames5//waitfor5seconds
(nil)
(5.24s)
127.0.0.1:6379>blpopnames5
Client#2
127.0.0.1:6379>lpus...
Client#1
127.0.0.1:6379>blpopnamesnames25
Client#2
127.0.0.1:6379>lpushnames2daniel
(integer)1
Client#1
1)"names2"
2)"dani...
BRPOPLPUSHsourcedestinationtimeout
Client#1
127.0.0.1:6379>lrangenames0-1
(emptylistorset)
127.0.0.1:6379>lrangenames20-1
...
HASH COMMANDS
HSETkeyfieldvalue
HGETkeyfield
HGETALLkey
127.0.0.1:6379>hsetobjectnamedaniel
(integer)1
127.0.0.1:6379>hsetobjectage34
(i...
HKEYSkey
HVALSkey
HEXISTSkeyfield
HLENkey
127.0.0.1:6379>hkeysobject
1)"name"
2)"age"
127.0.0.1:6379>hvalsobject
1)"daniel...
HINCRBYkeyfieldincrement
HINCRBYFLOATkeyfieldincrement
127.0.0.1:6379>hincrbyobjectage1
(integer)35
127.0.0.1:6379>hincrby...
HMSETkeyfieldvalue[fieldvalue...]
HMGETkeyfield[field...]
127.0.0.1:6379>hmsetobject2f1xf2y
OK
127.0.0.1:6379>hmgetobject2...
HSETNXkeyfieldvalue
127.0.0.1:6379>hsetnxobject2f3z
(integer)1
127.0.0.1:6379>hsetnxobject2f3Z
(integer)0
127.0.0.1:6379>h...
HDELkeyfield[field...]
127.0.0.1:6379>hdelobject2f3
(integer)1
127.0.0.1:6379>hdelobject2f2
(integer)1
127.0.0.1:6379>hget...
SET COMMANDS
SADDkeymember[member...]
SMEMBERSkey
127.0.0.1:6379>saddsetone
(integer)1
127.0.0.1:6379>saddsettwothree
(integer)2
127.0....
SREMkeymember[member...]
SISMEMBERkeymember
SCARDkey
127.0.0.1:6379>sremsetthree
(integer)1
127.0.0.1:6379>smembersset
1)"...
SRANDMEMBERkey
127.0.0.1:6379>saddsetthree
(integer)1
127.0.0.1:6379>smembersset
1)"one"
2)"three"
3)"two"
127.0.0.1:6379>...
SPOPkey
127.0.0.1:6379>spopset
"one"
127.0.0.1:6379>spopset
"three"
127.0.0.1:6379>smembersset
1)"two"
127.0.0.1:6379>spop...
SDIFFkey[key...]
SDIFFSTOREdestinationkey[key...]
127.0.0.1:6379>saddset1onetwothree
(integer)3
127.0.0.1:6379>saddset2one...
SINTERkey[key...]
SINTERSTOREdestinationkey[key...]
SUNIONkey[key...]
SUNIONSTOREdestinationkey[key...]
127.0.0.1:6379>sin...
SMOVEsourcedestinationmember
127.0.0.1:6379>smoveset1set2three
(integer)1
127.0.0.1:6379>smembersset1
1)"one"
2)"two"
127....
SORTED SET COMMANDS
ZADDkeyscoremember[scoremember...]
ZCARDkey
127.0.0.1:6379>zaddzset10one
(integer)1
127.0.0.1:6379>zaddzset20two30three
(i...
ZSCOREkeymember
ZCOUNTkeyminmax
127.0.0.1:6379>zscorezsetone
"10"
127.0.0.1:6379>zscorezsettwo
"20"
127.0.0.1:6379>zcountz...
ZRANKkeymember
ZREVRANKkeymember
127.0.0.1:6379>zrankzsetone
(integer)0
127.0.0.1:6379>zrankzsetthree
(integer)2
127.0.0.1...
ZRANGEkeystartstop[WITHSCORES]
ZREVRANGEkeystartstop[WITHSCORES]
127.0.0.1:6379>zrangezset0-1
1)"one"
2)"two"
3)"three"
12...
ZRANGEBYSCOREkeyminmax[WITHSCORES][LIMIToffsetcount]
ZREVRANGEBYSCOREkeyminmax[WITHSCORES][LIMIToffsetcount]
127.0.0.1:637...
ZINCRBYkeyincrementmember
ZREMkeymember[member...]
127.0.0.1:6379>zincrbyzset5two
"25"
127.0.0.1:6379>zscorezsettwo
"25"
1...
ZREMRANGEBYSCOREkeyminmax
ZREMRANGEBYRANKkeyminmax
127.0.0.1:6379>zremrangebyscorezset1020
(integer)1
127.0.0.1:6379>zrang...
KEYS COMMANDS
KEYSpatten
127.0.0.1:6379>keys*
1)"set2"
2)"set3"
3)"object2"
4)"name1"
5)"x"
6)"object"
7)"age"
8)"list2"
9)"name2"
10)"n...
EXISTSkey
TYPEkey
127.0.0.1:6379>existsname
(integer)1
127.0.0.1:6379>existsset
(integer)0
127.0.0.1:6379>typename
string
...
DELkey[key...]
127.0.0.1:6379>delxy
(integer)2
127.0.0.1:6379>keys*
1)"set2"
2)"set3"
3)"object2"
4)"list"
5)"name1"
6)"ob...
RENAMEkeynewkey
RENAMENXkeynewkey
127.0.0.1:6379>keyslist*
1)"list2"
127.0.0.1:6379>renamelist2list
OK
127.0.0.1:6379>keys...
MOVEkeydb
127.0.0.1:6379>keysname*
1)"name1"
2)"names"
3)"name2"
4)"name"
127.0.0.1:6379>movename1
(integer)1
127.0.0.1:63...
RANDOMKEY
127.0.0.1:6379>randomkey
"set2"
127.0.0.1:6379>randomkey
"name1"
127.0.0.1:6379>randomkey
"list"
127.0.0.1:6379>...
EXPIREkeyseconds
PEXPIREkeymillis
EXPIREATkeytimestamp
PEXPIREATkeymillis-timestamp
127.0.0.1:6379>expirename15
(integer)1...
TTLkey
PTTLkey
127.0.0.1:6379>setage34
OK
127.0.0.1:6379>ttlage
(integer)-1
127.0.0.1:6379>expireage5
(integer)1
127.0.0.1...
PERSISTkey
127.0.0.1:6379>setnameDaniel
OK
127.0.0.1:6379>expirename5
(integer)1
127.0.0.1:6379>ttlname
(integer)3
127.0.0...
PUBLISH/SUBSCRIBE COMMANDS
PUBLISHchannelmessage
SUBSCRIBEchannel[channel...]
Client#1
127.0.0.1:6379>subscribechannel1
Readingmessages...(pressCtrl-...
PSUBSCRIBEpattern[pattern...]
Client#1
127.0.0.1:6379>psubscribechannel*
Readingmessages...(pressCtrl-Ctoquit)
1)"psubscri...
Client#2
127.0.0.1:6379>publishchannel2Hello
(integer)2
Client#1
1)"pmessage"
2)"channel*"
3)"channel2"
4)"Hello"
UNSUBSCRIBE[channel[channel...]]
PUNSUBSCRIBE[pattern[pattern...]]
NotApplicable in redis-cli
TRANSACTIONS COMMANDS
MULTI
EXEC
127.0.0.1:6379>multi
OK
127.0.0.1:6379>setname"Daniel"
QUEUED
127.0.0.1:6379>setage20
QUEUED
127.0.0.1:6379>exe...
127.0.0.1:6379>multi
OK
127.0.0.1:6379>incrname
QUEUED
127.0.0.1:6379>incrage
QUEUED
127.0.0.1:6379>exec
1)(error)ERRvalue...
DISCARD
127.0.0.1:6379>multi
OK
127.0.0.1:6379>setname"Daniel"
QUEUED
127.0.0.1:6379>setage30
QUEUED
127.0.0.1:6379>discar...
NODE.JS DRIVER FOR REDIS
https://github.com/mranney/node_redis
$npminstallhiredisredis
SOCKET.IO
http://socket.io/
$npminstallsocket.io
$bowerinstallsocket.io-client
EXAMPLE
https://github.com/kjunine/redis-samples
REFERENCES
Tuts+ Premium: Redis Essential
대용량서버구축을위한Memcached와Redis
11 Common Web Use Cases Solved In Redis
THE END
THANKS.
Upcoming SlideShare
Loading in …5
×

Getting Started with Redis

549 views
428 views

Published on

Redis(http://redis.io/)는 최근 눈부시게 성장하고 있는 Key-Value Store 형태의 NoSQL이다.
Redis **시작하기**인 만큼 많이 사용되는 명령어들을 위주로 살펴보았다.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
549
On SlideShare
0
From Embeds
0
Number of Embeds
23
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Getting Started with Redis

  1. 1. GETTING STARTED WITH REDIS INTRODUCTION TO REDIS CreatedbyDanielKu
  2. 2. REDIS is an open source, BSD licensed, advanced key-valuestore. Redis
  3. 3. FEATURES DataTypes Publish/Subscribe Replication * Persistence * (Various)
  4. 4. INSTALLATION ON MAC $brewinstallredis Thanks, .brew
  5. 5. OTHER PLATFORMS ? .Download
  6. 6. START SERVER $redis-server/usr/local/etc/redis.conf
  7. 7. START SERVER AT LOGIN ON MAC $ln-sfv/usr/local/opt/redis/*.plist~/Library/LaunchAgents $launchctlload~/Library/LaunchAgents/homebrew.mxcl.redis.plist
  8. 8. START SHELL CLIENT $redis-cli 127.0.0.1:6379>
  9. 9. CONNECTION COMMANDS PING ECHOmessage QUIT 127.0.0.1:6379>ping PONG 127.0.0.1:6379>echohello "hello" 127.0.0.1:6379>quit
  10. 10. DATABASE COMMANDS SELECTindex 127.0.0.1:6379>select1 OK 127.0.0.1:6379[1]>select15 OK 127.0.0.1:6379[15]>select16//error (error)ERRinvalidDBindex 127.0.0.1:6379[16]>select0 OK
  11. 11. DATABASES Bydefault, there are 16 databases. Bydefault, selects database 0.
  12. 12. STRING COMMANDS
  13. 13. SETkeyvalue GETkey 127.0.0.1:6379>setname"Daniel" OK 127.0.0.1:6379>getname "Daniel"
  14. 14. APPENDkeyvalue STRLENkey 127.0.0.1:6379>getname "Daniel" 127.0.0.1:6379>appendname"Ku" (integer)9 127.0.0.1:6379>getname "DanielKu" 127.0.0.1:6379>strlenname (integer)9
  15. 15. GETRANGEkeystartend SETRANGEkeyoffsetvalue 127.0.0.1:6379>getname "DanielKu" 127.0.0.1:6379>getrangename47 "elK" 127.0.0.1:6379>setrangename7Kim (integer)10 127.0.0.1:6379>getname "DanielKim"
  16. 16. GETSETkeyvalue 127.0.0.1:6379>getname "DanielKim" 127.0.0.1:6379>getsetname"JennyLee" "DanielKim" 127.0.0.1:6379>getname "JennyLee"
  17. 17. MSETkeyvalue[keyvalue...] MGETkey[key...] 127.0.0.1:6379>msetname1"DanielKu"name2"JennyLee" OK 127.0.0.1:6379>mgetname1name2 1)"DanielKu" 2)"JennyLee" M-= Multiple
  18. 18. INCRkey DECRkey 127.0.0.1:6379>setage30 OK 127.0.0.1:6379>getage "30" 127.0.0.1:6379>incrage (integer)31 127.0.0.1:6379>getage "31" 127.0.0.1:6379>decrage (integer)30 127.0.0.1:6379>getage "30"
  19. 19. INCRBYkeyincrement DECRBYkeydecrement 127.0.0.1:6379>getage "30" 127.0.0.1:6379>incrbyage10 (integer)40 127.0.0.1:6379>incrbyage10 (integer)50 127.0.0.1:6379>decrbyage10 (integer)40 127.0.0.1:6379>getage "40"
  20. 20. INCRBYFLOATkeyincrement 127.0.0.1:6379>getage "40" 127.0.0.1:6379>incrbyage1.5 (error)ERRvalueisnotanintegeroroutofrange 127.0.0.1:6379>incrbyfloatage1.5 "41.5" 127.0.0.1:6379>getage "41.5" 127.0.0.1:6379>incrage (error)ERRvalueisnotanintegeroroutofrange
  21. 21. SETEXkeysecondsvalue PSETEXkeymillisvalue 127.0.0.1:6379>getname "JennyLee" 127.0.0.1:6379>setexname5"DanielKu" OK 127.0.0.1:6379>getname "DanielKu" 127.0.0.1:6379>getname//after5seconds (nil) 127.0.0.1:6379>psetexname5000"DanielKu" OK 127.0.0.1:6379>getname "DanielKu" 127.0.0.1:6379>getname//after5000milliseconds (nil) -EX = EXpire
  22. 22. SETNXkeyvalue 127.0.0.1:6379>getname (nil) 127.0.0.1:6379>setnxname"DanielKu" (integer)1 127.0.0.1:6379>getname "DanielKu" 127.0.0.1:6379>setnxname"JennyLee" (integer)0 127.0.0.1:6379>getname "DanielKu" -NX = NoteXist
  23. 23. MSETNXkeyvalue[keyvalue...] 127.0.0.1:6379>msetnxx1y2 (integer)1 127.0.0.1:6379>mgetxy 1)"1" 2)"2" 127.0.0.1:6379>msetnxx3z4 (integer)0 127.0.0.1:6379>mgetxyz 1)"1" 2)"2" 3)(nil)
  24. 24. LIST COMMANDS
  25. 25. LPUSHkeyvalue[value...] LRANGEkeystartstop 127.0.0.1:6379>lpushlistabc (integer)3 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"b" 3)"a" 127.0.0.1:6379>lpushlistd (integer)4 127.0.0.1:6379>lrangelist0-1 1)"d" 2)"c" 3)"b" 4)"a" 127.0.0.1:6379>lrangelist23 1)"b" 2)"a" L-= List&Left
  26. 26. RPUSHkeyvalue[value...] 127.0.0.1:6379>lrangelist0-1 1)"d" 2)"c" 3)"b" 4)"a" 127.0.0.1:6379>rpushlistz (integer)5 127.0.0.1:6379>lrangelist0-1 1)"d" 2)"c" 3)"b" 4)"a" 5)"z" R-= Right
  27. 27. LPOPkey RPOPkey LLENkey 127.0.0.1:6379>lpoplist "d" 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"b" 3)"a" 4)"z" 127.0.0.1:6379>rpoplist "z" 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"b" 3)"a" 127.0.0.1:6379>llenlist (integer)3
  28. 28. LREMkeycountvalue 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"b" 3)"a" 127.0.0.1:6379>lremlist1a (integer)1 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"b" 127.0.0.1:6379>lremlist1a (integer)0 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"b"
  29. 29. 127.0.0.1:6379>lpushlistcbab (integer)6 127.0.0.1:6379>lrangelist0-1 1)"b" 2)"a" 3)"b" 4)"c" 5)"c" 6)"b" 127.0.0.1:6379>lremlist2b (integer)2 127.0.0.1:6379>lrangelist0-1 1)"a" 2)"c" 3)"c" 4)"b"
  30. 30. 127.0.0.1:6379>lpushlistc (integer)5 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"a" 3)"c" 4)"c" 5)"b" 127.0.0.1:6379>lremlist-2c (integer)2 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"a" 3)"b"
  31. 31. LINSERTkeyBEFORE|AFTERpivotvalue 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"a" 3)"b" 127.0.0.1:6379>linsertlistbeforeax (integer)4 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"x" 3)"a" 4)"b"
  32. 32. 127.0.0.1:6379>linsertlistafteray (integer)5 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"x" 3)"a" 4)"y" 5)"b"
  33. 33. LINDEXkeyindex 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"x" 3)"a" 4)"y" 5)"b" 127.0.0.1:6379>lindexlist0 "c" 127.0.0.1:6379>lindexlist-1 "b" 127.0.0.1:6379>lindexlist3 "y"
  34. 34. LSETkeyindexvalue 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"x" 3)"a" 4)"y" 5)"b" 127.0.0.1:6379>lsetlist1X OK 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"X" 3)"a" 4)"y" 5)"b"
  35. 35. LTRIMkeystartstop 127.0.0.1:6379>lrangelist0-1 1)"c" 2)"X" 3)"a" 4)"y" 5)"b" 127.0.0.1:6379>ltrimlist23 OK 127.0.0.1:6379>lrangelist0-1 1)"a" 2)"y"
  36. 36. RPOPLPUSHsourcedestination 127.0.0.1:6379>lrangelist0-1 1)"a" 2)"y" 127.0.0.1:6379>rpoplpushlistlist2 "y" 127.0.0.1:6379>lrangelist0-1 1)"a" 127.0.0.1:6379>lrangelist20-1 1)"y" 127.0.0.1:6379>rpoplpushlistlist2 "a" 127.0.0.1:6379>lrangelist0-1 (emptylistorset) 127.0.0.1:6379>lrangelist20-1 1)"a" 2)"y"
  37. 37. LPUSHXkeyvalue RPUSHXkeyvalue 127.0.0.1:6379>lrangelist0-1 (emptylistorset) 127.0.0.1:6379>lrangelist20-1 1)"a" 2)"y" 127.0.0.1:6379>lpushxlista (integer)0 127.0.0.1:6379>lrangelist0-1 (emptylistorset) 127.0.0.1:6379>lpushxlist2b (integer)3 127.0.0.1:6379>lrangelist20-1 1)"b" 2)"a" 3)"y" -X = eXist
  38. 38. BLPOPkey[key...]timeout BRPOPkey[key...]timeout Client#1 127.0.0.1:6379>lrangenames0-1 (emptylistorset) 127.0.0.1:6379>lpushnamesdaniel (integer)1 127.0.0.1:6379>lrangenames0-1 1)"daniel" Client#2 127.0.0.1:6379>blpopnames1 1)"names" 2)"daniel" Client#1 127.0.0.1:6379>lrangenames0-1 (emptylistorset) B-= Blocking
  39. 39. Client#1 127.0.0.1:6379>blpopnames5//waitfor5seconds (nil) (5.24s) 127.0.0.1:6379>blpopnames5 Client#2 127.0.0.1:6379>lpushnamesdaniel (integer)1 Client#1 1)"names" 2)"daniel" (2.47s)
  40. 40. Client#1 127.0.0.1:6379>blpopnamesnames25 Client#2 127.0.0.1:6379>lpushnames2daniel (integer)1 Client#1 1)"names2" 2)"daniel" (3.18s)
  41. 41. BRPOPLPUSHsourcedestinationtimeout Client#1 127.0.0.1:6379>lrangenames0-1 (emptylistorset) 127.0.0.1:6379>lrangenames20-1 (emptylistorset) 127.0.0.1:6379>brpoplpushnamesnames25 Client#2 127.0.0.1:6379>lpushnamesdaniel (integer)1 Client#1 "daniel" (2.03s) 127.0.0.1:6379>lrangenames0-1 (emptylistorset) 127.0.0.1:6379>lrangenames20-1 1)"daniel"
  42. 42. HASH COMMANDS
  43. 43. HSETkeyfieldvalue HGETkeyfield HGETALLkey 127.0.0.1:6379>hsetobjectnamedaniel (integer)1 127.0.0.1:6379>hsetobjectage34 (integer)1 127.0.0.1:6379>hgetobjectname "daniel" 127.0.0.1:6379>hgetobjectage "34" 127.0.0.1:6379>hgetallobject 1)"name" 2)"daniel" 3)"age" 4)"34" H-= Hash
  44. 44. HKEYSkey HVALSkey HEXISTSkeyfield HLENkey 127.0.0.1:6379>hkeysobject 1)"name" 2)"age" 127.0.0.1:6379>hvalsobject 1)"daniel" 2)"34" 127.0.0.1:6379>hexistsobjectname (integer)1 127.0.0.1:6379>hexistsobjectjob (integer)0 127.0.0.1:6379>hlenobject (integer)2
  45. 45. HINCRBYkeyfieldincrement HINCRBYFLOATkeyfieldincrement 127.0.0.1:6379>hincrbyobjectage1 (integer)35 127.0.0.1:6379>hincrbyobjectage-2 (integer)33 127.0.0.1:6379>hgetallobject 1)"name" 2)"daniel" 3)"age" 4)"33"
  46. 46. HMSETkeyfieldvalue[fieldvalue...] HMGETkeyfield[field...] 127.0.0.1:6379>hmsetobject2f1xf2y OK 127.0.0.1:6379>hmgetobject2f1f2 1)"x" 2)"y" 127.0.0.1:6379>hgetallobject2 1)"f1" 2)"x" 3)"f2" 4)"y"
  47. 47. HSETNXkeyfieldvalue 127.0.0.1:6379>hsetnxobject2f3z (integer)1 127.0.0.1:6379>hsetnxobject2f3Z (integer)0 127.0.0.1:6379>hgetallobject2 1)"f1" 2)"x" 3)"f2" 4)"y" 5)"f3" 6)"z"
  48. 48. HDELkeyfield[field...] 127.0.0.1:6379>hdelobject2f3 (integer)1 127.0.0.1:6379>hdelobject2f2 (integer)1 127.0.0.1:6379>hgetallobject2 1)"f1" 2)"x"
  49. 49. SET COMMANDS
  50. 50. SADDkeymember[member...] SMEMBERSkey 127.0.0.1:6379>saddsetone (integer)1 127.0.0.1:6379>saddsettwothree (integer)2 127.0.0.1:6379>smembersset 1)"one" 2)"three" 3)"two" S-= Set
  51. 51. SREMkeymember[member...] SISMEMBERkeymember SCARDkey 127.0.0.1:6379>sremsetthree (integer)1 127.0.0.1:6379>smembersset 1)"one" 2)"two" 127.0.0.1:6379>sismembersetone (integer)1 127.0.0.1:6379>sismembersetthree (integer)0 127.0.0.1:6379>scardset (integer)2
  52. 52. SRANDMEMBERkey 127.0.0.1:6379>saddsetthree (integer)1 127.0.0.1:6379>smembersset 1)"one" 2)"three" 3)"two" 127.0.0.1:6379>srandmemberset "two" 127.0.0.1:6379>srandmemberset "one" 127.0.0.1:6379>srandmemberset "two" 127.0.0.1:6379>srandmemberset "two" 127.0.0.1:6379>srandmemberset "three"
  53. 53. SPOPkey 127.0.0.1:6379>spopset "one" 127.0.0.1:6379>spopset "three" 127.0.0.1:6379>smembersset 1)"two" 127.0.0.1:6379>spopset "two" 127.0.0.1:6379>smembersset (emptylistorset)
  54. 54. SDIFFkey[key...] SDIFFSTOREdestinationkey[key...] 127.0.0.1:6379>saddset1onetwothree (integer)3 127.0.0.1:6379>saddset2onetwofourfive (integer)4 127.0.0.1:6379>sdiffset1set2 1)"three" 127.0.0.1:6379>sdiffset2set1 1)"four" 2)"five" 127.0.0.1:6379>sdiffstoreset3set1set2 (integer)1 127.0.0.1:6379>smembersset3 1)"three"
  55. 55. SINTERkey[key...] SINTERSTOREdestinationkey[key...] SUNIONkey[key...] SUNIONSTOREdestinationkey[key...] 127.0.0.1:6379>sinterset1set2 1)"one" 2)"two" 127.0.0.1:6379>sunionset1set2 1)"two" 2)"one" 3)"four" 4)"five" 5)"three"
  56. 56. SMOVEsourcedestinationmember 127.0.0.1:6379>smoveset1set2three (integer)1 127.0.0.1:6379>smembersset1 1)"one" 2)"two" 127.0.0.1:6379>smembersset2 1)"four" 2)"one" 3)"five" 4)"two" 5)"three"
  57. 57. SORTED SET COMMANDS
  58. 58. ZADDkeyscoremember[scoremember...] ZCARDkey 127.0.0.1:6379>zaddzset10one (integer)1 127.0.0.1:6379>zaddzset20two30three (integer)2 127.0.0.1:6379>zcardzset (integer)3 Z-= Sorted Set
  59. 59. ZSCOREkeymember ZCOUNTkeyminmax 127.0.0.1:6379>zscorezsetone "10" 127.0.0.1:6379>zscorezsettwo "20" 127.0.0.1:6379>zcountzset-inf+inf (integer)3 127.0.0.1:6379>zcountzset1020 (integer)2 127.0.0.1:6379>zcountzset10(20 (integer)1 Z-= Sorted Set
  60. 60. ZRANKkeymember ZREVRANKkeymember 127.0.0.1:6379>zrankzsetone (integer)0 127.0.0.1:6379>zrankzsetthree (integer)2 127.0.0.1:6379>zrevrankzsetone (integer)2 127.0.0.1:6379>zrevrankzsetthree (integer)0
  61. 61. ZRANGEkeystartstop[WITHSCORES] ZREVRANGEkeystartstop[WITHSCORES] 127.0.0.1:6379>zrangezset0-1 1)"one" 2)"two" 3)"three" 127.0.0.1:6379>zrangezset0-1withscores 1)"one" 2)"10" 3)"two" 4)"20" 5)"three" 6)"30" 127.0.0.1:6379>zrevrangezset01withscores 1)"three" 2)"30" 3)"two" 4)"20"
  62. 62. ZRANGEBYSCOREkeyminmax[WITHSCORES][LIMIToffsetcount] ZREVRANGEBYSCOREkeyminmax[WITHSCORES][LIMIToffsetcount] 127.0.0.1:6379>zrangebyscorezset2030 1)"two" 2)"three" 127.0.0.1:6379>zrangebyscorezset(2030withscores 1)"three" 2)"30" 127.0.0.1:6379>zrevrangebyscorezset30(10withscores 1)"three" 2)"30" 3)"two" 4)"20" 127.0.0.1:6379>zrevrangebyscorezset+inf-infwithscoreslimit21 1)"one" 2)"10"
  63. 63. ZINCRBYkeyincrementmember ZREMkeymember[member...] 127.0.0.1:6379>zincrbyzset5two "25" 127.0.0.1:6379>zscorezsettwo "25" 127.0.0.1:6379>zremzsetthree (integer)1 127.0.0.1:6379>zrangezset0-1withscores 1)"one" 2)"10" 3)"two" 4)"25"
  64. 64. ZREMRANGEBYSCOREkeyminmax ZREMRANGEBYRANKkeyminmax 127.0.0.1:6379>zremrangebyscorezset1020 (integer)1 127.0.0.1:6379>zrangezset0-1withscores 1)"two" 2)"25" 127.0.0.1:6379>zremrangebyrankzset0-1 (integer)1 127.0.0.1:6379>zrangezset0-1withscores (emptylistorset)
  65. 65. KEYS COMMANDS
  66. 66. KEYSpatten 127.0.0.1:6379>keys* 1)"set2" 2)"set3" 3)"object2" 4)"name1" 5)"x" 6)"object" 7)"age" 8)"list2" 9)"name2" 10)"name" 11)"y" 12)"set1" 13)"names2" 127.0.0.1:6379>keysname* 1)"name1" 2)"name2" 3)"name" 4)"names2" 127.0.0.1:6379>keysset* 1)"set2" 2)"set3" 3)"set1"
  67. 67. EXISTSkey TYPEkey 127.0.0.1:6379>existsname (integer)1 127.0.0.1:6379>existsset (integer)0 127.0.0.1:6379>typename string 127.0.0.1:6379>typeage string 127.0.0.1:6379>typeset1 set 127.0.0.1:6379>typelist2 list
  68. 68. DELkey[key...] 127.0.0.1:6379>delxy (integer)2 127.0.0.1:6379>keys* 1)"set2" 2)"set3" 3)"object2" 4)"list" 5)"name1" 6)"object" 7)"age" 8)"name2" 9)"name" 10)"set1" 11)"names2"
  69. 69. RENAMEkeynewkey RENAMENXkeynewkey 127.0.0.1:6379>keyslist* 1)"list2" 127.0.0.1:6379>renamelist2list OK 127.0.0.1:6379>keyslist* 1)"list" 127.0.0.1:6379>keysname* 1)"name1" 2)"names2" 3)"name2" 4)"name" 127.0.0.1:6379>renamenxname2name (integer)0 127.0.0.1:6379>renamenxnames2names (integer)1 127.0.0.1:6379>keysname* 1)"name1" 2)"names" 3)"name2" 4)"name"
  70. 70. MOVEkeydb 127.0.0.1:6379>keysname* 1)"name1" 2)"names" 3)"name2" 4)"name" 127.0.0.1:6379>movename1 (integer)1 127.0.0.1:6379>keysname* 1)"name1" 2)"names" 3)"name2" 127.0.0.1:6379>select1 OK 127.0.0.1:6379[1]>keysname* 1)"name" 127.0.0.1:6379[1]>select0 OK
  71. 71. RANDOMKEY 127.0.0.1:6379>randomkey "set2" 127.0.0.1:6379>randomkey "name1" 127.0.0.1:6379>randomkey "list" 127.0.0.1:6379>randomkey "name2" 127.0.0.1:6379>randomkey "age" 127.0.0.1:6379>randomkey "object2" 127.0.0.1:6379>randomkey "set1"
  72. 72. EXPIREkeyseconds PEXPIREkeymillis EXPIREATkeytimestamp PEXPIREATkeymillis-timestamp 127.0.0.1:6379>expirename15 (integer)1 127.0.0.1:6379>getname1 "DanielKu" 127.0.0.1:6379>getname1//after5seconds (nil) 127.0.0.1:6379>pexpirename25000 (integer)1 127.0.0.1:6379>getname2 "JennyLee" 127.0.0.1:6379>getname2//after5000seconds (nil)
  73. 73. TTLkey PTTLkey 127.0.0.1:6379>setage34 OK 127.0.0.1:6379>ttlage (integer)-1 127.0.0.1:6379>expireage5 (integer)1 127.0.0.1:6379>ttlage (integer)4 127.0.0.1:6379>pttlage (integer)1720 127.0.0.1:6379>ttlage (integer)-2
  74. 74. PERSISTkey 127.0.0.1:6379>setnameDaniel OK 127.0.0.1:6379>expirename5 (integer)1 127.0.0.1:6379>ttlname (integer)3 127.0.0.1:6379>persistname (integer)1 127.0.0.1:6379>ttlname (integer)-1 127.0.0.1:6379>getname "Daniel"
  75. 75. PUBLISH/SUBSCRIBE COMMANDS
  76. 76. PUBLISHchannelmessage SUBSCRIBEchannel[channel...] Client#1 127.0.0.1:6379>subscribechannel1 Readingmessages...(pressCtrl-Ctoquit) 1)"subscribe" 2)"channel1" 3)(integer)1 Client#2 127.0.0.1:6379>publishchannel1"Hello" (integer)1 Client#1 1)"message" 2)"channel1" 3)"Hello"
  77. 77. PSUBSCRIBEpattern[pattern...] Client#1 127.0.0.1:6379>psubscribechannel* Readingmessages...(pressCtrl-Ctoquit) 1)"psubscribe" 2)"channel*" 3)(integer)1 Client#2 127.0.0.1:6379>publishchannel1Hi (integer)2 Client#1 1)"pmessage" 2)"channel*" 3)"channel1" 4)"Hi"
  78. 78. Client#2 127.0.0.1:6379>publishchannel2Hello (integer)2 Client#1 1)"pmessage" 2)"channel*" 3)"channel2" 4)"Hello"
  79. 79. UNSUBSCRIBE[channel[channel...]] PUNSUBSCRIBE[pattern[pattern...]] NotApplicable in redis-cli
  80. 80. TRANSACTIONS COMMANDS
  81. 81. MULTI EXEC 127.0.0.1:6379>multi OK 127.0.0.1:6379>setname"Daniel" QUEUED 127.0.0.1:6379>setage20 QUEUED 127.0.0.1:6379>exec 1)OK 2)OK 127.0.0.1:6379>mgetnameage 1)"Daniel" 2)"20"
  82. 82. 127.0.0.1:6379>multi OK 127.0.0.1:6379>incrname QUEUED 127.0.0.1:6379>incrage QUEUED 127.0.0.1:6379>exec 1)(error)ERRvalueisnotanintegeroroutofrange 2)(integer)21 127.0.0.1:6379>mgetnameage 1)"Daniel" 2)"21"
  83. 83. DISCARD 127.0.0.1:6379>multi OK 127.0.0.1:6379>setname"Daniel" QUEUED 127.0.0.1:6379>setage30 QUEUED 127.0.0.1:6379>discard OK
  84. 84. NODE.JS DRIVER FOR REDIS https://github.com/mranney/node_redis $npminstallhiredisredis
  85. 85. SOCKET.IO http://socket.io/ $npminstallsocket.io $bowerinstallsocket.io-client
  86. 86. EXAMPLE https://github.com/kjunine/redis-samples
  87. 87. REFERENCES Tuts+ Premium: Redis Essential 대용량서버구축을위한Memcached와Redis 11 Common Web Use Cases Solved In Redis
  88. 88. THE END THANKS.

×