1. redis 4.0.9 setup & jedis example

1.Centos 安装redis

    cd 

    mkdir redis

    cd redis

    wget  --no-check-certificate  https://github.com/antirez/redis/archive/4.0.9.tar.gz    

    tar xzf 4.0.9.tar.gz    

    cd redis-4.0.9/    

    make    

    cd src && make all    

    redis-server    
1.因为无法连接http://redis.io 所以此处使用github来下载redis压缩包;
2.操作中遇到无法验证证书问题,所以采用    --no-check-certificate
3.执行redis-server启动时有一个警告

WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

 意思是:
          解决方法是 修改配置文件 redis.conf:
            tcp-backlog 511
                          然后 修改 etc/sysctl.conf
                          添加 `net.core.somaxconn= 1024` 然后执行 `sysctl -p`  就可以永久消除这个warning
4.如果需要从别的ip进行调试,启动redis需要执行    `redis-server --protected-mode no`

2.使用java连接redis

    package com.jedis;

    import redis.clients.jedis.Jedis;

    public class JedisUtil {

	public static void main(String[] args) {

		Jedis jedis = new Jedis("redis://192.168.1.104:6379");

		jedis.set("foo", "bar");

		String value = jedis.get("foo");

		System.out.println(value);

	}

}
    java连接会出现 exceptions.JedisDataException 这样的异常;
    可以采用下面方法解决
                //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.

posted on 2018-05-12 17:09  Thieves  阅读(501)  评论(0编辑  收藏  举报

导航