jedis入门

Jedis入门git

Jedis介绍github

1.JedisRedis官方首选的Java客户端开发包redis

2.https://github.com/xetorthio/jedisvim

查看redis端口: ps -ef | grep -i redisspa

进入redis目录:cd  /usr/local/redisrest

启动redis   ./bin/redis-server  ./bin/redis.confserver

 

启动客户端:./bin/redis-cli对象

退出客户端:exitip

打开防火墙:资源

vim  /etc/sysconfig/iptables

yy复制

p 粘贴

 

重启防火墙

service iptables restart

 

public static void main(String[] args) {

// 1.设置地址和端口

Jedis jedis = new Jedis("192.168.21.207", 6379);

// 2.保存数据

jedis.set("name", "哈哈");

// 3.获取数据

String string = jedis.get("name");

System.out.println(string);

// 4.释放资源

jedis.close();

}

第二种方式

// 得到链接池的配置对象

JedisPoolConfig config = new JedisPoolConfig();

// 设置最大链接数

config.setMaxTotal(30);

// 设置最大空闲链接数:

config.setMaxIdle(10);

 

// 得到链接池:

JedisPool jedisPool = new JedisPool(config, "192.168.21.207", 6379);

 

// 得到核心对象

Jedis jedis = null;

 

try {

jedis = jedisPool.getResource();

// 设置数据

jedis.set("name", "张三");

String string = jedis.get("name");

System.out.println(string);

} catch (Exception e) {

e.printStackTrace();

} finally {

// 释放资源

if (jedis != null) {

jedis.close();

}

if (jedisPool != null) {

jedisPool.close();

}

}

 

}

相关文章
相关标签/搜索