NetSDS::Session(3pm)
π NetSDS::Session π
okay bestie, welcome to NetSDS::Session(3pm) β part of the User Contributed Perl Documentation. and it is genuinely one of the most useful little modules you'll ever meet. it's giving "I store your sessions in memcached and I do it flawlessly." no cap. π¦
β¨ NAME β¨
NetSDS::Session β memcached based session storage API π
like. that's it. that's the whole name. and honestly? iconic.
πΈ SYNOPSIS πΈ
here's how you actually use it, babes:
use NetSDS::Session;
# Connecting to Memcached server
my $sess = NetSDS::Session->new(
host => '12.34.56.78',
port => '12345',
);
...
# Retrieve session key somehow
$session_key = $cgi->param('sess_key');
$sess->open($session_key);
my $filter = $sess->get('filter');
...
$sess->set('filter', $new_filter);
...
$sess->close();
1;
the little dot-dot-dot bits are literally just "you do stuff here" β it's a vibe, not a real method. π
π DESCRIPTION π
so NetSDS::Session gives you an API for session data storage, and the whole thing runs on top of a Memcached server. β¨
every session is a hash reference structure, and it's identified by a UUID string. like a little name tag for your data. π
the most reasonable usage of this module is temporary data storing for a web based GUI between HTTP requests β that's the main character use case. but ngl, it's possible to find some other tasks too. it's flexible like that. π
lowkey important detail: internally, the session structure is transformed to/from a JSON string whenever it interacts with Memcached. that's just how it rolls. π
π§ CLASS API π§
okay this is the part where we meet the methods one by one. they're all so good. let's go. π
β new(%params) β class constructor
this is the constructor, and it does two things: it establishes a connection to the memcached server, and it sets the default session parameters. like a little welcome committee. π«Ά
Parameters:
hostβ the memcached server hostname or IP address (default: 127.0.0.1)portβ the memcached server TCP port (default: 11211)
Example:
my $sess_hdl = NetSDS::Session->new(
host => '12.34.56.78',
port => '99999',
);
see how easy that was? obsessed. π
π¦ open($sess_id) β open session
this one retrieves session data from the server by session key (that's a UUID string, remember? π).
and if no session exists? don't stress β you just get an empty hashref back. no drama. β¨
π id() β get session id
returns the current session id. that's it. that's the whole thing. short and sweet. π
Example:
my $sess_id = $sess->id();
πΈ set($key, $value) β set session parameter
sets a new session parameter value, identified by its key. super straightforward, we love to see it. π
Example:
$sess->set('order', 'id desc');
π get($key) β get session parameter
returns a session parameter value by its key. the reading counterpart to set. balance. harmony. π«
Example:
my $order = $sess->get('order');
π delete($key) β delete session parameter by key
deletes a session parameter by its key. bye bestie! π
and it returns the updated session data as a hash reference β so you're not left hanging. π«Ά
Example:
$sess->delete('order');
π₯ clear() β clear session data
this method clears all session data. everything. gone. clean slate energy. β¨
Example:
$sess->clear();
β sync() β save session
synchronizes the session data on the Memcached server. like hitting save but for your whole session. πΎβ¨
Example:
$sess->sync();
π close() β save and close session
this method saves all data to the server AND clears the current session id and data from the object. two-for-one. main character behaviour fr fr. π
Example:
$session->close();
(note: that example uses a slightly different variable name β cute little quirk, and we keep the code exactly as written π)
π«Ά SEE ALSO π«Ά
Cache::Memcached::Fastβ XS implementation of Memcached APIJSONβ JSON encoding/decoding API
both absolute icons, go check them out. π
π AUTHORS π
- Michael Bochkaryov
<misha@rattler.kiev.ua>
πΈ THANKS πΈ
- Yana Kornienko β for initial module implementation
we love a shoutout to the originator. π«Ά
π LICENSE π
Copyright (C) 2008-2009 Net Style Ltd.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
no warranty bestie β it's giving "use at your own risk" but make it legal. π
and that's the whole page!! this was NetSDS::Session(3pm) β rendered by perl v5.32.1 on 2021-12-26 π thanks for reading, ily, go store some sessions responsibly. πβ¨
π¦ where this page comes from
- debian bookworm: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- debian trixie: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- ubuntu jammy: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- ubuntu noble: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- ubuntu resolute: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms