博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Redis学习记录
阅读量:6851 次
发布时间:2019-06-26

本文共 1812 字,大约阅读时间需要 6 分钟。

hot3.png

安装,基本命令  参照

一个概念:  非切片额客户端,切片额客户端

类似客户端负载均衡,切片是带有负载均衡,连接池都一样,切片可以把多个连接池放一起,

非切片:

/**     * 初始化非切片池     */    private void initialPool()    {        // 池基本配置        JedisPoolConfig config = new JedisPoolConfig();        //控制一个pool最多有多少个状态为idle(空闲的)的jedis实例,默认值是8。        config.setMaxIdle(5);        // 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException;        config.setMaxWaitMillis(10000);        // 可用连接实例的最大数目,默认值为8;        // 如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。        config.setMaxTotal(10);        //在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的;        config.setTestOnBorrow(false);        jedisPool = new JedisPool(config,"127.0.0.1",6379);    }

切片:

/**     * 初始化切片池     */    private void initialShardedPool()    {        // 池基本配置        JedisPoolConfig config = new JedisPoolConfig();        config.setMaxIdle(5);        config.setTestOnBorrow(false);        // slave链接        List
shards = new ArrayList
(); shards.add(new JedisShardInfo("127.0.0.1", 6379, "master")); // 构造池 shardedJedisPool = new ShardedJedisPool(config, shards); }

 

pom.xml

redis.clients
jedis
2.9.0
org.springframework.data
spring-data-redis
1.6.2.RELEASE

下面spring-data-redis是spring集成redis的jar。采用redisTemplate操作redis,

spring-data-redis版本不对会报redisTemplate

转载于:https://my.oschina.net/u/2271162/blog/755061

你可能感兴趣的文章
微信开发学习(二)
查看>>
JS中的“!!”
查看>>
python之MySQL操作
查看>>
radioButton添加试题选项webview(二)
查看>>
Centos7 linux 安装 redis 遇到的几个问题
查看>>
Kohana的请求流
查看>>
Oracle 12c Sharding测试过程中的问题解决
查看>>
Oracle Index 索引监控
查看>>
Elasticsearch2.x 全文检索之——Match转换Bool Query
查看>>
NET联调
查看>>
noi.ac day6t1 queen
查看>>
作业四 任务分解(WBS)
查看>>
eclipse 创建maven 项目 动态web工程完整示例
查看>>
laravel中的命名公约规范及relation N+1问题
查看>>
Convolution of measures and one application
查看>>
逆序对 线段树&树状数组 (重制版)
查看>>
从此错位(相减)无计算
查看>>
RESTful API 设计最佳实践
查看>>
想要成为一个人,先按那个人的要求去做,你自然就成了那个人(转)
查看>>
Codeforces Round #425 (Div. 2) - A
查看>>