Making ServiceStack RedisSentinel use a RedisManagerPool instead of a PooledRedisClientManager - servicestack

Using ServiceStack version 4.0.40.
I am trying get RedisSentinel to use the RedisManagerPool instead of the
PooledRedisClientManager so it will allow clients above the client pool size.
I see this in the docs to set this...
sentinel.RedisManagerFactory = (master,slaves) => new RedisManagerPool(master);
I'm not sure how to use this. Do I pass in the master host name? What if I don't know which is master because of a previous failover? I can't sentinel.start() to find out which is master because it will start with the PooledRedisClientManager, which isn't what I want.
Or, do I pass in the sentinel hosts? RedisManagerPool takes a list of hosts, I can pass in the sentinel hosts, but I cannot set it to sentinel.RedisManagerFactory as RedisManagerFactory is not convertible to RedisManagerPool.
I think I am missing something simple here. Any help appreciated.
UPDATE
As per mythz's comment below, this isn't available in version 4.0.40 of ServiceStack. But you can use;
sential.RedisManagerFactory.FactoryFn = (master, slaves) => new RedisManagerPool(master);
Thanks

This is literally the config you need to use to change RedisSentinel to use RedisManagerPool:
sentinel.RedisManagerFactory = (master,slaves) =>
new RedisManagerPool(master);
You don’t need to pass anything else, the master host argument uses the lambda argument.

Related

Jooq database/schema name mapping

I use jooq to generate objects against a local database, but when running "for real" later in production the actual databases will have different names. To remedy this I use the <outputSchemaToDefault>true</outputSchemaToDefault> config option (maven).
At the same time, we have multiple databases (schemas), and are using a connection pool to the server like "jdbc:mysql://localhost:3306/" (without specifying a database here).
How do I tell jooq which database to use when running queries?
I have tried all config I can think of:
new Settings()
.withRenderSchema(true) // true/false seems to make no difference.
.withRenderCatalog(true) // true/false seems to make no difference.
.withRenderMapping(new RenderMapping()
.withDefaultSchema("my_database") // Seems to have no effect.
// The above 3 configs always give me an error saying "no database selected".
// Adding this gives me 'my_database.my_table' does not exist - while it actually does.
.withSchemata(new MappedSchema()
.withInputExpression(Pattern.compile(".*"))
.withOutput("my_database")
));
I have also tried using a database/schema name, as in not configuring outputSchemaToDefault. But then, adding the MappedSchema code above, but that gives me errors with "'my_databasemy_database.my_table' does not exist", which is correct. I have no clue why that code gives me the database/schema name twice?
Edit:
When jooq tells me that the db.table does not exist, if I put a break point in a good place and get the sql from jooq and run exactly that against my database it does work. But jooq fails to run it.
Also, I'm using version 3.15.3 of jooq.
I solved it. Instead of using .withInputExpression(Pattern.compile(".*")), it seems to work with .withInput("").
I'm still not sure why it works, or if this is the "correct" way of solving it. But at least it is a way forward.
No clue why using the pattern, I got the name twice though. But that one I'll leave alone.

Issue NestJS with oracle TypeORM

I'm trying to connect my NestJs Project with a Oracle db and I'm using TypeORM and the status of connection is ok but I don't know how I can connect with a function. This function is into of a package and at the same time this package is into of a schema. The structure is like:
mySchema:
--------->myPackage:
-------------------->myFunction(id)
In the NestJS code I'm define this import in the AppModule file:
When I try to use the entity I don't know what method can I use to connect with my function. With the ESLint I get the next methods:
I hope to be clear and thanks for all!
In you last picture you’re trying to make a request to the database and as you can see, when you mentioned the testRepository and dots(.) now you have to tell him what you want to do in your database and in the suggested list you have all the possible possibilities.
So if you want to get or fetch data from you database, you will use testRepository.find() this will give you everything in that particular entity. To do that, you have to do something like below, before that you code has something that I have never seen in Nest, (public); if it does exist but I won’t use that in my Example since I don’t know it in Nest and also; you have started writing without (return) I don’t know how you’re expecting to return what you will get from your database.
Here is my example:
in your controller:
#Get() AnyThing(): Promise<TestEntity[]> {return this.DaobscsService.whatEver(); }
And in your service:
#InjectRepository(TestEntity) private readonlytestRepository: Repository<TestEntity>, ) {}
async whatEver(): Promise<TestEntity[]> {return await this.testRepository.find();}
What ever name you gonna use instead (whatEver()) in the service that have used, remember to use the same name in your controller pointing to service (this.Boa...Service.(The name here) OOP system’s you know it I hope
This example is to get or fetch so if you don’t have any thing in your database then you will get nothing! if that’s not what u want then command with a full version of what exactly is your issue, what u expected and code from controller, service, and module.

How do I enforce a server-generated timestamp to a document in Firestore? [duplicate]

How do I check if user on client sided created document with only firebase.firestore.FieldValue.serverTimestamp()?
I have following:
allow create: if request.resource.data.timestamp == ??
What should I have instead of ??. I have tried serverTimestamp() firebase.firestore.FieldValue.serverTimestamp(), now or now() but it doesn't work.
It is possible to do it in Firebase like this:
".validate": "newData.child('timestamp').val() === now"
I am looking for the same solution. Any ideas? Thanks
You can access the current request timestamp in Security Rules using the request.time attribute (docs), which is the Firestore equivalent to the Realtime Databases's now. You'll therefore want something like:
allow create: if request.resource.data.timestamp == request.time;
For serverTimestamp() this should evaluate to true.
You should always validate client input in Security Rules, even if you're using serverTimestamp(). Security Rules doesn't automatically know the server input the value instead of the client, so without this check, a malicious client could create a different created at time.

Can ActiveStorage::PurgeJob be enqueued to other than `default`?

There wasn't any queue named default in our Rails code. But it seems Sidekiq sets queue for ActiveStorage::PurgeJob as default. That was why purge_later never worked.
[ActiveJob] Enqueued ActiveStorage::PurgeJob (Job ID: .. ) to Sidekiq(default) with arguments
Is there a way to have different queue name than "default" here? I couldn't find documentation about it yet.
Setting the name of the Active Job queue used by Active Storage
You can change the queue used by Active Storage for its async jobs at the configuration level like this
config.active_storage.queue = :low_priority
To make this an application-wide change, put it into your application.rb. For environment-specific changes, put it into the relevant environment file under config/environments
See the documentation here:
https://guides.rubyonrails.org/configuring.html#configuring-active-storage
This did not work for me, instead the following worked
config.active_storage.queues = Hash.new(:default)
This is due to purge_job.rb looking up the queue name like so
queue_as { ActiveStorage.queues[:purge] }
For Rails 7.1, setting config.active_storage.queue doesn't impact the queue used by the PurgeJob.
This did the trick:
config.active_storage.queues.analysis = "my-queue"
config.active_storage.queues.purge = "my-queue"

Passing sets of properties and nodes as a POST statement wit KOA-NEO4J or BOLT

I am building a REST API which connects to a NEO4J instance. I am using the koa-neo4j library as the basis (https://github.com/assister-ai/koa-neo4j-starter-kit). I am a beginner at all these technologies but thanks to some help from this forum I have the basic functionality working. For example the below code allows me to create a new node with the label "metric" and set the name and dateAdded propertis.
URL:
/metric?metricName=Test&dateAdded=2/21/2017
index.js
app.defineAPI({
method: 'POST',
route: '/api/v1/imm/metric',
cypherQueryFile: './src/api/v1/imm/metric/createMetric.cyp'
});
createMetric.cyp"
CREATE (n:metric {
name: $metricName,
dateAdded: $dateAdded
})
return ID(n) as id
However, I am struggling to know how I can approach more complicated examples. How can I handle situations when I don't know how many properties will be added when creating a new node beforehand or when I want to create multiple nodes in a single post statement. Ideally I would like to be able to pass something like JSON as part of the POST which would contain all of the nodes, labels and properties that I want to create. Is something like this possible? I tried using the below Cypher query and passing a JSON string in the POST body but it didn't work.
UNWIND $props AS properties
CREATE (n:metric)
SET n = properties
RETURN n
Would I be better off switching tothe Neo4j Rest API instead of the BOLT protocol and the KOA-NEO4J framework. From my research I thought it was better to use BOLT but I want to have a Rest API as the middle layer between my front and back end so I am willing to change over if this will be easier in the longer term.
Thanks for the help!
Your Cypher syntax is bad in a couple of ways.
UNWIND only accepts a collection as its argument, not a string.
SET n = properties is only legal if properties is a map, not a string.
This query should work for creating a single node (assuming that $props is a map containing all the properties you want to store with the newly created node):
CREATE (n:metric $props)
RETURN n
If you want to create multiple nodes, then this query (essentially the same as yours) should work (but only if $prop_collection is a collection of maps):
UNWIND $prop_collection AS props
CREATE (n:metric)
SET n = props
RETURN n
I too have faced difficulties when trying to pass complex types as arguments to neo4j, this has to do with type conversions between js and cypher over bolt and there is not much one could do except for filing an issue in the official neo4j JavaScript driver repo. koa-neo4j uses the official driver under the hood.
One way to go about such scenarios in koa-neo4j is using JavaScript to manipulate the arguments before sending to Cypher:
https://github.com/assister-ai/koa-neo4j#preprocess-lifecycle
Also possible to further manipulate the results of a Cypher query using postProcess lifecycle hook:
https://github.com/assister-ai/koa-neo4j#postprocess-lifecycle

Resources