日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

部署连接阿里云单体redis5.0

發布時間:2025/3/19 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 部署连接阿里云单体redis5.0 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、安裝

1,wget http://download.redis.io/releases/redis-5.0.0.tar.gz

2,tar –xvf redis-5.0.0.tar.gz

3,cd redis-5.0.0

4,make

5,make install

這就安裝完成了,這個流程基本是不會報錯的,我安裝過了就不截圖了。

執行redis-server -v出現如下結果表示安裝完成了

二、啟動

1,寫配置文件

//綁定主機地址bind 192.168.1.105//關閉保護模式 protected-mode no//設置后臺運行 daemonize yes//設置端口,最好不要用默認的6379,總有刁民想搞你的 port 6370//設置日志文件位置 logfile /var/log/redis.log//設置持久化文件存儲位置 dir /root/redis-5.0.0/data///設置密碼,也可以不設置,我被黑客搞過,所以還是設置一個 requirepass tianqi

然后執行redis-server redis_6370.conf啟動redis,ps -ef | grep redis查看,服務已經起來了

使用redis-cli -h 192.168.1.105 -p 6370即可連接到,-a是密碼,沒設置密碼可以不加這個

如果只是學習一下redis的安裝及命令到這就可以了,然后就各種set和get,下面是如何使用java程序連接到阿里云的單體redis

2,修改阿里云的安全組

3,寫程序了,使用springboot整合redis

pom依賴

<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId><version>2.1.4.RELEASE</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-pool2</artifactId><version>2.5.0</version></dependency><dependency><groupId>com.fasterxml</groupId><artifactId>jackson-xml-databind</artifactId><version>0.6.0</version></dependency></dependencies>

配置類

package redis.study.config;import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;import java.util.Arrays;@Configuration public class redisConfig extends CachingConfigurerSupport {@Beanpublic RedisTemplate<String,Object> getRedisTemplate(RedisConnectionFactory redisConnectionFactory){RedisTemplate<String,Object> redisTemplate = new RedisTemplate<String, Object>();redisTemplate.setConnectionFactory(redisConnectionFactory);GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer();redisTemplate.setDefaultSerializer(serializer);return redisTemplate;}@Bean@Overridepublic KeyGenerator keyGenerator(){return (target,method,objects) -> {StringBuilder sb = new StringBuilder();sb.append(target.getClass().getName()).append(method.getName()).append(Arrays.toString(objects));return sb.toString();};} }

?yml配置文件

server:port: 8001servlet:context-path: / spring:redis:host: 這里寫你的公網IPport: 6370password: tianqi #沒有密碼這里可以空著,pasword: database: 0jedis:pool:#連接池最大連接數默認是8max-active: 1000#連接池最大阻塞時間,-1表示無限制,默認-1max-wait: -1#連接池最大空閑數,默認8max-idle: 10#連接池最小空閑數,默認0min-idle: 10

測試類

package mytest.RedisTest;import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.test.context.junit4.SpringRunner; import redis.Application;@SpringBootTest(classes = Application.class) @RunWith(SpringRunner.class) public class Test1 {@AutowiredRedisTemplate redisTemplate;@Testpublic void test1(){Long aLong = redisTemplate.opsForList().leftPush("jinlong", "wang");System.out.println(redisTemplate.opsForList().rightPop("jinlong"));//System.out.println(aLong);} }

?結果

如果連接不了,timeout的話

1,看看公網IP寫錯了嗎,ping一下

2,配置文件中的內網IP是對的嗎,可能有幾個,可以試試到底是哪一個

3,保護模式關了嗎protected-mode no

4,防火墻關了嗎

這就是redis整個安裝部署到連接使用的過程了,有錯誤的話歡迎指出,有疑問可以下方提出,謝謝!?

總結

以上是生活随笔為你收集整理的部署连接阿里云单体redis5.0的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。