以前介紹過如何在ubuntu安裝Redis服務器:https://www.cnblogs.com/zifeiy/p/9062738.htmlhtml
接下來,咱們在Redis上進行一些基本的操做。
所縣使用命令:redis-cli
登錄Redis命令行。
而後執行下面的指令進行測試與學習:redis
### 增長一個值key爲name,value爲zifeiy 127.0.0.1:6379> set name 'zifeiy' OK ### 查詢name的值 127.0.0.1:6379> get name "zifeiy" ### 更新name的值 127.0.0.1:6379> set name 'yiefiz' OK ### 查詢name的值 127.0.0.1:6379> get name "yiefiz" ### 刪除namd的值 127.0.0.1:6379> del name (integer) 1 ### 查詢是溝存在name,0表示不存在 127.0.0.1:6379> exists name (integer) 0
### 添加key爲user_list,value爲'zifeiy','hello'的list集合 127.0.0.1:6379> lpush user_list 'zifeiy' 'hello' (integer) 2 ### 查詢key爲user_list的集合 127.0.0.1:6379> lrange user_list 0 -1 1) "hello" 2) "zifeiy" ### 往list底部添加love元素 127.0.0.1:6379> rpush user_list 'hi' (integer) 3 ### 查詢key爲user_list的集合 127.0.0.1:6379> lrange user_list 0 -1 1) "hello" 2) "zifeiy" 3) "hi" ### 更新index爲0的值 127.0.0.1:6379> lset user_list 0 'haha' OK ### 查詢key爲user_list的集合 127.0.0.1:6379> lrange user_list 0 -1 1) "haha" 2) "zifeiy" 3) "hi" ### 刪除第1個爲'wish'的值 127.0.0.1:6379> lrem user_list 0 'haha' (integer) 1 ### 查詢key爲user_list的集合 127.0.0.1:6379> lrange user_list 0 -1 1) "zifeiy" 2) "hi"
127.0.0.1:6379> flushdb OK 127.0.0.1:6379> hset user_hset "user1" "zifeiy" (integer) 1 127.0.0.1:6379> hset user_hset "user2" "apple" (integer) 1 127.0.0.1:6379> hlen user_hset (integer) 2 127.0.0.1:6379> hkeys user_hset 1) "user1" 2) "user2" 127.0.0.1:6379> hget user_hset "user1" "zifeiy" 127.0.0.1:6379> hgetall user_hset 1) "user1" 2) "zifeiy" 3) "user2" 4) "apple" 127.0.0.1:6379> hset user_hset "user1" "new_zifeiy" (integer) 0 127.0.0.1:6379> hset user_hset "user2" "banena" (integer) 0 127.0.0.1:6379> hgetall user_hset 1) "user1" 2) "new_zifeiy" 3) "user2" 4) "banena" 127.0.0.1:6379> hdel user_hset user1 (integer) 1 127.0.0.1:6379> hgetall user_hset 1) "user2" 2) "banena"
127.0.0.1:6379> flushdb OK 127.0.0.1:6379> zadd user_zset 1 "zifeiy" (integer) 1 127.0.0.1:6379> zadd user_zset 2 "banana" (integer) 1 127.0.0.1:6379> zadd user_zset 3 "hello" (integer) 1 127.0.0.1:6379> zrange user_zset 0 -1 1) "zifeiy" 2) "banana" 3) "hello" 127.0.0.1:6379> zrevrange user_zset 0 -1 1) "hello" 2) "banana" 3) "zifeiy" 127.0.0.1:6379> zscore user_zset "zifeiy" "1" 127.0.0.1:6379> zscore user_zset "hello" "3"