PDA

View Full Version : basic redis functionality



slyfox
Aug 21st, 2011, 03:04 PM
trying to simply get redis working with my spring project. I am connected to a redis to go instance.

When trying a simple:
redisTemplate.opsForValue().set("key", "val");

it is not updating the key and im getting this debug:
14:52:35 DEBUG [RedisConnectionUtils] Opening RedisConnection
14:52:35 DEBUG [RedisConnectionUtils] Closing Redis Connection

seems like the simplest use case:

<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.Je disConnectionFactory"
p:host-name="angler.redistogo.com" p:port="9512"
p:password="************************"/>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
p:connection-factory-ref="jedisConnectionFactory"/>

Costin Leau
Aug 23rd, 2011, 03:03 AM
And what makes you think the key is not written? Have you checked the redis instance (opened on port 9512)?
Note that there's a sample (Twitter clone on top of Redis) that should help you get started with the setup, if you face any problems - just refer to the reference documentation.

slyfox
Aug 23rd, 2011, 12:27 PM
Costin,

Thanks for the reply. Well I am connected to my redis instance via redis-cli and was not getting anything when issuing get commands. I have since discovered the MONITOR command and noticed that when I thought I was setting a string 'key', the following was actually happening:
\xac\xed\x00\x05t\x00\x06key" "\xac\xed\x00\x05t\x00\x03wtf"

I know that I have seen this somewhere in the doc or a tutorial...

Thanks,
Bobby

Costin Leau
Aug 24th, 2011, 02:09 AM
It's the RedisTemplate with the default JDK serializer - switch to StringRedisTemplate or set a different serializer.