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); } }
  • 相关阅读:
    Nginx进程信号管理
    Nginx配置缓存服务器
    访问Nginx显示目录
    kubeadm快速安装k8s
    《构建之法》读书笔记(一)
    Android Studio连接SQLite数据库与SQLite Studio实时同步的实现
    关于sqlite数据库与sqlite studio
    AS之去掉顶部标题栏
    今日学习
    AS之AlertDialog使用
  • 原文地址:https://www.cnblogs.com/lixiaoran/p/6605228.html
Copyright © 2011-2022 走看看