List of usage examples for org.springframework.data.redis.serializer StringRedisSerializer serialize
@Override public byte[] serialize(@Nullable String string)
From source file:grails.plugin.cache.redis.GrailsRedisCache.java
/** * Constructor./*from w ww. j a v a2 s. c o m*/ * * @param name cache name * @param prefix * @param cachePrefix */ public GrailsRedisCache(String name, byte[] prefix, RedisTemplate<? extends Object, ? extends Object> template, Long ttl) { Assert.hasText(name, "non-empty cache name is required"); this.name = name; this.template = template; this.prefix = prefix; this.ttl = ttl == null ? NEVER_EXPIRE : ttl.longValue(); StringRedisSerializer stringSerializer = new StringRedisSerializer(); // name of the set holding the keys setName = stringSerializer.serialize(name + "~keys"); cacheLockName = stringSerializer.serialize(name + "~lock"); }
From source file:com.cloudant.client.cache.redis.RedisCache.java
/** * Output contents of current database to a string. * * @return string containing output/*w w w . j a va2 s . co m*/ */ public String toString() { StringBuilder result = new StringBuilder("\nContents of Entire Cache\n\n"); StringRedisSerializer srs = new StringRedisSerializer(); // If we know that keys are strings, we don't have to use // StringRedisSerializer Set<byte[]> keys = cache.keys(srs.serialize("*")); for (byte[] key : keys) { String keyString = Serializer.deserializeFromByteArray(key); result.append("Key: " + keyString + "\n"); byte[] rawValue = cache.get(key); if (rawValue == null) { result.append("No value found in cache for keyString " + keyString + "\n\n"); continue; } CacheEntry<V> cacheEntry = Serializer.deserializeFromByteArray(rawValue); if (cacheEntry == null) { result.append("CacheEntry is null for keyString " + keyString + "\n\n"); continue; } result.append(cacheEntry.toString() + "\n\n"); } result.append("Cache size is: " + size() + "\n"); return result.toString(); }
From source file:org.springframework.data.redis.cache.RedisCache.java
/** * Constructs a new <code>RedisCache</code> instance. * /*from w ww . ja va2s .co m*/ * @param name cache name * @param prefix * @param template * @param expiration */ RedisCache(String name, byte[] prefix, RedisTemplate<? extends Object, ? extends Object> template, long expiration) { Assert.hasText(name, "non-empty cache name is required"); this.name = name; this.template = template; this.prefix = prefix; this.expiration = expiration; StringRedisSerializer stringSerializer = new StringRedisSerializer(); // name of the set holding the keys this.setName = ArrayUtils.addAll(prefix, stringSerializer.serialize(name + "~keys")); this.cacheLockName = ArrayUtils.addAll(prefix, stringSerializer.serialize(name + "~lock")); }