1 Java 连接redis
来源:互联网 发布:java分母最小化 编辑:程序博客网 时间:2024/06/03 01:41
在安装好redis后,从java这里连接redis。
<dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>2.8.2</version></dependency>
==
public class RedisMain {public static void main(String[] args) {Jedis jedis = new Jedis("192.168.40.129", 6379);//jedis.auth("123456"); jedis.set("test", "abc");String str = jedis.get("test");System.out.println(str);}}
报错
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.
这里,可以修改配置文件和添加密码就可以做到修改了。
解决①设置密码,在redis-cli执行 config set requirepass 123456,这个时候123456就是密码了,然后java代码需要先执行 jedis.auth("123456") 才行。
解决②,把redis主目录的redis.conf复制到src中,然后修改,把protected-mode改为 no 把bind 127.0.0.1注释掉,这个时候,代码不需要auth,也可以。
==
注意,在设置了密码后如果再需要用 ./redis-cli 使用redis,可能需要 >>auth 123456才行。
>>set name wang >>get name
- 1 Java 连接redis
- java连接redis
- Redis Java连接操作
- Redis Java连接使用
- Java连接Redis
- Java连接Redis
- java连接Redis
- java连接redis
- java接口连接redis
- Redis - Java连接
- Java连接Redis
- java连接redis原来如此。。。。
- java连接redis
- java 连接 redis
- JAVA连接Redis教程
- java连接Redis
- JAVA redis连接池
- java连接redis
- MD5的相关知识
- Bug:finish()按back键,原页面还存在的问题
- Java 初学者建议
- 链式前向星模板
- Qt修改工程名称的方法
- 1 Java 连接redis
- Java内部类
- 关于ActionBar的简单应用
- gym 100484
- AngularJS系列之表达式
- 为什么使用Redis
- Online Object Tracking Benchmark(OOTB)目标跟踪系统评估方式
- 【a703】求逆序对(树状数组的解法)
- Android应用界面主题Theme使用方法