Redis

Efficient Data Management in Redis: Leveraging Hashes and Sets for One-to-Many Relationships

When designing a caching solution in Redis for a one-to-many relationship, such as a quiz with multiple member answers, it’s important to choose the right data structures to ensure efficient storage and retrieval. Redis offers several data structures that can be used to achieve this, including hashes and sets. Below, we discuss two common approaches: using hashes and using sets combined with hashes.

Continue Reading

Redis 安裝與入門教學

REDIS

首先安裝 Redis 環境

Download

下載Redis壓縮,解壓縮後,make執行安裝

wget http://download.redis.io/releases/redis-4.0.10.tar.gz
tar xzf redis-4.0.10.tar.gz
cd redis-4.0.10
make

啟動redis server

src/redis-server

啟動 redis clien

src/redis-cli

接著就能測試新增及取得一筆資料

> set name helloworld
OK
> get name
"helloworld"

常用指令

新增 SET 取得 GET

在測試新增及取得資料時,已經有使用過 SET 以及 GET 的方法

在 SET 資料時,可以透過冒號 : 來輔助設計key

例如,建立 admin 相關資料時,可以這樣做

set admin:name adam
set admin:id 1
set admin:phone 0912345678

get admin:name
get admin:id
get admin:phone

DEL INCR 增減數值

透過 DEL, INCR 來針對數值遞增或遞減

Continue Reading