redis官方**
redis是一款開源的,高階的key-value資料儲存。支援眾多的資料型別,string,hash,list,set,sorted set。
wgettar zxvf redis-2.4.16
.tar.gz
cd redis-2.4.16
make
編譯之後在[redis-2.4.16\ src]目錄中有redis-server,用來啟動redis服務;redis-cli,redis客戶端,用來測試。
//儲存乙個key-value
set key value//獲取乙個key的value
get key set username "virusswb"get username
set connections 10//自增,也就是加1
incr connections//刪除元素
del connections//過期,120秒之後過期
expire username 120//獲取剩餘的生存時間,-1代表永不過期
ttl usernameredis的value除了支援簡單型別以外,還支援很多複雜的資料型別,讓我們先看一下list,list是有序的集合。你可以使用rpush, lpush, llen, lrange, lpop, and rpop命令來操作集合。集合的下標從0開始。
//在集合的尾部插入新值
rpush friends "tom"rpush friends "andy"
//在集合的頭部插入新值
lpush friends "bob"//獲取集合的長度,也是集合的元素個數
llen friends//獲取集合的子集合,第二個引數如果是-1,代表獲取從第乙個引數到尾部的全部
//資料
lrange friends 0 -1lrange friends 1 2
//返回集合的第一元素,也就是頭部元素,並且在集合中刪除這個元素
lpop friends//返回集合的最後乙個元素,也就是尾部元素,並且在集合中刪除這個元素
rpop friendsset也是redis支援的乙個value型別,set和list相似,但是set是無序的,並且集合中的元素不能重複。基本的操作包括:sadd, srem, sismember, smembers and sunion.
//新增元素
sadd superpowers "flight"sadd superpowers "x-ray"
sadd superpowers "reflex"
如果插入的元素已經在集合中存在,就不會進行插入操作,保證集合中不存在重複元素。
//刪除元素
srem superpowers "reflex"//判斷集合中是否存在元素
sismember superpowers "reflex"//返回集合的所有元素
smembers superpowers//合併兩個或者多個set集合,返回合併結果,合併會去除重複元素
sadd birdpowers "aaa"sadd birdpowers "x-ray"
sunion birdpowers superpowers
還有一種value型別,它是有序的set。每個元素和乙個score相關聯,score用來給元素排序。
zadd hackers 5 "aaa"zadd hackers 2 "bbb"
zadd hackers 9 "zzz"
zadd hackers 6 "kkk"
zrange hacker 2 6
zrange hackers 2 6
zrange hackers 0 -1
redis基本命令
一,基本操作 1.select index index 0 idnex 17選擇資料庫 3.shutdown 停止資料庫 4.config get loglevel 得到當前日誌級別 5.flushall 清空所有資料庫的資料 6.keys 遍歷當前資料庫中所有的鍵 7.type key 獲取鍵的型...
redis基本命令
redis是乙個記憶體資料庫,通常可以作為快取使用,常用的命令有 redis server 啟動資料庫,預設埠為6379 redis cli 連線資料庫,預設ip是127.0.0.1,埠是6379 redis cli h 127.0.0.1 p 6380 a 密碼 連線資料庫,指定主機和埠號 sel...
redis 基本命令
1 del key 該命令用於在 key 存在時刪除 key。dump key 序列化給定 key 並返回被序列化的值。exists key 檢查給定 key 是否存在。expire key seconds 為給定 key 設定過期時間。expireat key timestamp expireat...