在平時(shí)的工作中,需要根據(jù)需求對(duì)redis數(shù)據(jù)庫(kù)進(jìn)行一些操作。
為萬(wàn)州等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及萬(wàn)州網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、外貿(mào)網(wǎng)站建設(shè)、萬(wàn)州網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
可以參考Redis官網(wǎng)http://redis.io/commands 進(jìn)行詳細(xì)了解
1.SELECT 切換數(shù)據(jù)庫(kù)
redis 127.0.0.1:6379[1]> HELP SELECT SELECT index summary: Change the selected database for the current connection since: 1.0.0 group: connection redis 127.0.0.1:6379[1]> SELECT 2 OK
2.LLEN 得到一個(gè)列表的長(zhǎng)度
redis 127.0.0.1:6379[2]> HELP LLEN LLEN key summary: Get the length of a list since: 1.0.0 group: list redis 127.0.0.1:6379[2]> LLEN bi (integer) 412
3.LRANGE 獲取一個(gè)列表的所有元素
LRANGE 索引是以0開始的,0表示第一個(gè)元素,-1表示最后一個(gè)元素
LRANGE key start stop summary: Get a range of elements from a list since: 1.0.0 group: list redis 127.0.0.1:6379[2]> LRANGE bi 0 5
4.LPUSH 將一個(gè)或多個(gè)值添加到一個(gè)列表的開頭
redis 127.0.0.1:6379[2]> HELP LPUSH LPUSH key value [value ...] summary: Prepend one or multiple values to a list since: 1.0.0 group: list redis 127.0.0.1:6379[2]> LPUSH bi http://abc.com/logUserLogin?event_id=25&uid=de721bcef5cba1fc182d18
5.RPUSH 將一個(gè)或多個(gè)值追加到一個(gè)列表的末尾
redis 127.0.0.1:6379[2]> HELP RPUSH RPUSH key value [value ...] summary: Append one or multiple values to a list since: 1.0.0 group: list redis 127.0.0.1:6379[2]> RPUSH bi http://abc.com/logUserLogin?event_id=25&uid=de721bcef5cba1fc182d18
6.SAVE 同步數(shù)據(jù)到磁盤
SAVE命令執(zhí)行的時(shí)候會(huì)阻塞連接,所以生成環(huán)境最好使用BGSAVE命令
redis 127.0.0.1:6379[2]> HELP SAVE SAVE - summary: Synchronously save the dataset to disk since: 1.0.0 group: server redis 127.0.0.1:6379[2]> SAVE OK (1.33s)
7.BGSAVE 異步數(shù)據(jù)到磁盤
使用BGSAVE,Redis將會(huì)在后臺(tái)執(zhí)行保存數(shù)據(jù)的操作,不影響正常的客戶端連接,Redis將會(huì)fork出一個(gè)子進(jìn)程用于保存數(shù)據(jù),父進(jìn)程繼續(xù)處理客戶端請(qǐng)求。
redis 127.0.0.1:6379[2]> HELP BGSAVE BGSAVE - summary: Asynchronously save the dataset to disk since: 1.0.0 group: server redis 127.0.0.1:6379[2]> BGSAVE Background saving started
8.TYPE 判斷一個(gè)KEY的類型
redis 127.0.0.1:6379[2]> HELP TYPE TYPE key summary: Determine the type stored at key since: 1.0.0 group: generic redis 127.0.0.1:6379[2]> TYPE bi list
9.BGREWRITEAOF
異步重寫AOF文件,Redis將會(huì)創(chuàng)建一個(gè)對(duì)當(dāng)前AOF文件優(yōu)化過(guò)的AOF版本。
redis 127.0.0.1:6379> help BGREWRITEAOF BGREWRITEAOF - summary: Asynchronously rewrite the append-only file since: 1.0.0 group: server
10.CONFIG GET
獲取某個(gè)配置項(xiàng)的值
redis 127.0.0.1:6379> help config get CONFIG GET parameter summary: Get the value of a configuration parameter since: 2.0.0 group: server redis 127.0.0.1:6379> config get maxmemory 1) "maxmemory" 2) "0"
11.CONFIG SET
設(shè)置某個(gè)參數(shù)的值
redis 127.0.0.1:6379> help config set CONFIG SET parameter value summary: Set a configuration parameter to the given value since: 2.0.0 group: server redis 127.0.0.1:6379> config set maxmemory 200000000 OK
12.DBSIZE
返回當(dāng)前數(shù)據(jù)庫(kù)的KEY值得數(shù)量
redis 127.0.0.1:6379[3]> HELP DBSIZE DBSIZE - summary: Return the number of keys in the selected database since: 1.0.0 group: server redis 127.0.0.1:6379[3]> dbsize (integer) 12502
13.DEL
刪除一個(gè)KEY值
redis 127.0.0.1:6379> help del DEL key [key ...] summary: Delete a key since: 1.0.0 group: generic redis 127.0.0.1:6379> del foo (integer) 1
14.EXISTS
檢查一個(gè)KEY是否存在
redis 127.0.0.1:6379> help exists EXISTS key summary: Determine if a key exists since: 1.0.0 group: generic redis 127.0.0.1:6379> exists foo (integer) 1
15.SET 命令
設(shè)置一個(gè)KEY的值
redis 127.0.0.1:6379> help set SET key value summary: Set the string value of a key since: 1.0.0 group: string redis 127.0.0.1:6379> set foo test OK redis 127.0.0.1:6379>
16.PERSIST
刪除一個(gè)KEY的過(guò)期時(shí)間
edis 127.0.0.1:6379> help persist PERSIST key summary: Remove the expiration from a key since: 2.2.0 group: generic
17.RENAME
重新命名一個(gè)KEY
redis 127.0.0.1:6379> help rename RENAME key newkey summary: Rename a key since: 1.0.0 group: generic redis 127.0.0.1:6379> rename foo footest OK redis 127.0.0.1:6379>
18.EXPIRE
為一個(gè)KEY設(shè)置一個(gè)TTL過(guò)期時(shí)間
redis 127.0.0.1:6379> help expire EXPIRE key seconds summary: Set a key's time to live in seconds since: 1.0.0 group: generic redis 127.0.0.1:6379> expire footest 300 (integer) 1
19.TTL
獲取過(guò)期時(shí)間
redis 127.0.0.1:6379> help ttl TTL key summary: Get the time to live for a key since: 1.0.0 group: generic redis 127.0.0.1:6379> ttl footest (integer) 289 redis 127.0.0.1:6379> ttl footest (integer) 285 redis 127.0.0.1:6379> ttl footest (integer) 283 redis 127.0.0.1:6379> ttl footest (integer) 282 redis 127.0.0.1:6379> ttl footest (integer) 282 redis 127.0.0.1:6379>
20.EXPIREAT
設(shè)置一個(gè)KEY的過(guò)期時(shí)間,以UNIX時(shí)間戳表示
redis 127.0.0.1:6379> help expireat EXPIREAT key timestamp summary: Set the expiration for a key as a UNIX timestamp since: 1.2.0 group: generic redis 127.0.0.1:6379> expireat foo 1431532800 (integer) 1 redis 127.0.0.1:6379> ttl foo (integer) 3210141
21.GET
獲取一個(gè)KEY的值
redis 127.0.0.1:6379> help get GET key summary: Get the value of a key since: 1.0.0 group: string redis 127.0.0.1:6379> get foo "test"
22.HGET
獲取一個(gè)哈希字段的值
redis 127.0.0.1:6379> help hget HGET key field summary: Get the value of a hash field since: 2.0.0 group: hash redis 127.0.0.1:6379> hset myhash field1 "foo" (integer) 1 redis 127.0.0.1:6379> hget myhash field1 "foo" redis 127.0.0.1:6379> hget myhash field2 (nil) redis 127.0.0.1:6379>
23.LASTSAVE
上次成功保存數(shù)據(jù)到磁盤的UNIX時(shí)間戳
redis 127.0.0.1:6379> help lastsave LASTSAVE - summary: Get the UNIX time stamp of the last successful save to disk since: 1.0.0 group: server redis 127.0.0.1:6379> lastsave (integer) 1428373205 redis 127.0.0.1:6379>
24.LPUSH
將一個(gè)或多個(gè)值附加到一個(gè)Redis列表中
redis 127.0.0.1:6379> help lpush LPUSH key value [value ...] summary: Prepend one or multiple values to a list since: 1.0.0 group: list redis 127.0.0.1:6379> lpush mylist a b c (integer) 6 redis 127.0.0.1:6379> LRANGE mylist 0 -1 1) "c" 2) "b" 3) "a" 4) "c" 5) "b" 6) "a" redis 127.0.0.1:6379> llen mylist (integer) 6
分享題目:王高利:Redis運(yùn)維之常用命令操作
鏈接分享:http://chinadenli.net/article26/jgcicg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、動(dòng)態(tài)網(wǎng)站、靜態(tài)網(wǎng)站、小程序開發(fā)、網(wǎng)站營(yíng)銷、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)