You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 24, 2022. It is now read-only.
More API examples are available in [LexTests.cs](https://github.com/ServiceStack/ServiceStack.Redis/blob/master/tests/ServiceStack.Redis.Tests/LexTests.cs).
448
462
449
-
### New HyperLog API
463
+
### HyperLog API
450
464
451
465
The development branch of Redis server (available when v3.0 is released) includes an ingenious algorithm to approximate the unique elements in a set with maximum space and time efficiency. For details about how it works see Redis's creator Salvatore's blog who [explains it in great detail](http://antirez.com/news/75). Essentially it lets you maintain an efficient way to count and merge unique elements in a set without having to store its elements.
Redis v2.8 introduced a beautiful new [SCAN](http://redis.io/commands/scan) operation that provides an optimal strategy for traversing a redis instance entire keyset in managable-size chunks utilizing only a client-side cursor and without introducing any server state. It's a higher performance alternative and should be used instead of [KEYS](http://redis.io/commands/keys) in application code. SCAN and its related operations for traversing members of Sets, Sorted Sets and Hashes are now available in the Redis Client in the following API's:
469
483
@@ -495,15 +509,108 @@ var scanUsers = Redis.ScanAllKeys("urn:User:*");
495
509
varsampleUsers=scanUsers.Take(10000).ToList(); //Stop after retrieving 10000 user keys
496
510
```
497
511
512
+
### Efficient SCAN in LUA
513
+
514
+
The C# API below returns the first 10 results matching the `key:*` pattern:
ExecCachedLua is a convenient high-level API that eliminates the bookkeeping required for executing high-performance server LUA
571
+
Scripts which suffers from many of the problems that RDBMS stored procedures have which depends on pre-existing state in the RDBMS
572
+
that needs to be updated with the latest version of the Stored Procedure.
573
+
574
+
With Redis LUA you either have the option to send, parse, load then execute the entire LUA script each time it's called or
575
+
alternatively you could pre-load the LUA Script into Redis once on StartUp and then execute it using the Script's SHA1 hash.
576
+
The issue with this is that if the Redis server is accidentally flushed you're left with a broken application relying on a
577
+
pre-existing script that's no longer there. The new `ExecCachedLua` API provides the best of both worlds where it will always
578
+
execute the compiled SHA1 script, saving bandwidth and CPU but will also re-create the LUA Script if it no longer exists.
579
+
580
+
You can instead execute the compiled LUA script above by its SHA1 identifier, which continues to work regardless if it never existed
581
+
or was removed at runtime, e.g:
582
+
583
+
```csharp
584
+
// #1: Loads LUA script and caches SHA1 hash in Redis Client
585
+
r=redis.ExecCachedLua(FastScanScript, sha1=>
586
+
redis.ExecLuaSha(sha1, "key:*", "10"));
587
+
588
+
// #2: Executes using cached SHA1 hash
589
+
r=redis.ExecCachedLua(FastScanScript, sha1=>
590
+
redis.ExecLuaSha(sha1, "key:*", "10"));
591
+
592
+
// Deletes all existing compiled LUA scripts
593
+
redis.ScriptFlush();
594
+
595
+
// #3: Executes using cached SHA1 hash, gets NOSCRIPT Error, re-creates and re-executes with SHA1 hash
596
+
r=redis.ExecCachedLua(FastScanScript, sha1=>
597
+
redis.ExecLuaSha(sha1, "key:*", "10"));
598
+
```
599
+
600
+
### IRedisClient LUA API's
500
601
501
602
The `IRedisClient` API's for [redis server-side LUA support](http://redis.io/commands/eval) have been re-factored into the more user-friendly API's below:
0 commit comments