RedisKeyPrefixSerializer implements RedisKeySerializer { public byte[] serialize(RedisKey redisKey) { byte[] key = redisKey.toByteArray(); if (prefixBytes.length == 0) { return key; } byte[] keyWithPrefix = new byte[prefixBytes.length + key.length]; System.arraycopy(prefixBytes, 0, keyWithPrefix, 0, prefixBytes.length); System.arraycopy(key, 0, keyWithPrefix, prefixBytes.length, key.length); return keyWithPrefix; } RedisKeyPrefixSerializer(String prefix); byte[] serialize(RedisKey redisKey);  }
@Test public void shouldPrependKey() { RedisKeyPrefixSerializer serializer = new RedisKeyPrefixSerializer("namespace:"); String keyWithPrefix = new String(serializer.serialize(key)); assertEquals(String.format("namespace:%s", new String(key.toByteArray())), keyWithPrefix); }
@Test public void shouldNotPrependKeyIfEmptyString() { RedisKeyPrefixSerializer serializer = new RedisKeyPrefixSerializer(""); assertArrayEquals(key.toByteArray(), serializer.serialize(key)); }