Redis的公共操作命令

目錄

    • 1.Key操作命令
      • 1.1 `keys *`
      • 1.2 `exists <key]>`
      • 1.3 `type <key>`
      • 1.4 `del <key>`
      • 1.5 `unlink <key>`
      • 1.6 `ttl <key>`
      • 1.7 `expire <key> <秒數>`
      • 1.8 `move <key> <index>`
    • 2.庫操作命令
      • 2.1 `select <index>`
      • 2.2 `dbsize`
      • 2.3 `flushdb`
      • 2.4 `flushall`
    • 3.其他命令
      • 3.1 `help @<type>`

1.Key操作命令

Redis是Key-Value數據庫,Key都是字符串且區分大小寫,關于Redis的key操作,主要有常見的以下幾個

Redis的命令是不區分大小寫的

1.1 keys *

查看當前庫所有的Key,類似于數據庫的select * from tb_xxx

127.0.0.1:6379> keys *
1) "k1"
2) "k2"

1.2 exists <key]>

Key是否存在,返回bool,1代表true,0代表false

127.0.0.1:6379> exists k1
(integer) 1
127.0.0.1:6379> exists k2
(integer) 1
127.0.0.1:6379> exists k3
(integer) 0

Redis的底層使用C語言實現,很多命令返回bool時,多用0和1表示

1.3 type <key>

key對應的value是什么類型

127.0.0.1:6379> type k1
string

1.4 del <key>

刪除數據,返回bool

127.0.0.1:6379> del k2
(integer) 1

1.5 unlink <key>

非阻塞刪除,僅僅將key從keyspace元數據中刪除,真正的數據刪除將在后續異步進行,返回bool

127.0.0.1:6379> unlink k1
(integer) 1

1.6 ttl <key>

查看key還有多少秒過期,-1代表永不過期,-2代表已過期,通常和expire命令搭配使用

127.0.0.1:6379> ttl k1
(integer) -1

1.7 expire <key> <秒數>

為指定的key設置過期時間

127.0.0.1:6379> expire k1 100
(integer) 1
127.0.0.1:6379> ttl k1
(integer) 90
127.0.0.1:6379> ttl k1
(integer) 86

1.8 move <key> <index>

將當前key移動到指定的數據庫中,返回bool

127.0.0.1:6379> move k1 2
(integer) 1

2.庫操作命令

2.1 select <index>

選中幾號倉庫。redis.conf配置文件默認Redis共16個數據庫(0-15),默認選中0號庫

127.0.0.1:6379> select 2
OK
127.0.0.1:6379[2]> select 3
OK
127.0.0.1:6379[3]> 

2.2 dbsize

查看當前庫有多少key

127.0.0.1:6379[3]> dbsize
(integer) 0
127.0.0.1:6379[3]> set k1 v1
OK
127.0.0.1:6379[3]> dbsize
(integer) 1
127.0.0.1:6379[3]> 

2.3 flushdb

清空當前庫中的所有key

127.0.0.1:6379> flushdb
OK

2.4 flushall

清空整個Redis中的所有key

127.0.0.1:6379> flushall
OK

3.其他命令

3.1 help @<type>

命令行下輸入help @<type>命令,redis服務器會返回該數據類型的所有用法

127.0.0.1:6379> help @stringAPPEND key value
summary: Appends a string to the value of a key. Creates the key if it doesn't exist.
since: 2.0.0DECR key
summary: Decrements the integer value of a key by one. Uses 0 as initial value if the key doesn't exist.
since: 1.0.0DECRBY key decrement
summary: Decrements a number from the integer value of a key. Uses 0 as initial value if the key doesn't exist.
since: 1.0.0GET key
summary: Returns the string value of a key.
since: 1.0.0GETDEL key
summary: Returns the string value of a key after deleting the key.
since: 6.2.0GETEX key [EX seconds|PX milliseconds|EXAT unix-time-seconds|PXAT unix-time-milliseconds|PERSIST]
summary: Returns the string value of a key after setting its expiration time.
since: 6.2.0GETRANGE key start end
summary: Returns a substring of the string stored at a key.
since: 2.4.0GETSET key value
summary: Returns the previous string value of a key after setting it to a new value.
since: 1.0.0INCR key
summary: Increments the integer value of a key by one. Uses 0 as initial value if the key doesn't exist.
since: 1.0.0INCRBY key increment
summary: Increments the integer value of a key by a number. Uses 0 as initial value if the key doesn't exist.
since: 1.0.0INCRBYFLOAT key increment
summary: Increment the floating point value of a key by a number. Uses 0 as initial value if the key doesn't exist.
since: 2.6.0LCS key1 key2 [LEN] [IDX] [MINMATCHLEN min-match-len] [WITHMATCHLEN]
summary: Finds the longest common substring.
since: 7.0.0MGET key [key ...]
summary: Atomically returns the string values of one or more keys.
since: 1.0.0MSET key value [key value ...]
summary: Atomically creates or modifies the string values of one or more keys.
since: 1.0.1MSETNX key value [key value ...]
summary: Atomically modifies the string values of one or more keys only when all keys don't exist.
since: 1.0.1PSETEX key milliseconds value
summary: Sets both string value and expiration time in milliseconds of a key. The key is created if it doesn't exist.
since: 2.6.0SET key value [NX|XX] [GET] [EX seconds|PX milliseconds|EXAT unix-time-seconds|PXAT unix-time-milliseconds|KEEPTTL]
summary: Sets the string value of a key, ignoring its type. The key is created if it doesn't exist.
since: 1.0.0SETEX key seconds value
summary: Sets the string value and expiration time of a key. Creates the key if it doesn't exist.
since: 2.0.0SETNX key value
summary: Set the string value of a key only when the key doesn't exist.
since: 1.0.0SETRANGE key offset value
summary: Overwrites a part of a string value with another by an offset. Creates the key if it doesn't exist.
since: 2.2.0STRLEN key
summary: Returns the length of a string value.
since: 2.2.0SUBSTR key start end
summary: Returns a substring from a string value.
since: 1.0.0127.0.0.1:6379> 

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/900232.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/900232.shtml
英文地址,請注明出處:http://en.pswp.cn/news/900232.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【LLM】使用MySQL MCP Server讓大模型輕松操作本地數據庫

隨著MCP協議&#xff08;Model Context Protocol&#xff09;的出現&#xff0c;使得 LLM 應用與外部數據源和工具之間的無縫集成成為可能&#xff0c;本章就介紹如何通過MCP Server讓LLM能夠直接與本地的MySQL數據庫進行交互&#xff0c;例如新增、修改、刪除數據&#xff0c;…

【C++】從零實現Json-Rpc框架(2)

目錄 JsonCpp庫 1.1- Json數據格式 1.2 - JsonCpp介紹 ? 序列化接口 ? 反序列化接口 1.3 - Json序列化實踐 JsonCpp使用 Muduo庫 2.1 - Muduo庫是什么 2.2 - Muduo庫常見接口介紹 TcpServer類基礎介紹 EventLoop類基礎介紹 TcpConnection類基礎介紹 TcpClient…

語文常識推翻百年“R完備、封閉”論

?語文常識推翻百年“R完備、封閉”論 黃小寧 李四光&#xff1a;迷信權威等于扼殺智慧。語文常識表明從西方傳進來的數學存在重大錯誤&#xff1a;將無窮多各異數軸誤為同一軸。 復平面z各點z的對應點zk的全體是zk平面。z面平移變換為zk&#xff08;k是非1正實常數&#xf…

【Vue】 核心特性實戰解析:computed、watch、條件渲染與列表渲染

目錄 一、計算屬性&#xff08;computed&#xff09; ? 示例&#xff1a; 計算屬性-methods實現&#xff1a;在插值模塊里&#xff0c;實現函數的調用功能 計算屬性-computed的實現&#xff1a; 計算屬性-簡寫&#xff1a; ? 特點&#xff1a; ?? 與 methods 的區別…

二叉樹 遞歸

本篇基于b站靈茶山艾府的課上例題與課后作業。 104. 二叉樹的最大深度 給定一個二叉樹 root &#xff0c;返回其最大深度。 二叉樹的 最大深度 是指從根節點到最遠葉子節點的最長路徑上的節點數。 示例 1&#xff1a; 輸入&#xff1a;root [3,9,20,null,null,15,7] 輸出&…

與 AI 共舞:解鎖自我提升的無限可能

與 AI 共舞&#xff1a;解鎖自我提升的無限可能 在數字化浪潮的洶涌沖擊下&#xff0c;人工智能&#xff08;AI&#xff09;正以前所未有的速度重塑著世界的每一個角落。從日常生活的點滴便利到復雜工作的高效推進&#xff0c;AI 的力量無處不在。然而&#xff0c;面對 AI 的強…

【網絡安全論文】筑牢局域網安全防線:策略、技術與實戰分析

【網絡安全論文】筑牢局域網安全防線:策略、技術與實戰分析 簡述一、引言1.1 研究背景1.2 研究目的與意義1.3 國內外研究現狀1.4 研究方法與創新點二、局域網網絡安全基礎理論2.1 局域網概述2.1.1 局域網的定義與特點2.1.2 局域網的常見拓撲結構2.2 網絡安全基本概念2.2.1 網絡…

MoE Align Sort在醫院AI醫療領域的前景分析(代碼版)

MoE Align & Sort技術通過優化混合專家模型(MoE)的路由與計算流程,在醫療數據處理、模型推理效率及多模態任務協同中展現出顯著優勢,其技術價值與應用意義從以下三方面展開分析: 一、方向分析 1、提升醫療數據處理效率 在醫療場景中,多模態數據(如醫學影像、文本…

[ctfshow web入門] web4

前置知識 robots.txt是機器人協議&#xff0c;在使用爬蟲爬取網站內容時應該遵循的協議。協議并不能阻止爬蟲爬取&#xff0c;更像是一種道德規范。 假設robots.txt中寫道 Disallow: /admind.php&#xff0c;那我就暴露了自己的后臺&#xff0c;這屬于信息泄漏&#xff0c;攻擊…

innodb如何實現mvcc的

InnoDB 實現 MVCC&#xff08;多版本并發控制&#xff09;的機制主要依賴于 Undo Log&#xff08;回滾日志&#xff09;、Read View&#xff08;讀視圖&#xff09; 和 隱藏的事務字段。以下是具體實現步驟和原理&#xff1a; 1. 核心數據結構 InnoDB 的每一行數據&#xff08…

coding ability 展開第九幕(位運算——進階篇)超詳細!!!!

文章目錄 前言丟失的數字兩整數之和只出現一次的數字II消失的兩個數字總結 前言 上一篇博客&#xff0c;我們已經把位運算的基礎知識&#xff0c;以及基本運算都掌握啦 上次的習題還是讓人意猶未盡&#xff0c;今天我們來嘗試一下難一點的題目 位運算熟練起來真的讓人覺得做題是…

【數據結構篇】算法征途:穿越時間復雜度與空間復雜度的迷霧森林

文章目錄 【數據結構篇】算法征途&#xff1a;穿越時間復雜度與空間復雜度的迷霧森林 一、 什么是算法1. 算法的定義1.1 算法的五個特征1.2 好算法的特質 2. 時間復雜度3. 空間復雜度 【數據結構篇】算法征途&#xff1a;穿越時間復雜度與空間復雜度的迷霧森林 &#x1f4ac;歡…

Logo語言的系統監控

Logo語言的系統監控 引言 在信息技術飛速發展的時代&#xff0c;系統監控成為了確保計算機系統和網絡平穩運行的重要手段。系統監控不僅可以實時跟蹤系統的性能、資源使用情況和安全風險等&#xff0c;還能夠在出現問題時及時發出警報&#xff0c;從而避免潛在的故障和損失。…

STP學習

{所有內容均來自于西安歐鵬的陳俊老師} STP生成樹 當二層交換機意外成環路的時候會發生&#xff1a; 1.廣播風暴&#xff1a;當廣播幀進入環路時&#xff0c;會被不斷復制并傳輸&#xff0c;導致網絡中的廣播流量急劇增加&#xff0c;消耗大量的網絡帶寬&#xff0c;降低網絡…

使用RKNN進行yolo11-cls部署

文章目錄 概要制作數據集模型訓練onnx導出rknn導出概要 YOLO(You Only Look Once)是一系列高效的目標檢測算法,其核心思想是將目標檢測任務轉化為一個回歸問題,通過單個神經網絡直接在圖像上預測邊界框和類別概率。當將其用于分類任務時,會去除目標檢測相關的邊界框預測部…

【MySQL】01.MySQL環境安裝

注意&#xff1a;在MYSQL的安裝與卸載中&#xff0c;需要使用root用戶進行。 一、卸載不必要的環境 ? 查看是否有運行的服務 [rootVM-24-10-centos etc]# ps axj |grep mysql1 22030 22029 22029 ? -1 Sl 27 0:00 /usr/sbin/mysqld --daemonize --pid-fi…

程序化廣告行業(59/89):廣告驗證與反作弊實戰技巧

程序化廣告行業&#xff08;59/89&#xff09;&#xff1a;廣告驗證與反作弊實戰技巧 大家好&#xff01;在程序化廣告領域&#xff0c;想要做好投放&#xff0c;除了了解基本的架構和原理&#xff0c;還得掌握一些關鍵的技能&#xff0c;比如廣告驗證和反作弊。今天就和大家一…

矢量瓦片切片工具

1.geoserver 可以生成geojson mvt(pbf) tojson 三種格式矢量瓦片 2.mapbox的tippecanoe 可以生成pbf矢量瓦片&#xff0c;文件夾形式和mbtiles兩種 3.TileStache python工具&#xff0c;可以生成geojson瓦片 4.PostGis mapbox插件可以生成pbf瓦片&#xff0c;據說是動態切片…

Windows 系統 Git 2.15.0 (64位) 下載與安裝教程

1. 下載 Git 2.15.0 (64位) 安裝包 下載地址&#xff1a;https://pan.quark.cn/s/f817ab9285dc 2. 運行安裝程序 雙擊下載的 Git-2.15.0-64-bit.exe。 如果系統提示安全警告&#xff0c;選擇 “運行”&#xff08;確認來源可信&#xff09;。 3. 安裝向導設置 按以下步驟配…

MCP服務器:AI與外部工具交互的橋梁——Python和代理AI工具集成指南

&#x1f9e0; 向所有學習者致敬&#xff01; “學習不是裝滿一桶水&#xff0c;而是點燃一把火。” —— 葉芝 我的博客主頁&#xff1a; https://lizheng.blog.csdn.net &#x1f310; 歡迎點擊加入AI人工智能社區&#xff01; &#x1f680; 讓我們一起努力&#xff0c;共創…