conanan's blog conanan's blog
首页
关于
  • 分类
  • 标签
  • 归档
  • Java
  • Java Web
  • 工具

    • Maven
  • MySQL
  • Redis
  • Git
  • Vim
  • Nginx
  • Docker
GitHub

Evan Xu

前端界的小学生
首页
关于
  • 分类
  • 标签
  • 归档
  • Java
  • Java Web
  • 工具

    • Maven
  • MySQL
  • Redis
  • Git
  • Vim
  • Nginx
  • Docker
GitHub
  • 基础

    • 简介
    • string
    • hash
    • list—顺序双向链表
    • set—大量数据
    • sorted_set—排序的大量数据
    • bitmap—位图
    • HyperLogLog
    • GEO—地理坐标
    • stream
    • 通用指令
    • Jedis
      • 简单使用步骤
      • 工具类封装
  • 高级

  • 集群

  • Redis面试
  • Redis
  • 基础
conanan
2021-06-21

Jedis

# Jedis

可以操作 Redis 的 Client 有许多,参考文档 。具体使用参考 Jedis 的 Github 仓库。

使用时需要添加依赖,具体看文档!

# 简单使用步骤

//1. 获取连接
Jedis jedis = new Jedis("localhost",6379);
//2. 操作
jedis.set("username","zhangsan");
//3. 关闭连接
jedis.close();
1
2
3
4
5
6

# 工具类封装

redis.properties

host=111.51.216.173
port=6379
maxTotal=30
maxIdle=10
1
2
3
4
public class JedisPoolUtils {

    private static final JedisPool jedisPool;

    private static final int maxTotal;
    private static final int maxIdle;
    private static final String host;
    private static final int port;

    static {
        ResourceBundle redisBundle = ResourceBundle.getBundle("redis");
        maxTotal = Integer.parseInt(redisBundle.getString("maxTotal"));
        maxIdle = Integer.parseInt(redisBundle.getString("maxIdle"));
        host = redisBundle.getString("host");
        port = Integer.parseInt(redisBundle.getString("port"));

        //获取数据,设置到JedisPoolConfig中
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(maxTotal);
        config.setMaxIdle(maxIdle);
        //初始化JedisPool
        jedisPool = new JedisPool(config, host, port);
    }

    public static Jedis getJedis() {
        return jedisPool.getResource();
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
编辑
上次更新: 2021/06/21, 15:45:42
通用指令
安装&配置

← 通用指令 安装&配置→

最近更新
01
线程生命周期
07-06
02
线程安全理论
06-24
03
并发简史
06-24
更多文章>
Theme by Vdoing | Copyright © 2019-2021 Evan Xu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×