Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Feature Request: way for set on hash to return new state of keys in redis #190

@dlennardshipt

Description

@dlennardshipt

In postgresql, you can easily return the current state of a record after insert or update by using RETURNING *. So if you had a set of records that you updated, you can update a single field and then return the current state of the entire record.

ex:

CREATE TABLE users (firstname text, lastname text, id serial primary key);
INSERT INTO users (firstname, lastname) VALUES ('Joe', 'Cool') RETURNING *;
UPDATE sandbox.test_table SET firstname = 'bob' WHERE id = 1 RETURNING *;

So say hypothetically we have a set of keys of the following format in redis

redis> HMSET myhash field1 "Hello" field2 "World" field3 "Test"
"OK"

I've run into a situation where, after performing a transaction of many HSET/HMSET operations, I'll have to run a separate pipeline/transaction of HGETALL operations in order to return the state of records after the HSET/HMSET operation (requirement for front end). I'll be doing this on hundreds, possibly a thousand records per request.

It would be nice if we could replicate the functionality of RETURNING * via redis for hashes. It could be some sort of command, for the sake of example I'll call it HMSETRET and HSETRET (RET for RETURN), which would be the equivalent of running HSET/HGET or HMSET/HGETALL ran sequentially.

ex:

redis> HMSETRET myhash field1 "hello" field2 "world"
1) "field1"
2) "hello"
3) "field2"
4) "world"
3) "field3"
4) "Test"

redis> HSETRET myhash field3 "test"
1) "field1"
2) "hello"
3) "field2"
4) "world"
5) "field3"
6) "test"

This would allow for one single transaction or pipeline to run which would update information and return records back in one fell swoop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions