Hello there,

I wanna using phpredis to storing our site session, so I modified on php.ini then add:

session.save_handler = redis
session.save_path = "tcp://localhost:6379"

And I tested on our phpinfo() the information are ok:

php info

I create a custom module, and on hook_init(), I create a Session:

session_start();
if (isset($_SESSION['country']))
{
$_SESSION['country'] = $country_code;
}

The session $_SESSION['country'] is storing successfully, but it not storing by redis, I tried search on redis server but I was not found anything stuff.

Everyone has experience?

CommentFileSizeAuthor
screen.png30.2 KBjohntang
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pounard’s picture

Status: Active » Postponed (maintainer needs more info)

This is because Drupal will override your session handler and use its own, it goes straight to the database. I'd recomend that you try using this module: https://drupal.org/project/session_proxy

Or alternatively you could write a session.inc replacement using Redis, which I didn't because when needed I chose to use the session proxy module instead (which is actually working on a few sites).

Please re-open if you have any other questions or mark it as fixed if this answer suits you.

johntang’s picture

@pounard,

I didn't install this module, still keep using Drupal overwrite session but I think this is a best choice for my issue. I will install it on the next coming days and post again.

Thanks for help.

johntang’s picture

Once I installed https://drupal.org/project/session_proxy module, and config with phpredis, anything ok But I got the message:

 Allowed memory size of 134217728 bytes exhausted (tried to allocate 40 bytes) in /var/www/html/site/includes/database/log.inc on line 145

and lost all user profile picture on database, I tried increasing the memory to 256MB but still got it.

On our redis server, we saw the memory used is about 30.5 MB. Whenever I disable this module and comment all config stuff on setting.php, it working again.

Whose meets this problem?

pounard’s picture

There is great chances that your PHP memory limit exhaustion is due to the site as a whole, if you use a lot of modules etc... Adding a module may have triggered this. But if this is a bug due to the session proxy module, I need to find it, please give me the module versions you are using for all of core, redis and session_proxy.

johntang’s picture

Session proxy: 7.x-1.0-alpha1
Redis: 7.x-2.6

All are latest version.

Anonymous’s picture

Version: 7.x-2.6 » 7.x-3.x-dev
Category: Support request » Feature request
Status: Postponed (maintainer needs more info) » Active

Hi,

I am reopening this (but changing it to a feature request) because in experimenting with Session Proxy to store sessions in Redis I discovered that it breaks quite a few other modules that depend on the structure of the Drupal sessions table, as I also described at this issue at Session Proxy: https://www.drupal.org/node/1260634#comment-9941293

For instance, the NodeJS module has a function as follows that is expecting to have the uid & sid or ssid present in the session storge:

function nodejs_auth_check_callback($auth_token) {
  $sql = "SELECT uid FROM {sessions} WHERE MD5(sid) = :auth_key OR MD5(ssid) = :auth_key";
  return db_query($sql, array(':auth_key' => $auth_token))->fetchField();
}

With Session Proxy currently, it doesn't have that information. It is using the default cache bin structure (drupal_get_schema_unprocessed('system', 'cache')). Probably a lot of other modules will cease to work with the current Session Proxy method, such as Session Expire & Session Limit.

So, to sum up, having a Redis-module session.inc that could store sessions in Redis with the same structure Drupal uses in the sessions table would perhaps save conflicts with a lot of other modules, or at least make it easier for them to be patched to work.

pounard’s picture

Status: Active » Closed (works as designed)

Are you aware that I'm the maintainer of the two modules ? :) I'm going to give you the exact same answer as in the other module in #1260634: Add ability to manage session storage in APC or memcached:

Indeed there is no actual solution to this problem. By definition session handling is meant to be pluggable and its database table *IS NOT* a public facade. This means that any module working on it is supposed to only work with core session management.

I think that every session backend will be the cause for you of the exact same problem.

The only solution for this is the following: if you need a specific feature on the session management, and use a specific backend that does not use the database, ask politely the module maintainer to add the feature, or make a patch for your usage.

This is unsolvable in a generic way by design.

I'm closing this issue in flavor of the other module, I'd gladly answer any question or take a few minutes to think about solutions for your needs, but you'll have to open a specific issue for each specific need. We'll then see in the other issue queue (Session Proxy one) if the problem is storage specific (for example Redis or Memcache) or if it can be solved more generically in the Session Proxy module.

Anonymous’s picture

Thank you for your reply. That makes sense.