zoukankan      html  css  js  c++  java
  • 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

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

  • 相关阅读:
    构建之法:第二次心得
    构建之法:第一次心得
    tomcat配置限制ip和建立图片服务器
    tomcat8.5优化配置
    java 操作 csv文件
    jsoup教学系列
    (转)js实现倒计时效果(年月日时分秒)
    本地启动tomcat的时候报java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space
    使用mybatis执行oracle存储过程
    java 获取web登录者的ip地址
  • 原文地址:https://www.cnblogs.com/vincentren/p/6628190.html
Copyright © 2011-2022 走看看