feat(server family): add connection set name command fixes #458 (#485)

server family: add connection set name command fixes #458

Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
adiholden 2022-11-13 17:54:37 +02:00 committed by GitHub
parent c9c33b476b
commit b395834060
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View file

@ -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

View file

@ -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;

View file

@ -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"