Markdown

[Redis] KEY 設計

...
3 75             $redis = $this->container->get('snc_redis.default');~
3 76             $redis->SET("bank:bankid:$registerID:username","$registerUsername");~
3 77             $redis->SET("bank:bankid:$registerID:paassword","$registerPassword");~
3 78             $redis->SET("bank:bankid:$registerID:balance",'0');~

...
127.0.0.1:6379> KEYS *
1) "bank:bankid:121:balance"
2) "bank:bankid:121:username"
3) "bank:bankid:121:paassword"
127.0.0.1:6379> get "bank:bankid:121:balance"
"0"
127.0.0.1:6379> get "bank:bankid:121:username"
"C8763_6"
127.0.0.1:6379> get "bank:bankid:121:paassword"
"0000"
127.0.0.1:6379> scan 0 MATCH * COUNT 1000
1) "0"
2) 1) "bank:bankid:121:paassword"
   2) "bank:bankid:121:balance"
   3) "bank:bankid:121:username"
使用KEY 儲存的問題
trade:bankid:1:behavior:Deposit:tradeid:40630:tradeDate"
KEYS trade:bankid:1:behavior:Deposit:tradeid:40630*
會找到一堆0630的資料 要個別取直很麻煩
用LIST 就只會找到一筆0630 再把裡面資訊列出來比較方便
LPUSH
redis> LPUSH mylist "world"
(integer) 1
redis> LPUSH mylist "hello"
(integer) 2
redis> LRANGE mylist 0 -1
1) "hello"
2) "world"
LINDEX
redis> LPUSH mylist "World"
(integer) 1
redis> LPUSH mylist "Hello"
(integer) 2
redis> LINDEX mylist 0
"Hello"
redis> LINDEX mylist -1
"World"
redis> LINDEX mylist 3
(nil)

留言