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客户端连接的详细内容,更多请关注Work网其它相关文章!

09-18 05:21