skip to Main Content

I have some Java code implemented in Spring that persists a Java Bean like…

@Repository
public class SomeDamnRedisRepository {
  private static final String KEY = "someDamn";
  private static final Logger LOG = LoggerFactory.getLogger(SomeDamnRedisRepository.class);
  ...
  private RedisTemplate<String, Object> redisTemplate;
  private HashOperations hashOps;

  @Autowired
  public SomeDamnRedisRepository(RedisTemplate redisTemplate) {
    this.redisTemplate = redisTemplate;
  }

  @PostConstruct
  public void init() {
    hashOps = redisTemplate.opsForHash();
  }

  public void save(SomeDamn someDamn) {
    try {
      hashOps.put(KEY, someDamn.getVersion(), someDamn);
    } catch (Exception e) {
      LOG.warn(String.format("ignoring exception on save(%s)", someDamn != null ? someDamn.getVersion() : "null"), e);
    }
  }

  public SomeDamn get(String version) {
    try {
      return (SomeDamn) hashOps.get(KEY, version);
    } catch (Exception e) {
      LOG.warn(String.format("ignoring exception on get(%s)", version), e);
    }
    return null;

  }
}

The SomeDamn Java Bean is simple enough (Lombok is maintain Java bean).

@Data
@AllArgsConstructor
public class SomeDamn implements Serializable {
  private String id;           // This guy like "1"
  private String displayValue; // This guy like "One"
  private String version;      // This guy like "urn:com.example.object-ref:version:2f7dcb42-a27d-4c9f-88d4-8721b3642792"
}

In the redis-cli I get to see that something mutilated my "key desire" (I expected just "someDamn).

$ redis-cli
127.0.0.1:6379> keys *
1) "xacxedx00x05tx00x0bsomeDamn"

What is the redis-cli invocation to get it to return the value stored on "someDamn" key for the URN "urn:com.example.object-ref:version:2f7dcb42-a27d-4c9f-88d4-8721b3642792". Like if I stored new SomeDamn("1", "one", "urn:com.example.object-ref:version:2f7dcb42-a27d-4c9f-88d4-8721b3642792");?

Up-the-middle GET on what the cli reports on the key doesn’t do anything

127.0.0.1:6379> GET xacxedx00x05tx00x0bsomeDamn
(nil)
127.0.0.1:6379> GET someDamn
(nil)

Is there a "dump all the values at KEY ‘someDamn’ or something I can use to reason this out?

Redis is like a roach motel for me right now; bugs go in. Nothing comes out.

How do I find the value "urn:com.example.object-ref:version:2f7dcb42-a27d-4c9f-88d4-8721b3642792" on the redis key "someDamn" through the redis-cli for something put there by up-the-middle Spring Redis?

2

Answers


  1. To retrieve a Hash by key use
    HGETALL <mykey>, retrieves the whole hash, if you just want a certain name-value pair from the hash, then do HGET <mykey> <myname> and you get a single value back.

    Login or Signup to reply.
  2. You are using HASHSET in Redis, so you have to use

    HGETALL key

    HGET key field

    As i can see from code – your key is someDamn and field is urn:com.example.object-ref:version:2f7dcb42-a27d-4c9f-88d4-8721b3642792

    Official documentation also contains some examples if you will need them
    https://redis.io/commands/hget/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search