Menu
  • HOME
  • TAGS

Retrieve selection of servicestack redis session objects based on values of properties

Tag: redis,servicestack,stackexchange.redis,servicestack.redis,servicestack-auth

I want to update multiple servicestack user sessions that are stored in redis. I want to return all sessions that have a custom property set to a certain value, then I can process them. At the moment the best solution I have returns all keys as such:

List<string> sessionkeys = redis.SearchKeys("urn:iauthsession:*");

I am thinking this will not scale well. I'd like to do something analogous to:

List<string> sessionkeys = redis.AllKeys.Where(x=>x.ParentId == 3);

Is this possible with redis, and if so how, ideally using standard libraries with ServiceStack.

Best How To :

Instead of SearchKeys you want to be using the newer Redis Scan API's which let you iterate over keys in a cursor.

Redis values are blobbed and not indexed so there's not much opportunity to optimize this. The most efficient way would be to inspect the values using a custom server-side LUA operation which will minimize the number of requests and payload sent to the client.

Redis embedded version of LUA has cjson which can be used for deserializing JSON values, the Lua guide for Redis users has some examples of using this.

Since Redis doesn't support server-side querying or indexes, the Redis way would be to premept the queries you need to query on and maintain custom indexes whenever a Session is saved, some info on how to maintain custom indexes in Redis are at:

  • Storing Related Entities and Maintaining Custom Indexes
  • Designing a NoSQL Database using Redis

In ServiceStack you can override OnSaveSession() in your AppHost which gets called whenever a Session is saved.

ServiceStack Self Hosting Redirect any 404 for SPA (Url Rewrite)

angularjs,servicestack

You can register a Fallback Route with a wildcard for this which will let you handle unknown server routes in your Service in order to return the default page so routing can be handled in the client app, e.g: [FallbackRoute("/{PathInfo*}")] public class FallbackForClientRoutes { public string PathInfo { get; set;...

Using redis as a DB for some values

node.js,redis

Store the data in a hash, and create indices using sorted sets. For example: HSET key1 createday value HSET key1 size value And so on. For example, to sort on createday, store it as a Unix timestamp. On adding the entry, also add the ID of the entry (key1 in...

Service Stack set HttpCookie.Secure Flag / Attribute?

servicestack

You need to use SetConfig() when configuring ServiceStack, e.g: SetConfig(new HostConfig { OnlySendSessionCookiesSecurely = true, }); ...

Can Bluebird Promise work with redis in node.js?

javascript,node.js,redis,promise,bluebird

You were trying to use Promise.resolve wrong, it expects a Promise and session.get by default doesn't return a Promise. You first need to promisify it. (or promisifyAll) session.getAsync = Promise.promisify(session.get); // OR Promise.promisifyAll(session); //=> `session.getAsync` automatically created // OR Promise.promisifyAll(redis); //=> Recursively promisify all functions on entire redis Then use...

How change redis to be persistent

redis

Regarding your test, you should wait 5 minutes before killing the process if you want it to be snapshotted. This is the default config for Redis (2.8 - 3.0): ################################ SNAPSHOTTING ################################ # # Save the DB on disk: # # save <seconds> <changes> # # Will save the DB...

Travis gives me Redis connection to localhost:6379 failed - connect ECONNREFUSED

node.js,redis,travis-ci

I had a look at your problem and it seems the problem is due to the format of your .travis.yml file. I forked your project and removed the leading spaces in front of the language and node_js fields. I have created a pull request here that shows the changes I...

ServiceStack selfhosting disable caching for memory

model-view-controller,servicestack

Every request does not get cached in memory, when you're self-hosting it's running the binary dlls and static files that are copied into your /bin folder. You can change Config.WebHostPhysicalPath to change ServiceStack to serve files from your solution folder instead, e.g: SetConfig(new HostConfig { #if DEBUG DebugMode = true,...

ServiceStack versioning - how to customize the request deserialization based on versioning

servicestack

The recommended approach for versioning is to take advantage for the natural forwards compatibility of message-based services and extend existing services defensively so it can support multiple client versions and avoid create multiple versions of the same service. If you still want to expose /api/v1 routes than I'd recommend doing...

Set options for ZADD command in laravel redis

php,laravel,redis,set

Until Predis' zAdd method is updated to support the changes in Redis v3.0.2, your best bet is to explore the wonderful world of RawCommand: https://github.com/nrk/predis/blob/master/src/Command/RawCommand.php It should let you construct your own commands, including the ZADD NX ... variant....

Redis Serialization and Deserialization

redis,deserialization,spring-data,serializable,spring-data-redis

what causes deserialization problems? I would like to give you bit of background before answering your question, The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes...

ServiceStack.Text deserialize string into single object null reference

c#,.net,json,servicestack

By Default ServiceStack only serializes public properties so you could refactor your DTO to include properties, e.g: public class CustomMaker { public int UserID { get; set; } public String error { get; set; } } Or if you wanted to serialize public fields you can specify this with: JsConfig.IncludePublicFields...

Using Redis as a session state provider

asp.net,session,redis,stateless

You could use Redis as a cache to hold various pieces of state about the user. The idea is that when the user logs in, you probably need to load a bunch of information about them from your database (name, address, etc...) at that point, you know the user will...

nodejs Kue job processing logic

node.js,redis,kue

See the documentation - https://github.com/Automattic/kue#processing-jobs While there is a queue, it will continually run, and pick off jobs. As per the example: var kue = require('kue') , queue = kue.createQueue(); queue.process('email', function(job, done){ email(job.data.to, done); }); function email(address, done) { if(!isValidEmail(address)) { //done('invalid to address') is possible but discouraged return...

node.js redis and how to use promise when using a module

javascript,node.js,redis,promise,q

like @brad said, you could use Q.all, it would take an array of promises as input and then return an array of results when all the promises are finished: there is a mistake in your answer: Redis.prototype.exists = function (key) { return this.client.exists(key) // CHANGED, you still need to return...

node js redis pubsub

mysql,node.js,redis,publish-subscribe

Redis is a advanced key-value cache and store.Its operations cannot be directly mapped to mysql. In redis you can set either key value pair or a hash under a key. That is : If you want to store your name in redis it can be done by: var client =...

Redis - Delete/pop if more than x members in set

performance,redis

I'd suggest using "sorted sets" instead of simple sets and use ZADD, setting the scores to seconds since the epoch or something similar. Then you can ZREMRANGEBYSCORE to perform mass removals of old items.

Can RPUSH and LPUSH in Redis race?

transactions,redis,race-condition

Since Redis is single threaded, there is no such thing as them happening at the "same time", one will always arrive ahead of the other, though the timing is often beyond your control. Now if you have two processes can be coordinated in some way you can have one defer...

ServiceStack minimum configuration to get Redis Pub/Sub working between multiple Web sites/services

servicestack,servicestack.redis

The minimum code for a publisher is just: var redisManager = container.Resolve<IRedisClientsManager>(); using (var mqProducer = new RedisMessageProducer(redisManager)) { mqProducer.Publish(new Msg { ... }); } You could also use a MessageFactory: var msgFactory = new RedisMessageFactory(redisMangager); using (var mqClient = msgFactory.CreateMessageQueueClient()) { mqClient.Publish(new Msg { ... }); } ...

ServiceStack MemoryCached Authentication Register User

c#,servicestack

You'll need to enable the Registration Services to expose Services that allows creating a User with Password, e.g: Plugins.Add(new AuthFeature(() => new CustomUserSession(), new IAuthProvider[] { new CredentialsAuthProvider(), ... }) { IncludeRegistrationService = true }); The IncludeRegistrationService=true option enables ServiceStack's built-in RegisterService which allows creating new users at /register. You...

Celery worker with Redis broker can't execute Django task

redis,celery,django-celery,celery-task,celerybeat

Wrong task name. This got fixed by changing the task decorator to @celery_app1.task(name='tasks.rank_all') and tweaking my beat schedule to include the correct name: CELERYBEAT_SCHEDULE = { 'tasks.rank_all': { 'task': 'tasks.rank_all', 'schedule': timedelta(seconds=30), }, } ...

Soap Address Location : ServiceStack SOAP 1.2

soap,wsdl,servicestack

You can modify the dynamically generated WSDL in ServiceStack by overriding AppHost.GenerateWsdl(), e.g: public override string GenerateWsdl(WsdlTemplateBase wsdlTemplate) { var wsdl = base.GenerateWsdl(wsdlTemplate); return wsdl.Replace( "<soap:address location=\"http:", "<soap:address location=\"https:"); } Add ServiceStack Reference Also as an alternative to SOAP you can use Add ServiceStack Reference which like SOAP allows generation...

ServiceStack CredentialsAuthProvider is ignore rememberMe = false

servicestack

Both of ServiceStack ss-id and ss-pid Session Cookies are always created. The ?RememberMe=true parameter indicates that the Users Session should be stored under the permanent Id ss-pid instead of the default Temporary Session Id ss-id which is how Users Sessions can survive Browser restarts since the ss-pid permanent Cookie isn't...

Default Redis behaviour on graceful shutdown

linux,database,redis

Redis is configured for data persistence as a default, so yes - the keys would still be there after a reboot. If you want to change this behavior, review your redis.conf file after reading this blog post: http://oldblog.antirez.com/post/redis-persistence-demystified.html

Socket.io redis How data stored and cleared

redis,socket.io,socket.io-redis

Assuming that you are referring to https://github.com/Automattic/socket.io-redis/blob/master/index.js, it appears that the plugin uses Redis' PubSub functionality. PubSub does not maintain state in the Redis database so there's no need to clear any data.

Loop until i get correct user

ruby,redis

Change if to while: while ["user_4", "user_5"].include?(@randUser = @redis.spop("users")) do @redis.sadd("users", @randUser) end $user_username = @redis.hget(@randUser, "username") $user_password = @redis.hget(@randUser, "password") Please note, that you actually mixed up receiver and parameters on Array#include?...

How to understand text language in utf8 encoded text?

node.js,utf-8,character-encoding,redis,language-detection

Do a google search for "language detect node". This turned up https://github.com/FGRibreau/node-language-detect and https://github.com/dachev/node-cld.

Redis - linux / Error when Installing redis on linux: `cc: command not found`

linux,redis

You are trying to install redis from source code. What this process do is to compile and create executable on your machine and then install it. For doing this you need various tools like gcc etc. Best way is to install all of them together by installing that group. Run...

LINQ query fails with nullable variable ormlite

linq,servicestack,ormlite-servicestack

This is nature of the Linq. In order to achieve what you need, you will need to use two where closes: dbConn.Where<Product>(p => p.IsActive.HasValue).Where(p=>p.Value==true); ...

Is exists check required before calling StringSet method of StrackExchange.Redis

c#,redis,stackexchange.redis

yes, you can savely remove that. We also don't check for existence as that would lead to have two access points to the cache where only one is necessary. This would really slow down cache access. You may want to consider three other things: you may have to make the...

Docker - Cannot start Redis Service

redis,docker

In general, you can't use an init script inside a Docker container. These scripts are typically designed to start a service "in the background", which means that even if the service starts, the script ultimately exits. If this is the first process in your Docker container, Docker will see it...

How To Restore a Missing Redis Service

linux,redis,centos

Do you want to remove redis old package you can use yum remove command as below. yum remove redis then check it still available as below rpm -qi redis and also check files rpm -ql redis if its there you can remove as below. rpm -e redis (or you can...

ServiceStack View 403 (Forbidden)

razor,servicestack,servicestack-razor

See the difference between Views vs Content Pages, i.e. the /Views folder is a special folder for view pages that are only executed with the result of a Service (i.e. similar to ASP.NET MVC Controllers + Views). Essentially Razor pages in /Views can't be called directly, where as razor pages...

using Go redis client (Redigo)

go,redis

An application must call Receive to clear the responses from the server and to check for errors. If the application is not pipelining commands, then it's best to call Do. Do combines Send, Flush and Receive. If you don't care about errors, then start a goroutine to read the responses:...

hmset redis with result from mysqlDB

php,arrays,redis

I'm using Predis to store your array, code tested $data = array( 'userid' => 1, 'username' => 'test', 'password' => 'example2222', 'health' => 120 ); Predis::instance()->hmset('uid-' . $data['userid'], $data); die(); ...

Redis Cluster: Find which master holds particular key/slot

lua,redis

I still have to read the entire docs, but already found this: There are 16384 hash slots in Redis Cluster, and to compute what is the hash slot of a given key, we simply take the CRC16 of the key modulo 16384. There is a command for that op already:...

Redis Cache .Net Client

.net,redis,server

Either .NET, NodeJS, Ruby, even C/C++ don't require a server component to work with a Redis server. This is why they're clients. It would be required if Amazon would develop an own branch of Redis which would change standard communication protocol defined by official Redis implementation......

Ormlite int based enums coming as varchar(max)

servicestack,ormlite-servicestack

Add a [Flags] attribute to enums you want ServiceStack to treat as integers.

Predis: Pros and Cons of the two cluster strategies

php,session,redis,cluster-computing,predis

IIUC you're debating internally between using Predis' client-side sharding vs. having it leverage Redis v3's clustering abilities. Client-side sharding is a great to have clustering when a database doesn't support it and this approach is usually the easiest implement initially. However, when a database does provide native clustering functionality -...

Redis: Delete user token by email ( find Key by Value )

node.js,express,redis

You basically have to choose one of two approaches: a full scan of the database or an index. A full scan, as proposed in another answer to this question, will be quite inefficient - you'll go over your entire keyspace (or at least all the tokens) and will need to...

Django, socket.io, node.js - Manage private messages and group conversations

django,node.js,websocket,redis,socket.io

Private messages Node keeps track of which sockets that are currently connected with an array of socket ids keyed with some user identifier. You pretty much said it there. Django does not need to know the socket id of the target user, but node.js does. If you want to...

Servicestack reverse routing exception

servicestack

Eventually the problem was with the capitalization of the HTTP method on the route declaration. It worked after I set the route as follows [Route("/user/UserName/{UserName}", "GET")] The service has been working, even when it was declared as "Get" but the "ToAbsoluteUri()" brought up the problem....

predis: ZADD with NX keeps throwing error 'Predis\ServerException'

redis,predis

ZADD's NX switch was added only to the recent version of Redis, see here: https://groups.google.com/forum/#!topic/redis-db/4Y6OqK8gEyk In all likelihood you aren't running the recent version - use INFO to find out your server's version....

What happened to SafeConvertAll in ServiceStack?

servicestack

It's just a safe wrapper around ConvertAll to treat null collections as empty collections, it's been replaced with a much shorter Map() alias, e.g: public object Get(Images request) { return Directory.GetFiles(UploadsDir) .Map(x => x.SplitOnLast(Path.DirectorySeparatorChar).Last()); } You can also use .Safe() to return an empty collection for null collections letting you...

ServiceStack Authenticates both iOS Apps when one is logged in

rest,xamarin,servicestack,restful-authentication,servicestack-auth

The issue is because you're using the same Session Cookies with a shared ServiceClient instance which ends up referencing the same Authenticated Users Session. ServiceStack Sessions are only based on the session identifiers (ss-id/ss-pid) specified by the clients cookies, if you use the same cookies you will be referencing the...

Getting a lost Sentinel error message for Redis

redis,spring-boot,spring-data-redis

We discovered the issue. There was a blank between the node pairs in the application.yml and once we removed this " " the Lost Sentinel log message disappeared. so from nodes: 10.202.56.209:26379, 10.202.56.213:26379, 10.202.58.80:26379 to nodes: 10.202.56.209:26379,10.202.56.213:26379,10.202.58.80:26379 It would probably be a good thing is the committers looked at this...

Updating Xamarin app with servicestack

xamarin,servicestack

The official API has never changed and only has ever been IosPclExportClient: IosPclExportClient.Configure(); The class is defined in the ServiceStack.Pcl.iOS.dll and should be added by NuGet when you add the ServiceStack.Text NuGet package. If it's not you can try removing and re-adding the NuGet package again, otherwise you can adding...

Redis remote connection security concern

php,node.js,redis

From http://redis.io/topics/security Note that it is possible to bind Redis to a single interface by adding a line like the following to the redis.conf file: bind 127.0.0.1 It's also recommended to configure your firewall to close whatever port redis is listening on....

What is the use of privdata argument in redisAsyncCommand?

c,redis,hiredis

As I understand by reading the code on gihub, the purpose of privdata is to send your callback some predefined data (which can be anything; that is why void* is used). In your callback (fn pointer to redisCallbackFn) you will recieve that privdata as parameter (for example look at cb->fn(ac,reply,cb->privdata);...

I'm trying to import an external Redis database (.RDB file) on a Redis installation on Windows but the new data is not being loaded?

database,import,redis,nosql

The following line from your log suggests that the RDB is indeed loaded: [9480] 07 Jun 10:34:11.290 * DB loaded from disk: 3.540 seconds And this line begotten from INFO tells the whole thing: db2:keys=457985,expires=0,avg_ttl=0 Your keys are sitting in the database numbered 2, so to access them you'll need...

Low level caching for collection

ruby-on-rails,caching,redis

So should I use a cached_books method in the controller like this: Yes, you can. Although there's some gotchas you have to be aware of. Book is ActiveRecord. When you call Book.something (e.g. Book.all, or just even Book.order(:title) it returns you a ActiveRecord::Relation, which is basically wrapper for array...