Redis How to get current database name - redis

Is there any command in Redis to get the database name that I am using right now?
I know select is to switch the database. I am looking for "get database name" kind of a command.

First of all, there's NO name for Redis database. Instead, it has an index.
You can use the CLIENT SETNAME and CLIENT LIST commands to get the database index dynamically:
call CLIENT SETNAME a-unique-name to set a unique name for the current connection.
call CLIENT LIST to get info of all clients that connecting to Redis.
find the connection info with the unique name that we set in step 1.
parse the client info the get the database index.
You can get the format of client info from the doc.
NOTE: If anyone has a simpler solution, please let me know :)
UPDATE: Since Redis 6.2.0, you can use CLIENT INFO to get the information of current connection. So that you don't need to run step 1 - 3 mentioned above.

Since Redis version 6.2.0 you can use the CLIENT INFO command, the response of which contains both the name and the db number of the current client connection.

Related

How can I reliably track the status of a newly provisioned BareMetal server using the REST API

In SL support ticket opened last year, I was looking for assistance in working around a SoftLayer issue where when my team orders Baremetal servers through some custom scripting, sometimes, the server id associated with the new BM server changes during the provisioning process, and at that point, my tooling loses track of it, and fails. In this ticket:
https://control.softlayer.com/support/tickets/21903245
I was told that I should use the global identifier instead of the server id. I finally got around to testing that, but I am seeing an issue. It would seem that I can't query the hardware status of the new server using the global identifier when I have first submitted the request, like I can with the server id.
[chrisr#ratsy tools]$ curl -k -u chrisr1:<PW> "https://api.softlayer.com/rest/v3/SoftLayer_Hardware/320526/getHardwareStatus.json"
{"id":3,"status":"DEPLOY"}
[chrisr#ratsy tools]$ curl -k -u chrisr1:<PW> "https://api.softlayer.com/rest/v3/SoftLayer_Hardware/75302613-e55a-481a-829f-967799a41968/getHardwareStatus.json"
null
However, it does work later. I ran the same query for a server that was all ready provisioned.
[chrisr#ratsy tools]$ curl -sS -k -u chrisr1:<PW> "https://api.softlayer.com/rest/v3/SoftLayer_Hardware/1ab37f37-9373-4e10-9de4-7319fffcb4f8/getHardwareStatus.json" | json_pp
{
"status" : "ACTIVE",
"id" : 5
}
I need an identifier that I can query on that is:
a) available right away, and
b) won't change
Thanks.
The Global Identifier is assigned to the hardware until the provision is complete, for this reason the request returns "null" value. But it is the identifier that would not change if the server has been re-assigned.
Apparently there not exists any identifier that you can use to track Bare Metal Servers according your requirements.
However, I can recommend to track your server provisioning through hostname that you assigned to the server.
Getting server's information
https://$user:$apiKey#api.softlayer.com/rest/v3/SoftLayer_Account/getHardware?objectFilter={"hardware":{"hostname":{"operation":"serverHostname"}}}
Method: Get
Replace: serverHostname with the server's hostname that you
defined in your order.
The response will provide information about server's identifier,
then you can check the status from server with it.
https://$user:$apiKey#api.softlayer.com/rest/v3/SoftLayer_Hardware/123123/getHardwareStatus
Method: Get
Note: You need to make sure that you don't have more than one bare metal server's with the same hostname.
You are using wrong the global identifier, the idea is you query the server repeatedly until the provisionDate is filled in, it means you call the http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/getObject method and review if the "provisionDate" field has been filled in, in case that the field is not filled in that means that the server is still in provisioning. Once the provisioning server has been completed the "provisionDate" field will be filled in and also the ID of the server and other data will be updated as well. So you do not need to call the getHardwareStatus method in order to know if the server is still in provisioning or completed.

how to use sql server packages in go

I use the denisenkom/go-mssqldb package for connecting to SQL server in go but I don't know how to write the connecting code,
what are the arguments of this method : sql.Open() for example when we say :
db, err := sql.Open("mysql", "user:password#/database")
what do "mysql" and "user:password#/database" refer to?
and in which part of the program we should tell the name of the database which we want to use in the program? I mean in which part of the code we introduce the name of the database we want to use?
"mssql" is the protocol/driver/database type you are connecting to. "user:password#/database" is the connection string. See this example for the components of this String.
Your application typically knows the database it wants to connect. Or at last when the user logs in.

Postgresql job scheduler using pgagent giving error with update query

I have created a job scheduler using pgagent in postgresql:
What I did is mentioned as screen shots
I had created like this to update name in my database field in a certain time. But when I check it is getting failed.
The failed status as follows:
What I did wrong? How can I correct it?
I have also faced the same problem exactly. By trial and error, I changed the Connection Type from Local to Remote and gave the following connection string
user=some_user password=some_password host=localhost port=5432 dbname=some_database
in the properties of the Step. And, it worked. So, the trick is to treat even the local server as a remote server.

WCF SQL adapter issue while inserting the records into a SQL Server 2012 tables

Issue while inserting the records into the SQL Server 2012 table using the WCF SQL adapter. I am getting the following error message.
Error details: Microsoft.ServiceModel.Channels.Common.XmlReaderParsingException: The start element with name "NewDataSet" and namespace "http://www.ATM.Schemas.ATMAcquirerTransactionsDetails" was unexpected. Please ensure that your input XML conforms to the schema for the operation.
URI: mssql://WIN-UHMK25Q5BMH/BLUECLOUDSQL/ATM?
Action: TableOp/Insert/dbo/ATMAcquirerTransactionsDetails
Please help me resolve the issue.
The Root Node Name and Namespace properties you configured on your WCF-SQL Adapter do not correspond to the Root Node Name and Namespace present on the message that you are sending to the Adapter.
You might want to check the message you are sending and change the adapter properties accordingly; or map the message to the correct Root Node Name and Namespace.
I have similar problem. This is perhaps because the schema contains more than one element (NewDataSet must be the second, judging by my case). This means you are trying to write simultaneously to two tables. I haven't figured out a solution yet.

Check for the server name in connection string if it exists or not

I have done a program where in which I'll pass the server name to the connection string at run time. I need to check if the server name is valid.
Help me out with this?
Try using the SqlDataSourceEnumerator.Instance.GetDataSources() method to get a list of available SQL servers. (see MSDN: http://msdn.microsoft.com/en-us/library/system.data.sql.sqldatasourceenumerator.getdatasources.aspx)
You alternatively might want to connect to the server in a Try..Catch block and check if the connection status is 'open'.