• redis 入门


    (一)安装

    redis官方下载安装链接:https://redis.io/download

    按照官网的来总流程上是没问题的。不过我本地还是有点小问题。

    1、到你想安装的目录

    $ wget http://download.redis.io/releases/redis-3.2.8.tar.gz
    $ tar xzf redis-3.2.8.tar.gz
    $ cd redis-3.2.8
    $ make

    我的本地到make这就不行了,开始报错:提示缺少cc

    $ yum -y install gcc

    继续make,此时还是报错

    $ make CFLAGS="-march=x86-64"

    再make,就ok了。

    下面按官网的启动服务

    $ src/redis-server

    (二)java通过Jedis来操作

    这里说下我的环境:测试java连接是在我windows本地,redis装在我的虚拟机上

    package test.com.redis;
    
    import redis.clients.jedis.Jedis;
    
    public class RedisDemo {
    
        public static void main(String[] args) {
            Jedis jedis = new Jedis("10.99.8.166",6379);
    //        Jedis jedis = new Jedis("10.99.8.166");
    //        jedis.auth("admin");
            jedis.set("name", "vincent");
            System.out.println(jedis.get("name"));
        }
    }

    此处运行将会报错,错误是这样的:

    DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified,
    no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface.
    If you want to connect from external computers to Redis you may adopt one of the following solutions:
    1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to
    Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so.
    Use CONFIG REWRITE to make this change permanent.
    2) Alternatively you can just disable the protected mode by editing the Redis configuration file,
    and setting the protected mode option to 'no', and then restarting the server.
    3) If you started the server manually just for testing, restart it with the '--protected-mode no' option.
    4) Setup a bind address or an authentication password. NOTE:
    You only need to do one of the above things in order for the server to start accepting connections from the outside.

    我采用的是第二种解决方式。

    1)setting the protected mode option to 'no' 和注掉本地绑定

     重新启动
    ./redis-server ../redis.conf

    此时再运行main方法就会输出了。

    (三)图形化界面

    下载地址:http://pan.baidu.com/s/1b7ewk2 密码:jk5a

    以上是我今天的学习总结。

  • 相关阅读:
    leetcode 39 Combination Sum
    C/C++ 单元测试 catch
    二叉树
    线性表
    POJ1002
    HDU4329
    hdu 4329
    java代码优化总结1
    Linux操作系统常用命令总结1
    java开发基础知识总结1
  • 原文地址:https://www.cnblogs.com/vincentren/p/6628190.html
Copyright © 2020-2023  润新知