1Apache::Session::BrowseUasbelre:C:oMnytSrQiLb(u3t)ed PerAlpaDcohceu:m:eSnetsastiioonn::Browseable::MySQL(3)
2
3
4
6 Apache::Session::Browseable::MySQL - Add index and search methods to
7 Apache::Session::MySQL
8
10 Create table with columns for indexed fields. Example for
11 Lemonldap::NG:
12
13 CREATE TABLE sessions (
14 id varchar(64) not null primary key,
15 a_session text,
16 _whatToTrace text,
17 _session_kind text,
18 _utime bigint,
19 ipAddr text
20 );
21
22 Add indexes:
23
24 CREATE INDEX uid1 ON sessions (_whatToTrace) USING BTREE;
25 CREATE INDEX s1 ON sessions (_session_kind);
26 CREATE INDEX u1 ON sessions (_utime);
27 CREATE INDEX ip1 ON sessions (ipAddr) USING BTREE;
28
29 Use it with Perl:
30
31 use Apache::Session::Browseable::MySQL;
32
33 my $args = {
34 DataSource => 'dbi:mysql:sessions',
35 UserName => $db_user,
36 Password => $db_pass,
37 LockDataSource => 'dbi:mysql:sessions',
38 LockUserName => $db_user,
39 LockPassword => $db_pass,
40
41 # Choose your browseable fileds
42 Index => 'uid mail',
43 };
44
45 # Use it like Apache::Session
46 my %session;
47 tie %session, 'Apache::Session::Browseable::MySQL', $id, $args;
48 $session{uid} = 'me';
49 $session{mail} = 'me@me.com';
50 $session{unindexedField} = 'zz';
51 untie %session;
52
53 # Apache::Session::Browseable add some global class methods
54 #
55 # 1) search on a field (indexed or not)
56 my $hash = Apache::Session::Browseable::MySQL->searchOn( $args, 'uid', 'me' );
57 foreach my $id (keys %$hash) {
58 print $id . ":" . $hash->{$id}->{mail} . "\n";
59 }
60
61 # 2) Parse all sessions
62 # a. get all sessions
63 my $hash = Apache::Session::Browseable::MySQL->get_key_from_all_sessions();
64
65 # b. get some fields from all sessions
66 my $hash = Apache::Session::Browseable::MySQL->get_key_from_all_sessions('uid', 'mail')
67
68 # c. execute something with datas from each session :
69 # Example : get uid and mail if mail domain is
70 my $hash = Apache::Session::Browseable::MySQL->get_key_from_all_sessions(
71 sub {
72 my ( $session, $id ) = @_;
73 if ( $session->{mail} =~ /mydomain.com$/ ) {
74 return { $session->{uid}, $session->{mail} };
75 }
76 }
77 );
78 foreach my $id (keys %$hash) {
79 print $id . ":" . $hash->{$id}->{uid} . "=>" . $hash->{$id}->{mail} . "\n";
80 }
81
83 Apache::Session::browseable provides some class methods to manipulate
84 all sessions and add the capability to index some fields to make
85 research faster.
86
88 Apache::Session
89
91 Xavier Guimard, <x.guimard@free.fr>
92
94 Copyright (C) 2009-2017 by Xavier Guimard
95 2013-2017 by Clement Oudot
96
97 This library is free software; you can redistribute it and/or modify it
98 under the same terms as Perl itself, either Perl version 5.10.1 or, at
99 your option, any later version of Perl 5 you may have available.
100
101
102
103perl v5.32.0 2020-09-A0p7ache::Session::Browseable::MySQL(3)