redis如何实现负载均衡


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

public static void main(String[] args) {

        List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();

        shards.add(new JedisShardInfo("127.0.0.1", 6379));

        shards.add(new JedisShardInfo("127.0.0.1", 6380));

 

        ShardedJedisPool sjp = new ShardedJedisPool(new JedisPoolConfig(), shards);

        ShardedJedis shardClient = sjp.getResource();

        try {

            shardClient.set("A", "123");

            shardClient.set("B", "234");

            shardClient.set("C", "345");

 

            try {

                System.out.println(shardClient.get("A"));

            } catch (Exception e) {

                e.printStackTrace();

            }

 

            try {

                System.out.println(shardClient.get("B"));

            } catch (Exception e) {

                e.printStackTrace();

            }

 

            try {

                System.out.println(shardClient.get("C"));

            } catch (Exception e) {

                e.printStackTrace();

            }

        } catch (Exception e) {

            e.printStackTrace();

        } finally {

            sjp.returnResource(shardClient);

        }

    }

 

}

以上就是redis如何实现负载均衡的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

redis如何实现负载均衡

更多相关阅读请进入《redis负载均衡》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...