Redis

RUNGPHARIT
3 min readJun 15, 2020

--

https://en.wikipedia.org/wiki/Redis

What is Redis ?

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.

Redis คือ open source เพื่อเอาไว้ทำ database , cache และ message broker (ตัวจัดการ pub/sub) ซึ่งมี Datatypes หลายรูปแบบมาก เช่น strings , hashes, list , set ,sorted set ซึ่งมันจะเก็บข้อมูลอยู่ใน RAM ทำให้ไม่ว่าจะ Read , Write ,Update หรือ Delete เร็วมาก

เริ่มใช้งาน Redis กัน

อย่าลืมเข้าไปดาวน์โหลดกันก่อนนะครับ

##start redis 
redis-cli
##ทดสอบว่ายังมีการ connect กันอยู่มั้ย
ping
##เซตข้อมูล
SET <constant> <value>
##โชว์ข้อมูล
GET <constant>
##ดูว่ามี constant อยู่มั้ย
EXISTS <constant>
##ลบ constant
DEL <constant>
##ลบทุกอย่าง
FLUSHALL
##เซต key:value
SET <constant>:<key> <value>
##ดูค่า
GET <constant>:<key>
##เซตค่าโดยกำหนดการหมดอายุ
SETEX <constant> <time> <value>
##ดูระยะเวลา
TTL <constant>

LIST

##set list
LPUSH <constant> <value>
##ดูข้อมูล
LRANGE <constant> <number> <number>
##ความยาวของข้อมูล
LLEN <constant>

SET

##เซตข้อมูล
SADD <constant> <value>
##ดูข้อมูล
SMEMBERS <constant>
##ตรวจสอบข้อมูล
SISMEMBER <constant> <value>
##ดูความยาวของข้อมูล
SCARD

HASH

##เซตข้อมูล
HSET <constant> <key> <value>
##ดูข้อมูล
HGET <constant>
##ดูข้อมูลทั้งหมด
HGETALL <constant>

ยังมีข้อมูลอีกหลายรูปแบบให้ศึกษากันนะครับ สามารถเข้าไปดูได้ที่เว็บไซต์ของ redis เองได้เล้ยย

อาจจะสงสัยว่า แล้วไหนบอกว่า ทำอะไรได้เร็วมากมายเหลือเกิน ในบทความนี้แค่บอกก่อนว่า redis คืออะไร แล้วมีคำสั่งอะไรที่เราสามารถเล่นกับมันได้บ้าง ส่วนในการทดสอบว่ามันดียังไง เร็วแค่ไหน จะมีในบทความถัดไปกันนะครับ

Reference :

https://www.youtube.com/watch?v=Hbt56gFj998

https://medium.com/scale360-engineering/redis101-redis-%E0%B8%A1%E0%B8%B1%E0%B8%99%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3%E0%B8%AB%E0%B8%A7%E0%B9%88%E0%B8%B2-f85caac0183d

https://medium.com/@iamgique/what-redis-is-4381ff32880d

https://codeburst.io/redis-what-and-why-d52b6829813

--

--