Skip to content

Commit

Permalink
feat(server family): add connection set name command fixes #458 (#485)
Browse files Browse the repository at this point in the history
server family: add connection set name command fixes #458

Signed-off-by: adi_holden <[email protected]>
  • Loading branch information
adiholden authored Nov 13, 2022
1 parent c9c33b4 commit b395834
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/api_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ with respect to Memcached and Redis APIs.
- [X] WATCH
- [X] UNWATCH
- [X] DISCARD
- [X] CLIENT LIST/SETNAME
- [X] CLIENT LIST/SETNAME/GETNAME
- [ ] CLIENT KILL/UNPAUSE/PAUSE/GETNAME/REPLY/TRACKINGINFO
- [X] COMMAND
- [X] COMMAND COUNT
Expand Down
9 changes: 9 additions & 0 deletions src/server/server_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,15 @@ void ServerFamily::Client(CmdArgList args, ConnectionContext* cntx) {
return (*cntx)->SendOk();
}

if (sub_cmd == "GETNAME") {
const char* name = cntx->owner()->GetName();
if (*name != 0) {
return (*cntx)->SendBulkString(name);
} else {
return (*cntx)->SendNull();
}
}

if (sub_cmd == "LIST") {
vector<string> client_info;
fibers::mutex mu;
Expand Down
8 changes: 8 additions & 0 deletions tests/dragonfly/server_family_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,11 @@ def test_multi_eval(client):
except Exception as e:
msg = str(e)
assert "Dragonfly does not allow execution of" in msg


def test_connection_name(client):
name = client.execute_command("CLIENT GETNAME")
assert not name
client.execute_command("CLIENT SETNAME test_conn_name")
name = client.execute_command("CLIENT GETNAME")
assert name == "test_conn_name"

0 comments on commit b395834

Please sign in to comment.