redis的安装与使用

1. redis的安装

  1. 下载

    下载链接

  2. 解压

    [hadoop@spark000 software]$ tar -zxvf redis-5.0.5.tar.gz -C ~/app
    
  3. 编译

    [hadoop@spark000 software]$ cd ~/app/redis-5.0.5/
    [hadoop@spark000 redis-5.0.5]$ make
    [hadoop@spark000 redis-5.0.5]$ make install
    

    出现问题
    make install 权限

    Error:Permission denied
    Solve:使用 sudo make install
    sudo
    Error:hadoop is not in the sudoers file. This incident will be reported.

    Solve:

    1. 切到 root 用户

    2. 添加 sudo 文件的写权限

      [root@spark000 ~]# chmod u+w /etc/sudoers
      
    3. 编辑 sudoers 文件

      [root@spark000 ~]# vim /etc/sudoers
      

      找到这行 root ALL=(ALL) ALL,在它下面添加 hadoop ALL=(ALL) ALL (这里的hadoop是你的用户名),如图
      sudoers

    4. 撤销 sudoers 文件写权限

      [root@spark000 ~]# chmod u-w /etc/sudoers
      
    5. 扩展

      # 你可以在 sudoers 文件中添加下面四行中任意一个 
      youruser ALL=(ALL) ALL :允许用户 youruser 执行 sudo 命令(需要输入密码)。
      %youruser ALL=(ALL) ALL :允许用户组 youruser 里面的用户执行 sudo 命令(需要输入密码)。
      youruser ALL=(ALL) NOPASSWD: ALL :允许用户 youruser 执行 sudo 命令,并且在执行的时候不输入密码。
      %youruser ALL=(ALL) NOPASSWD: ALL :允许用户组 youuser 里面的用户执行 sudo 命令,并且在执行的时候不输入密码。
      
  4. 此时再输入 sudo make install
    在这里插入图片描述

  5. 配置 redis.conf ,后台启动

    [hadoop@spark000 redis-5.0.5]$ vim redis.conf
    1). # bind 127.0.0.1 (将此行注释掉)
    2). protected-mode no (测试阶段改为 no)
    3). daemonize yes (进程后台启动)
    4). logfile "/home/hadoop/data/redislogs/redis.log" (启动日志)
    
  6. 启动

    [hadoop@spark000 redis-5.0.5]$ src/redis-server redis.conf
    [hadoop@spark000 redis-5.0.5]$ src/redis-cli -h spark000 -p 6379
    spark000:6379>
    
  7. 测试

    如果redis.conf配置文件中的 bind 127.0.0.1 没有被注释掉
    则
    [hadoop@spark000 redis-5.0.5]$ src/redis-cli -h spark000 -p 6379
    Could not connect to Redis at spark000:6379: Connection refused
    not connected>
    不能连接其他主机
    
    此时发现
      1)当注释掉此行启动时
        [hadoop@spark000 redislogs]$ ps -ef|grep redis
        hadoop   58038     1  0 11:01 ?        00:00:00 src/redis-server *:6379
        hadoop   58045 57947  0 11:02 pts/0    00:00:00 grep --color=auto redis
      2)此行没有被注释时
        [hadoop@spark000 redislogs]$ ps -ef|grep redis
        hadoop   58057     1  0 11:04 ?        00:00:00 src/redis-server 127.0.0.1:6379
        hadoop   58062 57947  0 11:04 pts/0    00:00:00 grep --color=auto redis
    

2. redis命令的使用

  • 如果你想查看 string 的使用方法
    在命令行输入

    127.0.0.1:6379> help @string
    APPEND key value
    summary: Append a value to a key
    since: 2.0.0
    
    GET key
    summary: Get the value of a key
    since: 1.0.0
    
    INCR key
    summary: Increment the integer value of a key by one
    since: 1.0.0
    
    INCRBY key increment
    summary: Increment the integer value of a key by the given amount
    since: 1.0.0
    
    INCRBYFLOAT key increment
    summary: Increment the float value of a key by the given amount
    since: 2.6.0
    
    MGET key [key ...]
    summary: Get the values of all the given keys
    since: 1.0.0
    
    MSET key value [key value ...]
    summary: Set multiple keys to multiple values
    since: 1.0.1
    
    ......
    
  • hash,list,set,sorted set 等命令查看方法一致

  • 查看redis版本号

    redis-cli -v 
    redis-cli --version
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值