@Override public synchronized Object clone() { return new RedisProperties(defaults, hashOps); }
@Override public Object putIfAbsent(Object key, Object value) { return (hashOps.putIfAbsent((String) key, (String) value) ? null : get(key)); }
@Override public synchronized boolean contains(Object value) { return containsValue(value); }
@Test @RedisAvailable public void testProperties() { RedisProperties redisProperties = new RedisProperties("pepboys", this.redisTemplate); assertEquals(0, redisProperties.size()); Properties pepboys = new Properties(); pepboys.put("1", "Manny"); pepboys.put("2", "Moe"); pepboys.put("3", "Jack"); Message<Properties> message = MessageBuilder.withPayload(pepboys).build(); this.propertyChannel.send(message); assertEquals("Manny", redisProperties.get("1")); assertEquals("Moe", redisProperties.get("2")); assertEquals("Jack", redisProperties.get("3")); }
private void writeToProperties(final RedisProperties properties, Message<?> message) { final Object payload = message.getPayload(); if (this.extractPayloadElements && payload instanceof Properties) { processInPipeline(() -> properties.putAll((Properties) payload)); } else { Assert.isInstanceOf(String.class, payload, "For property, payload must be a String."); Object key = this.determineMapKey(message, true); properties.put(key, payload); } }
@Override public synchronized boolean equals(Object o) { if (o == this) return true; if (o instanceof RedisProperties) { return o.hashCode() == hashCode(); } return false; }
@Override public synchronized Enumeration<Object> keys() { Set<Object> keys = keySet(); return Collections.enumeration(keys); }
/** * Persists the provided key and value to Redis. * * @param key Must not be null * @param value Must not be null */ @Override public void put(String key, String value) { Assert.notNull(key, "'key' must not be null."); Assert.notNull(value, "'value' must not be null."); this.properties.put(key, value); }
@Override public String putIfAbsent(String key, String value) { Assert.notNull(key, "'key' must not be null."); Assert.notNull(value, "'value' must not be null."); Object oldValue = this.properties.putIfAbsent(key, value); if (oldValue != null) { Assert.isInstanceOf(String.class, oldValue, "Invalid type in the store"); } return (String) oldValue; }
@Override public String remove(String key) { Assert.notNull(key, "'key' must not be null."); Object removed = this.properties.remove(key); if (removed != null) { Assert.isInstanceOf(String.class, removed, "The removed value was an invalid type"); } return (String) removed; }
@Override public boolean replace(String key, String oldValue, String newValue) { Assert.notNull(key, "'key' must not be null."); Assert.notNull(oldValue, "'oldValue' must not be null."); Assert.notNull(newValue, "'newValue' must not be null."); return this.properties.replace(key, oldValue, newValue); }
@Test @RedisAvailable public void testPropertiesSimple() { RedisProperties redisProperties = new RedisProperties("foo", this.redisTemplate); assertEquals(0, redisProperties.size()); Message<String> message = MessageBuilder.withPayload("bar") .setHeader(RedisHeaders.KEY, "foo") .setHeader("baz", "qux") .build(); this.simplePropertyChannel.send(message); assertEquals("bar", redisProperties.get("qux")); }
private void writeToProperties(final RedisProperties properties, Message<?> message) { final Object payload = message.getPayload(); if (this.extractPayloadElements && payload instanceof Properties) { processInPipeline(() -> properties.putAll((Properties) payload)); } else { Assert.isInstanceOf(String.class, payload, "For property, payload must be a String."); Object key = this.determineMapKey(message, true); properties.put(key, payload); } }
@Override public synchronized boolean equals(Object o) { if (o == this) return true; if (o instanceof RedisProperties) { return o.hashCode() == hashCode(); } return false; }
@Override public synchronized Enumeration<Object> keys() { Set<Object> keys = keySet(); return Collections.enumeration(keys); }
/** * Persists the provided key and value to Redis. * * @param key Must not be null * @param value Must not be null */ @Override public void put(String key, String value) { Assert.notNull(key, "'key' must not be null."); Assert.notNull(value, "'value' must not be null."); this.properties.put(key, value); }
@Override public String putIfAbsent(String key, String value) { Assert.notNull(key, "'key' must not be null."); Assert.notNull(value, "'value' must not be null."); Object oldValue = this.properties.putIfAbsent(key, value); if (oldValue != null) { Assert.isInstanceOf(String.class, oldValue, "Invalid type in the store"); } return (String) oldValue; }
@Override public String remove(String key) { Assert.notNull(key, "'key' must not be null."); Object removed = this.properties.remove(key); if (removed != null) { Assert.isInstanceOf(String.class, removed, "The removed value was an invalid type"); } return (String) removed; }
@Override public boolean replace(String key, String oldValue, String newValue) { Assert.notNull(key, "'key' must not be null."); Assert.notNull(oldValue, "'oldValue' must not be null."); Assert.notNull(newValue, "'newValue' must not be null."); return this.properties.replace(key, oldValue, newValue); }
@SuppressWarnings("unchecked") private RedisStore createStore(DataType dt) { switch (dt) { case LIST: return new DefaultRedisList(key, template); case SET: return new DefaultRedisSet(key, template); case ZSET: return new DefaultRedisZSet(key, template); case HASH: if (CollectionType.PROPERTIES.equals(type)) { return new RedisProperties(key, template); } return new DefaultRedisMap(key, template); } return null; }