zoukankan      html  css  js  c++  java
  • java连接redis使用jedis带密码

    一.引入jedis的Maven配置文件

    <!-- redis连接客户端jedis -->
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
                <version>2.9.0</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>

    二.java连接redis代码

    package yuelj.utils;
    
    import java.util.LinkedList;
    import java.util.List;
    import redis.clients.jedis.JedisPoolConfig;
    import redis.clients.jedis.JedisShardInfo;
    import redis.clients.jedis.ShardedJedis;
    import redis.clients.jedis.ShardedJedisPool;
    public class RedisUtils { private static ShardedJedisPool pool; static { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(100); config.setMaxIdle(50); config.setMaxWaitMillis(3000); config.setTestOnBorrow(true); config.setTestOnReturn(true); // 集群 JedisShardInfo jedisShardInfo1 = new JedisShardInfo("120.26.1.1", 6379); jedisShardInfo1.setPassword("123456888888"); List<JedisShardInfo> list = new LinkedList<JedisShardInfo>(); list.add(jedisShardInfo1);
         pool
    = new ShardedJedisPool(config, list); } public static void main(String[] args) { ShardedJedis jedis = pool.getResource(); String keys = "myname"; String vaule = jedis.set(keys, "lxr"); System.out.println(vaule); } }
  • 相关阅读:
    python脚本
    python引用,浅拷贝,深拷贝
    postgresql MVCC详解
    sql排它锁
    sqlalchemy使用
    ASP.Net MVC开发基础学习笔记(7):数据查询页面
    js timestamp与datetime之间的相互转换
    聊聊iOS中TCP / UDP 协议
    IOS -执行时 (消息传递 )
    Java对象的序列化和反序列化
  • 原文地址:https://www.cnblogs.com/lixiaoran/p/6605228.html
Copyright © 2011-2022 走看看