zoukankan      html  css  js  c++  java
  • Linux环境下redis常用命令

    ps -ef | grep redis        ps -ef是查看所有的进程的 然后用grep筛选出你要的信息,redis是我筛选的信息
    

      

    1 注册服务:
    2 redis-server --service-install redis.windows.conf --loglevel verbose
    3 卸载服务:
    4 redis-server --service-uninstall
    5 注册情况下启动和停止-server-start
    6            server-stop

      

    没注册情况下启动和停止-
    启动Redis:
    redis-server --service-start
    停止Redis:
    redis-server --service-stop
    
      1                  Redis命令
      2 1--    redis-cli的使用之发送命令
      3 默认连接:IP 127.0.0.1 端口 6379
      4 redis-cli
      5 指定IP端口:
      6     redis-cli –h 127.0.0.1 –p 6379
      7     Redis提供了PING-PONG机制,测试与客户端和服务器链接是否正常
      8     redis-cli ping
      9  10     redis-cli
     11     redis 127.0.0.1:6379>ping
     12     PONG
     13 
     14 2--    redis-cli的使用之命令返回值
     15 状态回复(最简单的回复-redis提供的测试命令)
     16 redis>PING
     17 PONG
     18 127.0.0.1:6379>SET test 123
     19 OK
     20 错误回复(以error开头,后面跟着错误信息)
     21 127.0.0.1:6379>TEST
     22 (error) ERR unknown command 'TEST'
     23 整数回复
     24 127.0.0.1:6379>INCR test_incr
     25 (integer) 1
     26 字符串回复(最长久的一种回复,双引号包裹)
     27 127.0.0.1:6379>get test
     28 “123 29 多行字符串回复
     30 127.0.0.1:6379>KEYS *
     31 1) "test_incr"
     32 2) "test"
     33 
     34 3--    退出
     35 127.0.0.1:6379> exit
     36 
     37 4--    关闭
     38 127.0.0.1:6379> shutdown
     39 
     40 5--    基本命令KEYS GET SET
     41 字符串类型是redis中最基本的数据类型,它能存储任何形式的字符串,包括二进制数据。可以存储JSON化的对象、字节数组等。一个字符串类型键允许存储的数据最大容量是512MB。
     42 赋值与取值:
     43 SET key value
     44 GET key
     45 127.0.0.1:6379> keys *
     46 (empty list or set)
     47 127.0.0.1:6379> set test 123
     48 OK
     49 127.0.0.1:6379> set test1 ab
     50 OK
     51 127.0.0.1:6379> keys *
     52 1) "test1"
     53 2) "test"
     54 127.0.0.1:6379> get test
     55 "123"
     56 127.0.0.1:6379> get test1
     57 "abc"
     58 127.0.0.1:6379> get test2
     59 (nil)
     60 127.0.0.1:6379>
     61 
     62 6--    redis数据库切换SELECT
     63 redis默认支持16个数据库,对外都是以一个从0开始的递增数字命名,可以通过参数database来修改默认数据库个数。客户端连接redis服务后会自动选择0号数据库,可以通过select命令更换数据库,例如选择1号数据库:
     64 127.0.0.1:6379>SELECT 1
     65 OK
     66 127.0.0.1:6379>GET test
     67 (nil)
     68 说明:
     69 Redis不支持自定义数据库名称。
     70 Redis不支持为每个数据库设置访问密码。
     71 Redis的多个数据库之间不是安全隔离的,FLUSHALL命令会清空所有数据库的数据。
     72 
     73 7--    redis的基本命令之KEYS
     74 获取符合规则的建名列表。
     75 KEYS *
     76 keys test[_]*
     77 keys t[a-d]
     78 说明:
     79 ?    匹配一个字符
     80 *   匹配任意个(包括0个)字符
     81 []  匹配括号间的任一字符,可以使用“-“表示范围。如a[a-d]匹配ab/ac/ad
     82 x    匹配字符x,用于转义符合,如果要匹配“?“就需要使用?
     83 
     84 8--    redis的基本命令之EXISTS
     85 判断一个键是否存在。
     86 如果键存在则返回整数类型1,否则返回0。
     87 127.0.0.1:6379> keys *
     88 1) "test_incr"
     89 2) "test"
     90 127.0.0.1:6379> exists test
     91 (integer) 1
     92 127.0.0.1:6379> exists test1
     93 (integer) 0
     94 127.0.0.1:6379>
     95 
     96 9--    redis的基本命令之DEL
     97 删除键,可以删除一个或者多个键,多个键用空格隔开,返回值是删除的键的个数。
     98 127.0.0.1:6379> del test
     99 (integer) 1
    100 127.0.0.1:6379> del test
    101 (integer) 0
    102 127.0.0.1:6379> del test test_incr
    103 (integer) 1
    104 127.0.0.1:6379>
    105 
    106 10--    redis的基本命令之TYPE
    107 获得键值的数据类型,返回值可能是string(字符串)、hash(散列类型)、list(列表类型)、set(集合类型)、zset(有序集合类型)。
    108 127.0.0.1:6379> keys *
    109 1) "test1"
    110 2) "test"
    111 127.0.0.1:6379> type test
    112 string
    113 127.0.0.1:6379> type test1
    114 string
    115 
    116 11--    redis的基本命令之HELP
    117 127.0.0.1:6379> help
    118 redis-cli 2.8.19
    119 Type: "help @<group>" to get a list of commands in <group>
    120       "help <command>" for help on <command>
    121       "help <tab>" to get a list of possible help topics
    122       "quit" to exit
    123 127.0.0.1:6379> help type
    124 
    125   TYPE key
    126   summary: Determine the type stored at key
    127   since: 1.0.0
    128   group: generic
    129 
    130 官网:http://www.redis.io帮助
    131  
    132 12--    redis的基本命令之FLUSHALL
    133 清空所有数据库。
    134 127.0.0.1:6379> FLUSHALL
    135 OK
    136 
    137 13.    redis的基本命令之FLUSHDB
    138 清空当前数据库。
    139 127.0.0.1:6379> FLUSHDB
    140 OK
    141  
    1)info                    #查看所有信息
       info Replication        #只查看Replication片段信息 查看角色
    
    2)CentOS 配置防火墙操作实例(启、停、开、闭端口):
    注:防火墙的基本操作命令:
    查询防火墙状态:
    [root@localhost ~]# service   iptables status
    停止防火墙:
    [root@localhost ~]# service   iptables stop
    启动防火墙:
    [root@localhost ~]# service   iptables start
    重启防火墙:
    [root@localhost ~]# service   iptables restart
    永久关闭防火墙:
    [root@localhost ~]# chkconfig   iptables off
    永久关闭后启用:
    [root@localhost ~]# chkconfig   iptables on
    
    3)主从复制配置:
    slaveof 192.168.80.21 6379(主上的IP地址)    #挂接到主
    第一次执行slaveof,会全部内容进行复制。(全量复制)


    pwd 查询当前路径
    
    
    
     
  • 相关阅读:
    感知机学习算法 python实现
    最小二乘法 python实现
    python数据结构与算法——图的基本实现及迭代器
    python数据结构与算法——二叉树结构与遍历方法
    python数据结构与算法——字典树
    python数据结构与算法——完全树 与 最小/大堆
    win2008服务器asp站点配置要点
    SQL Server分页语句ROW_NUMBER,读取第4页数据,每页10条
    WinForm Control.Invoke&Control.BeginInvoke异步操作控件实例
    Couchbase应用示例(初探)
  • 原文地址:https://www.cnblogs.com/dgsh/p/6561021.html
Copyright © 2011-2022 走看看