Redis only using 1 key in database - wordpress

I have setup Redis as a caching mechanism on my server with a Wordpress site. Basically on each request I check if a cache of the page exists and then I show the cache.
I'm using Predis (https://github.com/nrk/predis) as an interface to the redis database.
When I get the info from the usage of Redis however, I only see 1 key used in the system:
used_memory:103810376
used_memory_human:99.00M
used_memory_rss:106680320
used_memory_peak:222011768
used_memory_peak_human:211.73M
mem_fragmentation_ratio:1.03
mem_allocator:jemalloc-2.2.5
loading:0
aof_enabled:0
changes_since_last_save:8
bgsave_in_progress:0
last_save_time:1396168319
bgrewriteaof_in_progress:0
total_connections_received:726918
total_commands_processed:1240245
expired_keys:22
evicted_keys:0
keyspace_hits:1158841
keyspace_misses:699
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:21712
vm_enabled:0
role:master
db0:keys=1,expires=0
How could this be? I expect to see more keys listed, as each cached copy of the html of a page should have it's own key?
What am I missing here?

Without looking at the technical implementation, it could be several things.
1) The pages didn't get a hit, so they are not in the cache
2) The keys expired already
3) The mechanism uses for example a HSET , where you can have N key/values registered under 1 main key. You can check this by using the TYPE redis command on the single key you've got.

Related

SignalR connected client in Clients.User(..) shouldn't exist

In my SignalR hub, I use the following method to check whether a user has an active connection:
var receivingClient = Clients.User(receiver);
if (receivingClient != null)
{
But I also track the online users manually over OnConnected \ OnDisconnected (in a ConcurrentDictionary). Now even when I shut down everything and start the server from scratch (e.g. IISExpress from VS), the above code part returns a result for a connection that doesn't exist.
Let's say I send from User A to user B. I start the server, go online with user A, then send a message to B: The above code returns a Microsoft.AspNetCore.SignalR.Internal.UserProxy<mySite.Services.ChatHub>.
I don't get it. Is it wrong to check for existing client connections with a null check? Should I exclusively rely on my manual tracking?
Thanks for some insight!
(PS: This is all on the same server - no load balancing / sharding)
Clients.User(receiver) returns a type that is used to invoke methods for the given user. It doesn't have anything to do with whether the user you pass in exists or not.
Is it wrong to check for existing client connections with a null check? Should I exclusively rely on my manual tracking?
Yes. Use manual tracking.

Calling .setPersistenceEnabled(false) when logging out of app, not working

In my Flutter/Dart mobile app I make use of Firebase RTDB persistence to enable offline use of the app.
My understanding is that to enable persistence you have to make the call, as per the following piece of code, before using any database references to eg. query the database. I use the following piece of code to enable persistence immediately after loading the app and it works fine:
FirebaseDatabase firebaseDatabase = FirebaseDatabase.instance;
bool _success = await firebaseDatabase.setPersistenceEnabled(true);
print(_success); // Prints true, so persistence is set 'on'.
When I logout of the app I attempt to turn persistence off with:
bool _success = await firebaseDatabase.setPersistenceEnabled(false);
print(_success); // Prints false, so persistence is still 'on', ie. the call failed.
I assume the reason persistence cannot be turned off is because there have been calls to db references prior to trying to switch it off.
This leads to three questions, I guess:
Should I be worried about turning it off at all, when I logout? The reason I attempt it is good house-keeping, mainly. I clean up shared preferences, close keepsyncd's, etc when logout is run. Also, though, the user can have multiple userids to login and I want to make sure that I am not retaining persisted data from their previous login id.
Related to 1, does setting persistence to false clear the cache of
data and potential queued calls to the db?
If the answers to 1 and 2 are 'yes', how can I switch persistence off given the code I'm using to do so keeps telling me it failed?
The typical way to handle this is to enable persistence once a user logs in.
Once disk persistence has been enabled and your app has used the database, it cannot be turned off. The documentation says this about it:
The returned Future will complete with true if the operation was successful or false if the persistence could not be set (because database references have already been created).
That last bit is clearly the case for you: you've been using the database already, which means that disk persistence is on.
To your specific questions:
Unfortunately the data in the local cache cannot be cleared up through the API at the moment. It is a valid feature request, but for now you'll have to assume that any data on the device can be seen by any user on that device (or device profile).
Disabling disk persistence keep the client from adding data to the cache. It does not clear any existing data in the cache.

Symfony - Log runnables natives queries when database is out

I'am working on a Symfony app that provides a rest web service (simple HTTP Request with JSON).
That service check some rules and inserts few lines in two MySQL table (write only).
For optimize reason, even if Doctrine bundle is available, i use native MySQL Query (with bind params) to insert this lines.
My need is : If for any reason, the database is not available, write "runnables" queries into a log file.
The final purpose is that when database is back, i want to be able to execute directly the file's content on the database.
Note that there is no unique constraint (pk is a generated uuid) and no lock or transaction to handle (simple insert statements).
I write a custom SQLLogger, but when $connection->insert(...) is called, the connect fail before logger is called.
So, my question is : There is a way to get the final query (with binded parameters) without database connection ?
Or should i rewrite the mecanism that bind params into query and log it myself when database is not available ?
Best regards,
Julien
As the final query with parameters is build by the database, there is just no way to build the query with PHP and to be garanteed that the query will be the same as the database.
The only way si to build query without binded parameters, but this is clearly not a good practice.
So, i finally decided to store all the JSON (API request body) in a file if the database is not available.
So when the database is back, instead of replay SQL queries, i can replay the original HTTP query.
Hope this late self-anwser will help someone.
Best regards.

ASP.NET Azure Blob Geographically Redundant Storage - How to use?

I have been searching for an answer on MS, SE and Google and cannot find it. I want to use the GRS option for Azure Storage (Cloud Block Blobs) but I cannot figure out how to properly do that.
I created my storage object in Azure and chose the GRS option.
I get that I have a primary and secondary connection string and know how to get that from the Azure portal.
What I do not know, in ASP.NET 4.0, is how to set both connection strings in the CloudBlockClient and gracefully handle the primary storage being unavailable.
--What exception is thrown and where, when primary is unavailable? Is this thrown when I create the client, or when I try to get a blob reference?
-- How do I then use the secondary?
Do I have to just test for any old exception and then try using the secondary connection string in a new CloudBlockClient if the primary does not work? Or is there anything in the API for this. I would think there would be but I cannot find it.
None of the "How to use Azure Storage" tutorials I have seen go into this. Most of the documentation seems to date from before mid-2014 when this feature became generally available.
This blog post should help you. In short if you want to read from both primary and secondary you want to enable RA-GRS - essentially read access from the secondary. If you are using out storage client libraries you can also enable a retry policy that will first try to read from a primary and then from the secondary if the first read fails.

Express.js session with sqlite

I am trying to setup a light weight application with Express.js. I would like to use Sqlite3 for storage.
I need some sort of session management and trying to use the session management module described in the Express guide document like so (CoffeeScript)
g.app.configure ->
g.app.set 'views', "#{__dirname}/views"
g.app.set 'view engine', 'jade'
g.app.use g.express.bodyParser()
g.app.use g.express.cookieParser()
g.app.use g.express.session(secret:'cruel')
g.app.use g.express.methodOverride()
g.app.use g.app.router
g.app.use g.express.static "#{__dirname}/public"
Now I would like to store the sessions either in sqlite3 or as files in the project path somehow.
All examples I find use different kinds of NoSql-databases.
Could anyone shed some light on where to find other session store modules, or even how to implement one.
I think these 3 links will be useful for you:
http://senchalabs.github.com/connect/middleware-session.html (at the bottom of the page)
https://github.com/senchalabs/connect/blob/master/lib/middleware/session/memory.js
(the default memory store for session that connect has built-in)
https://github.com/senchalabs/connect/wiki (Session Stores)
From the Connect guide (Connect Session page):
Session Store Implementation
Every session store must implement the following methods
* .get(sid, callback)
* .set(sid, session, callback)
* .destroy(sid, callback)
Recommended methods include, but are not limited to:
* .length(callback)
* .clear(callback)
For an example implementation view the connect-redis repo.
* param Object options
* returns Function
All examples I find use different
kinds of NoSql-databases.
The nice thing about a lot of those NoSQL databases is that they are really easy to install. Installing redis is very easy and will make your site a lot faster(in memory database backupped by disc)...
Could anyone shed some light on where
to find other session store modules
I found the following modules using http://search.npmjs.org / http://github.com searches:
https://github.com/pkrumins/supermarket-cart
Supermarket-cart can be used to store
connect's sessions in supermarket
database.
I believe this uses sqlite.
http://search.npmjs.org/#/connect-cookie-session:
A Connect middleware to allow you to
store your sessions directly in the
client's cookie.
https://github.com/caolan/cookie-sessions
Secure cookie-based session middleware
for Connect.
https://github.com/creationix/nstore-session
This is a simple session store for
Connect that uses nStore for
persisting session data.
https://github.com/visionmedia/connect-redis
connect-redis is a Redis session store
backed by node_redis, and is insanely
fast :)
https://github.com/masylum/connect-mongodb
https://github.com/kcbanner/connect-mongo
This is what I found quickly, but when doing a more thoroughly search I believe you should be able to find even more session implementations.
or even how to implement one.
I think you should be able to use supermarket-cart, but you could also implement your own store by using this links as a reference:
http://senchalabs.github.com/connect/middleware-session.html
https://github.com/visionmedia/connect-redis

Resources