Redis 使用笔记之 hash
来源:互联网 发布:网络诈骗去哪里举报 编辑:程序博客网 时间:2024/05/29 19:55
1、RedisClient 类
package com.redis;import redis.clients.jedis.Jedis;/** * Description: Created by Bluesky on 2017/7/18. */public class RedisClient { private static Jedis jedis; private RedisClient() { } static { // 连接本地的 Redis 服务 jedis = new Jedis( "localhost" ); jedis.auth( "*******" ); } public static Jedis getRedisClient() { return jedis; }}
2、User 类
package com.redis;import java.io.Serializable;/** * Description: Created by Bluesky on 2017/7/18. */public class User implements Serializable { private static final long serialVersionUID = 5486841748799373759L; private Long id; private String name; private Integer age; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } @Override public String toString() { return "User{" + "id=" + id + ", name='" + name + '\'' + ", age=" + age + '}'; }}
3、使用 hash 存取对象
public static void testMap() { Jedis jedis = RedisClient.getRedisClient(); User user = new User(); user.setId(3l); user.setName("Tom3"); user.setAge(28); String key = "u:3"; try { jedis.hmset(key, BeanUtils.describe(user)); User user1 = new User(); BeanUtils.populate(user1, jedis.hgetAll(key)); System.out.println(user1.toString()); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } }
阅读全文
0 0
- Redis 使用笔记之 hash
- redis数据类型之hash
- redis数据类型之hash
- redis之hash
- Redis之Hash
- redis之hash类型
- Redis之Hash数据结构
- redis之hash命令
- redis之hash(5)
- Redis数据类型之Hash
- Redis笔记6:数据类型之哈希(Hash)
- 【Redis笔记】4.Hash(H)
- Redis数据类型之HASH类型
- 04. redis 数据类型之Hash
- jedis调用redis之Hash
- php操作redis之hash
- Redis 数据类型之Hash类型
- Redis之Hash类型操作
- 空域高斯滤波与频域高斯滤波
- iOS MDM相关资料
- Android 常用开源框架汇总
- Google Inception Net 特点总结
- EJSP技术理解
- Redis 使用笔记之 hash
- 字符串和JSON对象的互相转化
- java--抽象类/抽象方法
- Scapy使用文档中文版
- svn使用教程
- 全面解析HTTP/2:历史、特性、调试、性能
- Redis支持的两种持久化备份方式(RDB & AOF)
- android获取屏幕的分辨率方法
- <安彦>Java中JVM的原理一