Redis 簡介
Redis is an open-source, in-memory data structure store used as a database, cache, message broker, and streaming engine. It delivers sub-millisecond latency, supports rich data types (Strings, Hashes, Lists, Sets, Sorted Sets, Streams, JSON, vector sets), and scales horizontally with Redis Cluster. Redis also supports vector search for GenAI apps, including semantic search, RAG, and recommendation systems. Redis is free to use, runs anywhere, and offers a managed option through Redis Cloud.
反正就是說它很快、有資料結構、單執行緒,Blah Blah Blah。
簡單教學
通常會用 redis-cli,假設在 pollution.htb 的端口 6379 上找到 Reddis 的 Open Port:
$ nmap -sC -sV -p6379 pollution.htb
PORT STATE SERVICE VERSION
6379/tcp open redis Redis key-value store
我們就可以透過 redis-cli 與他互動:
$ redis-cli -h pollution.htb
pollution.htb:6379> AUTH COLLECTR3D1SPASS
OK
...<SNIP>...
而 Redis 其實就只是個 Python Dict:
redis = {}
redis["user:1:name"] = "Alice"
redis["page:views"] = 42大家習慣用 : 當作命名分隔,這樣查詢比較方便,像是 SCAN user:*。在 Redis 你會看到類似這樣的東西:
pollution.htb:6379> keys *
1) "PHPREDIS_SESSION:umicnume7bm2gf2opghp0pr129"
2) "PHPREDIS_SESSION:r8qne20hig1k3li6prgk91t33j"
透過 GET 查看鍵值:
pollution.htb:6379> GET PHPREDIS_SESSION:umicnume7bm2gf2opghp0pr129
""
透過 SET 設定鍵值:
pollution.htb:6379> SET PHPREDIS_SESSION:umicnume7bm2gf2opghp0pr129 'auth|b:1;'
OK
pollution.htb:6379> GET PHPREDIS_SESSION:umicnume7bm2gf2opghp0pr129
"auth|b:1;"
如果不熟,打到一半也會告訴你接下來該怎麼做:
