redis配置文件和java客户端连接

2021/7/4 2:23:38

本文主要是介绍redis配置文件和java客户端连接,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

daemonize 

bind ip白名单,  0.0.0.0.0放行所有

port 6379

databases 0-15 16个

save 持久化频次

ddbfilename 持久化文件名

requirepass 密码    requirepass 123456

maxclient 同时连接最大数

maxmemory 最大内存


 

./redis-cli -h 193.168.0.1 -p 6379 -a 123456  // -h -p 能省略

 

set username zs

get username 

select 2 //切库

set username zs  //不同库可以存相同的key

set immoc:users:1 zs

get immoc:users:1      //层级存储

keys *             //所有key

info

flushall    //清空所有

 

 

package com.itheima.springbootradis.tools;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisConnectionPool {

    static Jedis j;
    static JedisPool pool;

    static {
        j = new Jedis("127.0.0.1", 6379);
        j.auth("123456");
        String pong = j.ping();
        System.out.println("pong = " + pong);

        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(5);
        jedisPoolConfig.setMaxIdle(6);

        pool = new JedisPool(jedisPoolConfig, "192.168.10.101", 6379, 100, "123456");
    }

    public static Jedis getJedis() {
        return pool.getResource();
    }

}
    @Test
    public void testJedis() {
        Jedis j = JedisConnectionPool.getJedis();
        j.select(2);
        String result = j.set("user", "zs");
        System.out.println("result = " + result);
        String result2 = j.get("user");
        System.out.println("result2 = " + result2);
        j.set("level1:level2:1", "zs");
        String level = j.get("levle1:level2:1");
        System.out.println("level = " + level);

        Set<String> set = j.keys("*");
        System.out.println("set = " + set);

    }

 



这篇关于redis配置文件和java客户端连接的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程