nwnx_redis
and nwnx_redis_short
. They do the same, but _short
is not prefixed with NWNX_Redis
.nwnx_redis_ps.nss
and on_pubsub.nss
are not needed if PubSub functionality is not being used.NWNX_REDIS_HOST
and NWNX_REDIS_PORT
for nwnx. NWNX_REDIS_PORT
is not necessary if the default redis port is used.To use Redis commands in nwscript include nwnx_redis
and nwnx_redis_lib
. The nwnx_redis include contains the redis commands like, for example, int NWNX_Redis_GET(string key)
. All of the nwnx redis comands return an int which is the resultId. The nwnx_redis_lib include contains functions to get the data (and type) you can work with for this resultId. Three of these functions are:
There are also functions to work with result arrays and one to get the type of a result. You can look those up in nwnx_redis_lib.nss.
NWNX_Redis_GetResultAs<Type>
has to be called on all the commands that return a resultId even if the actual value is an int as well. The following is an example to set, check for existance of and get a key.
NWNX_REDIS_PUBSUB_SCRIPT
). An example is included in NWScript/.NWNX_REDIS_PUBSUB_CHANNELS
to be "test".redis-cli
to connect to your running redis server and type PUBLISH test hi there
.redis-cli monitor
in a separate shell is a great way to figure out what's going on.NWNX_Redis_GetPubSubMessageData()
.NWNX_Redis_PUBLISH("nwserver.players.join", GetPCPlayerName(..));
HSET nwserver:players:PlayerName:.lastSeen 1234
) and then trigger a PubSub message with the same subject (PUBLISH nwserver.players.joins PlayerName
). This cuts down on wire overhead.Variable Name | Type | Default Value |
---|---|---|
NWNX_REDIS_HOST | string | (none) |
NWNX_REDIS_PORT | int16 | 6379 |
NWNX_REDIS_PUBSUB_SCRIPT | string | on_pubsub |
NWNX_REDIS_PUBSUB_CHANNELS | comma-separated strings | "" |
Files | |
file | nwnx_redis.nss |
Autogenerated redis commands for NWNX usage. Autogenerated on: 2019-10-01 20:51:53 -0400. | |
file | nwnx_redis_lib.nss |
Allows connection and interfacing with a redis server. | |
file | nwnx_redis_ps.nss |
Interface to Redis PUBSUB. | |
file | on_pubsub.nss |
Script to handle PubSub event. | |
Functions | |
int | NWNX_Redis_GetResultType (int resultId) |
Returns the result type as a int. More... | |
int | NWNX_Redis_GetArrayLength (int resultId) |
Gets the length of the given result. More... | |
int | NWNX_Redis_GetArrayElement (int resultId, int idx) |
Gets a list entry as a string. More... | |
float | NWNX_Redis_GetResultAsFloat (int resultId) |
Gets the given result as a float. More... | |
int | NWNX_Redis_GetResultAsInt (int resultId) |
Gets the given result as an integer. More... | |
string | NWNX_Redis_GetResultAsString (int resultId) |
Gets the given result as a string. More... | |
int NWNX_Redis_GetResultType | ( | int | resultId | ) |
Returns the result type as a int.
Definition at line 66 of file nwnx_redis_lib.nss.
int NWNX_Redis_GetArrayLength | ( | int | resultId | ) |
Gets the length of the given result.
resultId | The result id. |
Definition at line 73 of file nwnx_redis_lib.nss.
int NWNX_Redis_GetArrayElement | ( | int | resultId, |
int | idx | ||
) |
Gets a list entry as a string.
resultId | The result id. |
idx | The index in the list. |
Definition at line 81 of file nwnx_redis_lib.nss.
float NWNX_Redis_GetResultAsFloat | ( | int | resultId | ) |
Gets the given result as a float.
resultId | The result id. |
Definition at line 89 of file nwnx_redis_lib.nss.
int NWNX_Redis_GetResultAsInt | ( | int | resultId | ) |
Gets the given result as an integer.
resultId | The result id. |
Definition at line 96 of file nwnx_redis_lib.nss.
string NWNX_Redis_GetResultAsString | ( | int | resultId | ) |
Gets the given result as a string.
resultId | The result id. |
Definition at line 103 of file nwnx_redis_lib.nss.
const int NWNX_REDIS_RESULT_ARRAY = 1 |
Array result.
Definition at line 13 of file nwnx_redis_lib.nss.
const int NWNX_REDIS_RESULT_ERROR = 3 |
Error result.
This never appears: it is rewritten into STRING for simplicity reasons. const int NWNX_REDIS_RESULT_BULK_STRING = 2;
Definition at line 20 of file nwnx_redis_lib.nss.
const int NWNX_REDIS_RESULT_INTEGER = 4 |
Integer result.
Definition at line 25 of file nwnx_redis_lib.nss.
const int NWNX_REDIS_RESULT_STRING = 5 |
String result.
Definition at line 28 of file nwnx_redis_lib.nss.
const int NWNX_REDIS_RESULT_NULL = 6 |
Null result.
Definition at line 31 of file nwnx_redis_lib.nss.