GithubHelp home page GithubHelp logo

Comments (4)

jhecking avatar jhecking commented on June 29, 2024

At the moment, that's not possible. But it wouldn't be too difficult to extend the concept of the customizable serializer and provide hooks to customize how the session object is mapped to/from a record in Aerospike. I.e. we would need a new interface that provides two methods:

(session) => record
(record) => session

PR would be welcome.

from aerospike-session-store-expressjs.

jhecking avatar jhecking commented on June 29, 2024

@umangkedia, please take a look at PR #10. I've added a new, customizable data mapper to replace the existing serializer. With the new data mapper interface, it's possible to map the session object to Aerospike record bins in any way you want.

from aerospike-session-store-expressjs.

umangkedia avatar umangkedia commented on June 29, 2024

@jhecking This should work fine. I have forked the repo for now as I needed few more changes like option to save the PK so that it is returned back while querying secondary index.

from aerospike-session-store-expressjs.

jhecking avatar jhecking commented on June 29, 2024

@umangkedia, sure, let me know if you make some changes to your fork that you think should be merged back into the official copy.

To save the record key on the server, you can set the client's default write policy like this:

const writePolicy = new Aerospike.WritePolicy({ key: Aerospike.policy.key.SEND })
const clientConfig = new Aerospike.Config({ policies: { write: writePolicy } })
const client = Aerospike.client(clientConfig)

And you can now supply a custom mapper to add extra bins to the record in the DB:

const mapper = {
  toRecord: session => {
    return {
      session: JSON.stringify(session),
      mobileNumber: session.mobileNumber,
      userId: session.userId
    }
  },
  fromRecord: record => JSON.parse(record.session)
}

Here is a full, working example: https://gist.github.com/anonymous/c6367ee14c7c0eb7f42b34d7b76617e2

from aerospike-session-store-expressjs.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.