jedis.get(byte[] key) jedis.set(byte[] key, byte[] value)
public byte[] serialize(Object obj); public Object unSerialize(byte[] bytes);
jedis.get(String key); jedis.set(String key, String value);
jedis.hgetAll(String key); jedis.hmset(String key, Map<String,String> values);
/** *Encapsulates the specified object data into a map * * @param bean *Object Data * @return */ @SuppressWarnings("all") public static Map<String, String> warp(AbstractRedisBean bean) { Map<String, String> propertyMap = new HashMap<String, String>(); try { PropertyDescriptor[] ps = Introspector.getBeanInfo(bean.getClass()) .getPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : ps) { String propertyName = propertyDescriptor.getName(); if (propertyName != null && !propertyName.equals(CLASS)) { Method getter = propertyDescriptor.getReadMethod(); if (getter != null) { RedisBeanField mannota = getter .getAnnotation(RedisBeanField.class); if (mannota != null && mannota.serialize() == false) { continue; } propertyMap.put(propertyName, String.valueOf(getter.invoke(bean, null))); } } } } catch (Exception e) { logger.error(e); } return propertyMap; }
/** *Convert the map to the specified object * * @param beanMap *Map data * @param clazz *Specified class object * @return */ public static <T extends AbstractRedisBean> T reverse( Map<String, String> beanMap, Class<T> clazz) { T bean = getRedisBean(clazz); try { PropertyDescriptor[] ps = Introspector.getBeanInfo(clazz) .getPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : ps) { String propertyName = propertyDescriptor.getName(); if (propertyName != null && !propertyName.equals(CLASS)) { Method setter = propertyDescriptor.getWriteMethod(); String value = beanMap.get(propertyName); String type = propertyDescriptor.getPropertyType() .getName(); if (setter != null && value != null && ! value.equalsIgnoreCase("null")) { Object obj = value(value, type); if (obj != null) { setter.invoke(bean, obj); } } } } } catch (Exception e) { logger.error(e); e.printStackTrace(); } bean.clearChangeMap(); return bean; } /** *Converts a String type numeric value to the specified type * * @param value *Value * @param type *Specified type * @return */ private static Object value(String value, String type) { if (type.equals("boolean")) { return Boolean.valueOf(value); } else if (type.equals("byte")) { return Byte.valueOf(value); } else if (type.equals("short")) { return Short.valueOf(value); } else if (type.equals("float")) { return Float.valueOf(value); } else if (type.equals("int")) { return Integer.valueOf(value); } else if (type.equals("java.lang.String")) { return value; } else if (type.equals("long")) { return Long.valueOf(value); } return null; }