首页 > 其他分享 >Jedis操作string、Jedis操作hash

Jedis操作string、Jedis操作hash

时间:2022-08-24 14:12:32浏览次数:49  
标签:map hash string Jedis user jedis hset

 

 

 Jedis操作string

Jedls操作各种redis中的数据结构
  1)字符串类型string
    set
    get
2)哈希类型hash : map格式
    hset
    hget
3)列表类型list : linkedlist格式。支持重复元秦
    lpush / rpush
    lpop / rpop
4)集合类型set:不允许重复元秦
    sadd
5)有序集合类型sortedset :不允许重复元素,且元素有顺序
    zadd

案例:

     

    @Test
public void test2(){
Jedis jedis = new Jedis("localhost", 6379);
// 操作
jedis.set("username","zhangshan");
// 获取
String username = jedis.get("username");
System.out.println(username);
// 关闭连接
jedis.close();
}
}

 

 

 使用一个setex()方法存储可以指定过期时间 key value 存入redis 并且20秒后自动删除
jedis.setex("activecode",20,"hehe");

 

 

 

Jedis操作hash

2)哈希类型hash : map格式
    hset
    hget

案例:

  

    @Test
public void test3(){
Jedis jedis = new Jedis("localhost", 6379);
// 操作
// 储存hash
jedis.hset("user","name","list");
jedis.hset("user","age","13");
jedis.hset("user","aex ","nan");
String name = jedis.hget("user", "name");
System.out.println(name);
// 获取hash的所有map中的数据
Map<String, String> map = jedis.hgetAll("user");
for (String s : map.keySet()) {
String s1 = map.get(s);
System.out.println(s+":"+s1);
}


// 关闭连接
jedis.close();
}
}

 

标签:map,hash,string,Jedis,user,jedis,hset
From: https://www.cnblogs.com/ssr1/p/16619695.html

相关文章

  • Object类和String类
    API的概念应用程序编程接口:每一个技术,官方都会定义出许多的功能,开发人员可以直接拿来使用(拿来主义).API可以理解为Sun公司已经开发好的类和方法.API文档就是我们......
  • String类型与基础类型的转换(String.valueof())
    1.由基本数据型态转换成String String类别中已经提供了将基本数据型态转换成String的static 方法 也就是String.valueOf()这个参数多载的方法 有下列几种 S......
  • 第十三章 StringTable
    翻篇是很重要的能力,从悲伤中大方走出来,就是艺术家1.String的基本特性String字符串定义的两种方式Strings1=“baidu”;//字面量的定义方式Strings2=newStr......
  • [Oracle] LeetCode 696 Count Binary Substrings
    Givenabinarystrings,returnthenumberofnon-emptysubstringsthathavethesamenumberof0'sand1's,andallthe0'sandallthe1'sinthesesubstring......
  • redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to "x
    Java连接Redis所遇问题1.检查Linux是否关闭防火墙,或对外开放redis默认端口6379关闭防火墙。systemctlstopfirewalld对外开放端口。firewall-cmd--zone=publi......
  • 记C# 通过JObject 读取 json对象(Newtonsoft.Json.Linq.JObject.this[string].get 返回
    json对象"RequestHeaders":{ "Host":"tool.kkbmtj.com", "Referer":"https://m.kkbmtj.com/ys/shortindex?origin=kktj&xcx", }代码:HeaderLogheaderLog......
  • String ==和equals的区别
    public boolean equals(Object obj) {    return (this == obj);} Object中的equals()方法其实就是==,而String重写了equals()方法把它修改成比......
  • String 常用Api
    packagecom.itheima;publicclassstring{publicstaticvoidmain(String[]args){Strings1="qwertyuio";Strings3="QWErtyuio";......
  • Jedis案例
    案例:案例需求:提供index.html页面,页面中有一个省份下拉列表当页面加载完成后发送ajax请求,加载所有省份代码实现:ProvinceDaopackagecom.ailyt.dao;importco......
  • Lombok的使用 以及@EqualsAndHashCode
    @EqualsAndHashCode(of={"docId","travelDate"})其中,of选择指定的属性,构建生成equals方法与hashcode方法exclude排除制定属性lombok常用注释:1@Data//用于......