创建一个springcloud项目(略)

添加依赖

<dependency>
  <groupId>redis.clients</groupId>
  <artifactId>jedis</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

 

设置配置文件,

这里的集群用的是我之前已经配置好了的集群,可以参照访问另一篇文章,

Redis cluster集群模式搭建

spring:
  redis:
    cluster:
      nodes:
        - 10.211.55.14:7001
        - 10.211.55.14:7002
        - 10.211.55.14:7003
        - 10.211.55.16:7001
        - 10.211.55.16:7002
        - 10.211.55.16:7003
        - 10.211.55.17:7001
        - 10.211.55.17:7002
        - 10.211.55.17:7003
    #超时时间
    command-timeout: 3000
    # 重试次数
    max-attempts: 3

 

使用StringRedisTemplate操作redis

@Autowired
private StringRedisTemplate stringRedisTemplate;

@ResponseBody
@RequestMapping("/setKey")
public BaseResult hello(String key, String value) {
    stringRedisTemplate.opsForValue().set(key, value);
    return BaseResult.success();
}

@ResponseBody
@RequestMapping("/getkey")
public BaseResult hello(String key) {
    String value = stringRedisTemplate.opsForValue().get(key);
    System.out.println(value);
    return BaseResult.success();
}

 

一个写入,一个读取

测试下效果,启动项目,调用接口

http://localhost:8989/table/user/setKey?key=userkey&value=keyvalue

插入成功,登录任意一个节点,查看redis的key内容

van@van ~$ redis-cli -h 10.211.55.14 -p 7001 -c

10.211.55.14:7001> keys *

1) "keydemo"

2) "userkey"

3) "wang"

10.211.55.14:7001> get userkey

-> Redirected to slot [5079] located at 10.211.55.16:7002

"keyvalue"

10.211.55.16:7002> 

 

通过接口调用查询也okay,这里不做截图了。

这就是最简单的连接使用redis cluster方法

206 对 “springcloud项目中使用redis cluster集群”的想法;

  1. Size yayılan takipçi hizmetleriyle basit bir
    şekilde instagram profilinizi büyütebilirsiniz.

    Şirketin hizmetlerinden faydalanarak dilediğiniz kadar takipçiye ulaşabilirsiniz, instgaram takipçi satın AL işlemi oldukça
    basit ve kısa süreçte size teslim edilmektedir.
    Yapmanız gereken tek şey Takip2018 e sadece giriş yaparak dilediğiniz
    kadar takipçi isteği yapabilirsiniz.
    Size uygun paketi seçmeniz halinde dilediğiniz alabilir ve sadece izlersiniz.
    Benzersiz hizmet vererek size daha çeşitli paketler önerebiliyor.

  2. Pingback: ates ve su 1
  3. Pingback: sftony
  4. Hello would you mind letting me know which webhost you’re utilizing?
    I’ve loaded your blog in 3 different web browsers and I must
    say this blog loads a lot faster then most. Can you recommend a good web hosting provider at a fair price?
    Many thanks, I appreciate it!

  5. Бизнесмен и меценат Максим Евгеньевич Каганский
    родился в Москве 19 ноября
    1980 года в многодетной семье сотрудника МВД.
    В 1998 году поступил в Московский
    Юридический Институт МВД России (сейчас – Академия МВД
    России), специальность – юрист-правовед.

    максим каганский фото
    максим каганский фото http://fashionmelis.com/__media__/js/netsoltrademark.php?d=mignews.com%2Fnews%2Feconomics%2Fkrz-vzyali-120-millionov.html

  6. Бизнесмен и меценат Максим Евгеньевич Каганский родился в Москве
    19 ноября 1980 года в многодетной семье сотрудника
    МВД. В 1998 году поступил в
    Московский Юридический Институт МВД России (сейчас –
    Академия МВД России), специальность – юрист-правовед.

    каганский максим евгеньевич сейчас
    каганский максим евгеньевич
    сейчас http://203.105.227.131

  7. Бизнесмен и меценат Максим Евгеньевич Каганский родился в Москве 19 ноября 1980 года в многодетной семье сотрудника МВД.
    В 1998 году поступил в Московский Юридический Институт МВД России (сейчас – Академия МВД России), специальность – юрист-правовед.

    каганский максим евгеньевич сейчас
    каганский максим евгеньевич сейчас http://kuhni-stock.ru/bitrix/redirect.php?event1=&event2=&event3=&goto=https://www.calend.ru/afisha/1356/

  8. High quality supplements help you build the body
    of your dreams. If you wish nothing but the best for
    your silhouette and health, be sure to get steroids from the Balkan pharmaceuticals.
    Balkan Pharmaceuticals is one of the largest manufacturers of
    quality goods. In our store, there are only original items obtained directly from the
    industry. Popular Supplements: Steroids, Fat-Burners,
    Post-Cycle Therapy (PCT), Combined Course and others.

    Florence
    Florence https://1bpshop.com/SP-Metan

  9. I have been surfing online more than 4 hours today, yet I never found any interesting article like yours.
    It is pretty worth enough for me. Personally, if all site owners
    and bloggers made good content as you did, the internet will be much more useful than ever before.

  10. It is the best time to make some plans for
    the future and it’s time to be happy. I’ve read this post and if I could I want to suggest you few interesting things or advice.
    Maybe you could write next articles referring
    to this article. I desire to read more things
    about it!

  11. Good website! I truly love how it is simple on my eyes and the data are well written. I’m wondering how I might be notified when a new post has been made. I’ve subscribed to your feed which must do the trick! Have a nice day!

  12. I have been browsing online more than 3 hours today, yet I never found any interesting article like yours.
    It is pretty worth enough for me. In my opinion,
    if all site owners and bloggers made good content as you did, the web will be a
    lot more useful than ever before.

  13. Hi there, There’s no doubt that your website may be having internet browser compatibility
    problems. Whenever I look at your website in Safari, it looks fine however, when opening in IE,
    it’s got some overlapping issues. I just wanted to provide you with a quick heads up!
    Other than that, wonderful website!

发表评论